kconfig: Have ninja Re-run CMake when Kconfig sources change

Users often get confused when they change Kconfig sources and then
rebuild only to discover that nothing happens. To fix this we add a
dependency between re-running cmake, and all Kconfig sources, similair
to how touching CMakeLists.txt files cause CMake to re-run.

This fixes #5634

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2019-02-20 17:49:46 +01:00 committed by Carles Cufí
commit f96c9bc75a
2 changed files with 37 additions and 1 deletions

View file

@ -14,6 +14,7 @@ endif()
set(BOARD_DEFCONFIG ${BOARD_DIR}/${BOARD}_defconfig)
set(DOTCONFIG ${PROJECT_BINARY_DIR}/.config)
set(PARSED_KCONFIG_SOURCES_TXT ${PROJECT_BINARY_DIR}/kconfig/sources.txt)
if(CONF_FILE)
string(REPLACE " " ";" CONF_FILE_AS_LIST "${CONF_FILE}")
@ -159,6 +160,7 @@ execute_process(
${KCONFIG_ROOT}
${DOTCONFIG}
${AUTOCONF_H}
${PARSED_KCONFIG_SOURCES_TXT}
${merge_fragments}
WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR}
# The working directory is set to the app dir such that the user
@ -169,10 +171,14 @@ if(NOT "${ret}" STREQUAL "0")
message(FATAL_ERROR "command failed with return code: ${ret}")
endif()
# Force CMAKE configure when the configuration files changes.
# Read out the list of 'Kconfig' sources that were used by the engine.
file(STRINGS ${PARSED_KCONFIG_SOURCES_TXT} PARSED_KCONFIG_SOURCES_LIST)
# Force CMAKE configure when the Kconfig sources or configuration files changes.
foreach(kconfig_input
${merge_config_files}
${DOTCONFIG}
${PARSED_KCONFIG_SOURCES_LIST}
)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${kconfig_input})
endforeach()

View file

@ -93,6 +93,9 @@ def main():
print("Configuration written to '{}'".format(args.dotconfig))
kconf.write_autoconf(args.autoconf)
# Write the list of processed Kconfig sources to a file
write_kconfig_filenames(kconf.kconfig_filenames, kconf.srctree, args.sources)
# Message printed when a promptless symbol is assigned (and doesn't get the
# assigned value)
@ -182,6 +185,32 @@ def promptless(sym):
return not any(node.prompt for node in sym.nodes)
def write_kconfig_filenames(paths, root_path, output_file_path):
# 'paths' is a list of paths. The list has duplicates and the
# paths are either absolute or relative to 'root_path'.
# We need to write this list, in a format that CMake can easily
# parse, to the output file at 'output_file_path'.
# The written list should also have absolute paths instead of
# relative paths, and it should not have duplicates.
# Remove duplicates
paths_uniq = set(paths)
with open(output_file_path, 'w') as out:
# sort to be deterministic
for path in sorted(paths_uniq):
# Change from relative to absolute path (do nothing for
# absolute paths)
abs_path = os.path.join(root_path, path)
# Assert that the file exists, since it was sourced, it
# must surely also exist.
assert os.path.isfile(abs_path), "Internal error"
out.write("{}\n".format(abs_path))
def parse_args():
parser = argparse.ArgumentParser(
@ -192,6 +221,7 @@ def parse_args():
parser.add_argument("kconfig_root")
parser.add_argument("dotconfig")
parser.add_argument("autoconf")
parser.add_argument("sources")
parser.add_argument("conf_fragments", metavar='conf', type=str, nargs='+')
return parser.parse_args()