From c3bf2a06855e255f8f3de219edbb4c6f6363e1c0 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 15 Jan 2019 23:06:50 +0800 Subject: [PATCH 1/8] confgen: base config creation on output type args --- tools/kconfig_new/confgen.py | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index 416c28d886..91cfc7c835 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -49,10 +49,6 @@ def main(): nargs='?', default=None) - parser.add_argument('--create-config-if-missing', - help='If set, a new config file will be saved if the old one is not found', - action='store_true') - parser.add_argument('--kconfig', help='KConfig file with config item definitions', required=True) @@ -90,26 +86,22 @@ def main(): raise RuntimeError("Defaults file not found: %s" % args.defaults) config.load_config(args.defaults) - if args.config is not None: - if os.path.exists(args.config): - config.load_config(args.config) - elif args.create_config_if_missing: - print("Creating config file %s..." % args.config) - config.write_config(args.config) - elif args.default is None: - raise RuntimeError("Config file not found: %s" % args.config) + # If config file previously exists, load it + if args.config and os.path.exists(args.config): + config.load_config(args.config, replace=False) - for output_type, filename in args.output: - temp_file = tempfile.mktemp(prefix="confgen_tmp") + # Output the files specified in the arguments + for output_type, filename in args.output: + temp_file = tempfile.mktemp(prefix="confgen_tmp") + try: + output_function = OUTPUT_FORMATS[output_type] + output_function(config, temp_file) + update_if_changed(temp_file, filename) + finally: try: - output_function = OUTPUT_FORMATS[output_type] - output_function(config, temp_file) - update_if_changed(temp_file, filename) - finally: - try: - os.remove(temp_file) - except OSError: - pass + os.remove(temp_file) + except OSError: + pass def write_config(config, filename): @@ -262,6 +254,7 @@ def write_json_menus(config, filename): def update_if_changed(source, destination): with open(source, "r") as f: source_contents = f.read() + if os.path.exists(destination): with open(destination, "r") as f: dest_contents = f.read() From 6dde1b7b80c97119cbaa2755b540ca15542d011e Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 15 Jan 2019 23:07:17 +0800 Subject: [PATCH 2/8] cmake: only generate sdkconfig on top level project --- tools/cmake/kconfig.cmake | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 8de088b681..e308cd0f17 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -105,7 +105,6 @@ function(kconfig_process_config) --kconfig ${ROOT_KCONFIG} --config ${SDKCONFIG} ${defaults_arg} - --create-config-if-missing --env "COMPONENT_KCONFIGS=${kconfigs}" --env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}" --env "IDF_CMAKE=y") @@ -138,12 +137,24 @@ function(kconfig_process_config) # makes sdkconfig.h and skdconfig.cmake # # This happens during the cmake run not during the build - execute_process(COMMAND ${confgen_basecommand} - --output header ${SDKCONFIG_HEADER} - --output cmake ${SDKCONFIG_CMAKE} - --output json ${SDKCONFIG_JSON} - --output json_menus ${KCONFIG_JSON_MENUS} - RESULT_VARIABLE config_result) + if(NOT BOOTLOADER_BUILD) + execute_process( + COMMAND ${confgen_basecommand} + --output header ${SDKCONFIG_HEADER} + --output cmake ${SDKCONFIG_CMAKE} + --output json ${SDKCONFIG_JSON} + --output json_menus ${KCONFIG_JSON_MENUS} + --output config ${SDKCONFIG} # only generate config at the top-level project + RESULT_VARIABLE config_result) + else() + execute_process( + COMMAND ${confgen_basecommand} + --output header ${SDKCONFIG_HEADER} + --output cmake ${SDKCONFIG_CMAKE} + --output json ${SDKCONFIG_JSON} + --output json_menus ${KCONFIG_JSON_MENUS} + RESULT_VARIABLE config_result) + endif() if(config_result) message(FATAL_ERROR "Failed to run confgen.py (${confgen_basecommand}). Error ${config_result}") endif() From 89afc96bf0f9fa619c59900405a63e3f8f702247 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 15 Jan 2019 23:37:48 +0800 Subject: [PATCH 3/8] docs: remove invalid arg in confgen invocation on docs generation --- docs/conf_common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf_common.py b/docs/conf_common.py index 843943e2d0..34b597e829 100644 --- a/docs/conf_common.py +++ b/docs/conf_common.py @@ -53,7 +53,6 @@ confgen_args = ["python", "../../tools/kconfig_new/confgen.py", "--kconfig", "../../Kconfig", "--config", temp_sdkconfig_path, - "--create-config-if-missing", "--env", "COMPONENT_KCONFIGS={}".format(kconfigs), "--env", "COMPONENT_KCONFIGS_PROJBUILD={}".format(kconfig_projbuilds), "--output", "docs", kconfig_inc_path + '.in' From 18b5d7e5ab63243f74213e45f2a72a774e1404ee Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Mon, 14 Jan 2019 19:41:29 +0800 Subject: [PATCH 4/8] tool: Add unit test for Kconfig gen --- tools/ci/test_build_system.sh | 11 +++++++++++ tools/ci/test_build_system_cmake.sh | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index 136045987e..baa27b1cfa 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -265,6 +265,17 @@ function run_tests() make EXTRA_COMPONENT_DIRS=$PWD/mycomponents || failure "EXTRA_COMPONENT_DIRS has added a sibling directory" rm -rf esp32 rm -rf mycomponents + + print_status "sdkconfig should have contents both files: sdkconfig and sdkconfig.defaults" + make clean > /dev/null; + rm -f sdkconfig.defaults; + rm -f sdkconfig; + echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> sdkconfig.defaults; + echo "CONFIG_PARTITION_TABLE_TWO_OTA=y" >> sdkconfig; + make defconfig > /dev/null; + grep "CONFIG_PARTITION_TABLE_OFFSET=0x10000" sdkconfig || failure "The define from sdkconfig.defaults should be into sdkconfig" + grep "CONFIG_PARTITION_TABLE_TWO_OTA=y" sdkconfig || failure "The define from sdkconfig should be into sdkconfig" + print_status "All tests completed" if [ -n "${FAILURES}" ]; then echo "Some failures were detected:" diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 41b820999f..c679acc5c6 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -238,6 +238,17 @@ EOF export PATH="$OLDPATH" rm ./python + print_status "sdkconfig should have contents both files: sdkconfig and sdkconfig.defaults" + idf.py clean > /dev/null; + idf.py fullclean > /dev/null; + rm -f sdkconfig.defaults; + rm -f sdkconfig; + echo "CONFIG_PARTITION_TABLE_OFFSET=0x10000" >> sdkconfig.defaults; + echo "CONFIG_PARTITION_TABLE_TWO_OTA=y" >> sdkconfig; + idf.py reconfigure > /dev/null; + grep "CONFIG_PARTITION_TABLE_OFFSET=0x10000" sdkconfig || failure "The define from sdkconfig.defaults should be into sdkconfig" + grep "CONFIG_PARTITION_TABLE_TWO_OTA=y" sdkconfig || failure "The define from sdkconfig should be into sdkconfig" + print_status "All tests completed" if [ -n "${FAILURES}" ]; then echo "Some failures were detected:" From 30ed610950280db79d256e443ae80c58370fea57 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 25 Jan 2019 17:42:25 +0800 Subject: [PATCH 5/8] kconfiglib: allow disabling of redundant definition warnings Patches ESP-IDF copy of kconfiglib.py with modifications in commit 94c63de77c7a3422347e59e168b05174d0b9e84d from kconfiglib repository. --- tools/kconfig_new/kconfiglib.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/kconfig_new/kconfiglib.py b/tools/kconfig_new/kconfiglib.py index 929f30d4db..46f845c577 100644 --- a/tools/kconfig_new/kconfiglib.py +++ b/tools/kconfig_new/kconfiglib.py @@ -500,6 +500,7 @@ class Kconfig(object): __slots__ = ( "_choices", "_print_undef_assign", + "_print_redun_assign", "_print_warnings", "_set_re_match", "_unset_re_match", @@ -575,6 +576,7 @@ class Kconfig(object): self._print_warnings = warn self._print_undef_assign = False + self._print_redun_assign = True self.syms = {} self.const_syms = {} @@ -826,10 +828,12 @@ class Kconfig(object): display_val = val display_user_val = sym.user_value - self._warn('{} set more than once. Old value: "{}", new ' - 'value: "{}".' - .format(name, display_user_val, display_val), - filename, linenr) + msg = '{} set more than once. Old value: "{}", new value: "{}".'.format(name, display_user_val, display_val) + + if display_user_val == display_val: + self._warn_redun_assign(msg, filename, linenr) + else: + self._warn(msg, filename, linenr) sym.set_value(val) @@ -1057,6 +1061,19 @@ class Kconfig(object): """ self._print_undef_assign = False + def enable_redun_warnings(self): + """ + Enables warnings for redundant assignments to symbols. Printed to + stderr. Enabled by default. + """ + self._print_redun_assign = True + + def disable_redun_warnings(self): + """ + See enable_redun_warnings(). + """ + self._print_redun_assign = False + def __repr__(self): """ Returns a string with information about the Kconfig object when it is @@ -1071,6 +1088,8 @@ class Kconfig(object): "warnings " + ("enabled" if self._print_warnings else "disabled"), "undef. symbol assignment warnings " + ("enabled" if self._print_undef_assign else "disabled"), + "redundant symbol assignment warnings " + + ("enabled" if self._print_redun_assign else "disabled") ))) # @@ -2150,6 +2169,12 @@ class Kconfig(object): 'attempt to assign the value "{}" to the undefined symbol {}' \ .format(val, name), filename, linenr) + def _warn_redun_assign(self, msg, filename=None, linenr=None): + """ + See the class documentation. + """ + if self._print_redun_assign: + _stderr_msg("warning: " + msg, filename, linenr) class Symbol(object): """ From df86f46efefea7ff412e1c409dce6b1e244ae1d3 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Fri, 25 Jan 2019 18:24:53 +0800 Subject: [PATCH 6/8] confgen: disable redundant assignment warning --- tools/kconfig_new/confgen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index 91cfc7c835..8b7048219f 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -78,6 +78,7 @@ def main(): os.environ[name] = value config = kconfiglib.Kconfig(args.kconfig) + config.disable_redun_warnings() if args.defaults is not None: # always load defaults first, so any items which are not defined in that config From 1ee0f9455fbd0cc673e45f411861b3aa1277f937 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 29 Jan 2019 11:16:25 +0800 Subject: [PATCH 7/8] kconfiglib: allow disabling of config override warnings Patches ESP-IDF copy of kconfiglib.py with modifications in commit b65baa47f69ae4c3993876a7edf0da0075aa70ff from kconfiglib repository. --- tools/kconfig_new/kconfiglib.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/kconfig_new/kconfiglib.py b/tools/kconfig_new/kconfiglib.py index 46f845c577..c17b32b4ab 100644 --- a/tools/kconfig_new/kconfiglib.py +++ b/tools/kconfig_new/kconfiglib.py @@ -500,6 +500,7 @@ class Kconfig(object): __slots__ = ( "_choices", "_print_undef_assign", + "_print_override", "_print_redun_assign", "_print_warnings", "_set_re_match", @@ -576,7 +577,7 @@ class Kconfig(object): self._print_warnings = warn self._print_undef_assign = False - self._print_redun_assign = True + self._print_redun_assign = self._print_override = True self.syms = {} self.const_syms = {} @@ -833,7 +834,7 @@ class Kconfig(object): if display_user_val == display_val: self._warn_redun_assign(msg, filename, linenr) else: - self._warn(msg, filename, linenr) + self._warn_override(msg, filename, linenr) sym.set_value(val) @@ -1074,6 +1075,23 @@ class Kconfig(object): """ self._print_redun_assign = False + def enable_override_warnings(self): + """ + Enables warnings for duplicated assignments in .config files that set + different values (e.g. CONFIG_FOO=m followed by CONFIG_FOO=y, where + the last value set is used). + + These warnings are enabled by default. Disabling them might be helpful + in certain cases when merging configurations. + """ + self._print_override = True + + def disable_override_warnings(self): + """ + See enable_override_warnings(). + """ + self._print_override = False + def __repr__(self): """ Returns a string with information about the Kconfig object when it is @@ -2176,6 +2194,13 @@ class Kconfig(object): if self._print_redun_assign: _stderr_msg("warning: " + msg, filename, linenr) + def _warn_override(self, msg, filename=None, linenr=None): + """ + See the class documentation. + """ + if self._print_override: + _stderr_msg("warning: " + msg, filename, linenr) + class Symbol(object): """ Represents a configuration symbol: From 02ee80201bf63e714b9134a184e8c9f021fe6712 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Tue, 29 Jan 2019 11:17:02 +0800 Subject: [PATCH 8/8] confgen: disable config override warnings --- tools/kconfig_new/confgen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index 8b7048219f..40501af3da 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -79,6 +79,7 @@ def main(): config = kconfiglib.Kconfig(args.kconfig) config.disable_redun_warnings() + config.disable_override_warnings() if args.defaults is not None: # always load defaults first, so any items which are not defined in that config