From 260fe847e23f319aa137e19ac638821c7d1c170d Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 16 Apr 2020 13:59:16 +1000 Subject: [PATCH 1/2] kconfig: Fix generation of hex outputs for Make & CMake And add tests for hex output formatting in all output formats. Previously, Make & CMake outputs only formatted hex values with the 0x prefix if they had the 0x prefix in the sdkconfig file. Now this prefix is always applied. Closes https://github.com/espressif/vscode-esp-idf-extension/issues/83 --- tools/kconfig_new/confgen.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index 43e9b74a1..be9698234 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -310,14 +310,24 @@ def write_makefile(deprecated_options, config, filename): def get_makefile_config_string(name, value, orig_type): if orig_type in (kconfiglib.BOOL, kconfiglib.TRISTATE): - return "{}{}={}\n".format(config.config_prefix, name, '' if value == 'n' else value) - elif orig_type in (kconfiglib.INT, kconfiglib.HEX): - return "{}{}={}\n".format(config.config_prefix, name, value) + value = '' if value == 'n' else value + elif orig_type == kconfiglib.INT: + 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: - return '{}{}="{}"\n'.format(config.config_prefix, name, kconfiglib.escape(value)) + value = '"{}"'.format(kconfiglib.escape(value)) else: raise RuntimeError('{}{}: unknown type {}'.format(config.config_prefix, name, orig_type)) + return '{}{}={}\n'.format(config.config_prefix, name, value) + def write_makefile_node(node): item = node.item 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 elif sym.orig_type == kconfiglib.STRING: val = kconfiglib.escape(val) - write("set({}{} \"{}\")\n".format( - prefix, sym.name, val)) + elif sym.orig_type == kconfiglib.HEX: + val = hex(int(val, 16)) # ensure 0x prefix + write('set({}{} "{}")\n'.format(prefix, sym.name, val)) configs_list.append(prefix + sym.name) dep_opt = deprecated_options.get_deprecated_option(sym.name) 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) config.walk_menu(write_node) From 18abdd7cb0203543999633adf7db72fe81282438 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 16 Apr 2020 14:04:54 +1000 Subject: [PATCH 2/2] confserver: Always store hex values in sdkconfig with 0x prefix This is not necessary for correct behaviour or to have valid sdkconfig files (previous commit adds tests for this), but it's useful for consistency with sdkconfig files generated by menuconfig. As reported in https://github.com/espressif/vscode-esp-idf-extension/issues/83 --- tools/kconfig_new/confserver.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/kconfig_new/confserver.py b/tools/kconfig_new/confserver.py index b02a2f1ce..57a948c75 100755 --- a/tools/kconfig_new/confserver.py +++ b/tools/kconfig_new/confserver.py @@ -224,6 +224,13 @@ def handle_set(config, error, to_set): sym.set_value(0) else: 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: sym.set_value(str(val)) print("Set %s" % sym.name)