From 5c9ab21d817a45d9355d4a24bc80a6a52f3aafc3 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 0d88b8489..9b18819b6 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -50,10 +50,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) @@ -91,26 +87,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): @@ -263,6 +255,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 eb6dbeb15a33afc0e998e090e0b5ed80313b3d7a 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 aad91c10d..42486a1b1 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -109,7 +109,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") @@ -141,12 +140,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 0420f290a45afa5849d92a54d7954ba8137ad575 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 8ffd0b3ec..4506d7337 100644 --- a/docs/conf_common.py +++ b/docs/conf_common.py @@ -74,7 +74,6 @@ confgen_args = [sys.executable, "../../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), "--env", "IDF_PATH={}".format(idf_path), From cec39b750ac0fe0fc3c91e1e1885c1d500f7894b 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 | 10 ++++++++++ tools/ci/test_build_system_cmake.sh | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index efc3703b1..f3fb2b6b1 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -238,6 +238,16 @@ function run_tests() ( make 2>&1 | grep "does not fit in configured flash size 1MB" ) || failure "Build didn't fail with expected flash size failure message" mv sdkconfig.bak sdkconfig + 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 c5e02fc4d..f9bf0a264 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -212,6 +212,17 @@ function run_tests() mv CMakeLists.bak CMakeLists.txt assert_built ${APP_BINS} ${BOOTLOADER_BINS} ${PARTITION_BIN} + 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 d2cf266762e3b0912c21c1cedae57322c34df6bc 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 929f30d4d..46f845c57 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 403a24ab64e03a75aab29ff4e9e9d59a8023c6bf 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 9b18819b6..9e4d120ec 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -79,6 +79,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 a34d788a5e71769785b5c7e2ae66fcf2c87c5ab3 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 46f845c57..c17b32b4a 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 022a9295b04c6a23b8f89ef14de727384cd577c9 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 9e4d120ec..54a22a5be 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -80,6 +80,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