Merge branch 'bugfix/kconfig_hex_values_v4.0' into 'release/v4.0'

kconfig: Fix two cases of hex values being handled incorrectly (v4.0)

See merge request espressif/esp-idf!8788
This commit is contained in:
Angus Gratton 2020-06-01 14:48:16 +08:00
commit 6a844f3737
2 changed files with 25 additions and 7 deletions

View file

@ -310,14 +310,24 @@ def write_makefile(deprecated_options, config, filename):
def get_makefile_config_string(name, value, orig_type): def get_makefile_config_string(name, value, orig_type):
if orig_type in (kconfiglib.BOOL, kconfiglib.TRISTATE): if orig_type in (kconfiglib.BOOL, kconfiglib.TRISTATE):
return "{}{}={}\n".format(config.config_prefix, name, '' if value == 'n' else value) value = '' if value == 'n' else value
elif orig_type in (kconfiglib.INT, kconfiglib.HEX): elif orig_type == kconfiglib.INT:
return "{}{}={}\n".format(config.config_prefix, name, value) try:
value = int(value)
except ValueError:
value = ""
elif orig_type == kconfiglib.HEX:
try:
value = hex(int(value, 16)) # ensure 0x prefix
except ValueError:
value = ""
elif orig_type == kconfiglib.STRING: elif orig_type == kconfiglib.STRING:
return '{}{}="{}"\n'.format(config.config_prefix, name, kconfiglib.escape(value)) value = '"{}"'.format(kconfiglib.escape(value))
else: else:
raise RuntimeError('{}{}: unknown type {}'.format(config.config_prefix, name, orig_type)) raise RuntimeError('{}{}: unknown type {}'.format(config.config_prefix, name, orig_type))
return '{}{}={}\n'.format(config.config_prefix, name, value)
def write_makefile_node(node): def write_makefile_node(node):
item = node.item item = node.item
if isinstance(item, kconfiglib.Symbol) and item.env_var is None: if isinstance(item, kconfiglib.Symbol) and item.env_var is None:
@ -373,13 +383,14 @@ def write_cmake(deprecated_options, config, filename):
val = "" # write unset values as empty variables val = "" # write unset values as empty variables
elif sym.orig_type == kconfiglib.STRING: elif sym.orig_type == kconfiglib.STRING:
val = kconfiglib.escape(val) val = kconfiglib.escape(val)
write("set({}{} \"{}\")\n".format( elif sym.orig_type == kconfiglib.HEX:
prefix, sym.name, val)) val = hex(int(val, 16)) # ensure 0x prefix
write('set({}{} "{}")\n'.format(prefix, sym.name, val))
configs_list.append(prefix + sym.name) configs_list.append(prefix + sym.name)
dep_opt = deprecated_options.get_deprecated_option(sym.name) dep_opt = deprecated_options.get_deprecated_option(sym.name)
if dep_opt: if dep_opt:
tmp_dep_list.append("set({}{} \"{}\")\n".format(prefix, dep_opt, val)) tmp_dep_list.append('set({}{} "{}")\n'.format(prefix, dep_opt, val))
configs_list.append(prefix + dep_opt) configs_list.append(prefix + dep_opt)
config.walk_menu(write_node) config.walk_menu(write_node)

View file

@ -224,6 +224,13 @@ def handle_set(config, error, to_set):
sym.set_value(0) sym.set_value(0)
else: else:
error.append("Boolean symbol %s only accepts true/false values" % sym.name) error.append("Boolean symbol %s only accepts true/false values" % sym.name)
elif sym.type == kconfiglib.HEX:
try:
if not isinstance(val, int):
val = int(val, 16) # input can be a decimal JSON value or a string of hex digits
sym.set_value(hex(val))
except ValueError:
error.append("Hex symbol %s can accept a decimal integer or a string of hex digits, only")
else: else:
sym.set_value(str(val)) sym.set_value(str(val))
print("Set %s" % sym.name) print("Set %s" % sym.name)