Merge branch 'bugfix/regenerate_sdkconfig_fails_v3.2' into 'release/v3.2'

Fix issues with regenerating sdkconfig on modification (backport v3.2)

See merge request idf/esp-idf!4169
This commit is contained in:
Angus Gratton 2019-01-30 09:27:47 +08:00
commit 671be20cc5
6 changed files with 110 additions and 34 deletions

View file

@ -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),

View file

@ -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:"

View file

@ -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:"

View file

@ -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()

View file

@ -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)
@ -83,6 +79,8 @@ def main():
os.environ[name] = value
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
@ -91,26 +89,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 +257,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()

View file

@ -500,6 +500,8 @@ class Kconfig(object):
__slots__ = (
"_choices",
"_print_undef_assign",
"_print_override",
"_print_redun_assign",
"_print_warnings",
"_set_re_match",
"_unset_re_match",
@ -575,6 +577,7 @@ class Kconfig(object):
self._print_warnings = warn
self._print_undef_assign = False
self._print_redun_assign = self._print_override = True
self.syms = {}
self.const_syms = {}
@ -826,10 +829,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_override(msg, filename, linenr)
sym.set_value(val)
@ -1057,6 +1062,36 @@ 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 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
@ -1071,6 +1106,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 +2187,19 @@ 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)
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):
"""