diff --git a/scripts/check-unixnu.py b/scripts/check-unixnu.py old mode 100644 new mode 100755 index 181e592..d8942d9 --- a/scripts/check-unixnu.py +++ b/scripts/check-unixnu.py @@ -50,6 +50,13 @@ def der(tag, body): def main(): config = parse_config('# c\nCONFIG_A=y\nCONFIG_B=n\n# CONFIG_C is not set\nCONFIG_D="x y"\nCONFIG_E=0x10\n') expect(config == {'A': True, 'B': False, 'C': False, 'D': 'x y', 'E': 16}, 'defconfig values') + for raw, value in ( + ('0', 0), ('-0', 0), ('00', 0), ('-00', 0), + ('8', 8), ('-8', -8), ('08', 8), ('-08', -8), + ('010', 10), ('-010', -10), ('00042', 42), ('-00042', -42), + ('0x10', 16), ('-0x10', -16), ('0x00FF', 255), ('-0x00FF', -255), + ): + expect(parse_config(f'CONFIG_NUMBER={raw}\n') == {'NUMBER': value}, f'defconfig number: {raw}') try: parse_config('CONFIG_A=maybe\n') expect(False, 'bad defconfig value accepted') diff --git a/scripts/unixnu/config.py b/scripts/unixnu/config.py index b19320d..5e7f20a 100644 --- a/scripts/unixnu/config.py +++ b/scripts/unixnu/config.py @@ -51,7 +51,7 @@ def parse_config(text): elif raw.startswith('"') and raw.endswith('"') and len(raw) >= 2: values[name] = raw[1:-1] elif re.fullmatch(r'-?(0x[0-9a-fA-F]+|\d+)', raw): - values[name] = int(raw, 0) + values[name] = int(raw, 16 if raw.lstrip('-').startswith('0x') else 10) else: raise Error(f'defconfig line {number}: value must be y, n, a number or a quoted string: {line}') return values