Skip to content

Commit cb46ed6

Browse files
57300carlescufi
authored andcommitted
cmake: kconfig: Preserve correct CLI assignments across re-runs
This tiny patch makes two improvements: 1. Preserve boolean (=n) assignments from command-line. This fixes an issue where, if a symbol with `default y` were turned off via command-line, e.g., `-DCONFIG_BOOT_BANNER=n`, a CMake re-run would revert that symbol back to its default value. To avoid this, the assignment should have been preserved in CMake cache as `CLI_CONFIG_BOOT_BANNER:INTERNAL=n`. However, `kconfig.cmake` clears unset variables from cache, and (=n) symbols become unset variables, so an exception had to be made for them. 2. Discard invalid assignments from command-line. Although `kconfig.cmake` takes care to discard assignments to symbols which get unset by Kconfig, it wasn't handling the case where Kconfig would keep the symbol but replace its value, making the CMake-cached assignment invalid. For example, this assignment: west build . -DCONFIG_PRINTK=n could be invalidated if PRINTK were selected by, e.g., BOOT_BANNER, producing this warning: PRINTK (...) was assigned the value 'n' but got the value 'y'. (...) Still, the old value of (=n) was being cached. One way in which this was evident was when setting an unrelated symbol in a separate invocation: west build . -DCONFIG_MAIN_STACK_SIZE=512 the same warning for PRINTK would show up again. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent 9228c37 commit cb46ed6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cmake/modules/kconfig.cmake

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,32 @@ foreach (name ${cli_config_list})
376376
unset(${name} CACHE)
377377
endforeach()
378378

379+
# Before importing the symbol values from DOTCONFIG, process the CLI values by
380+
# re-importing them from EXTRA_KCONFIG_OPTIONS_FILE. Later, we want to compare
381+
# the values from both files, and 'import_kconfig' will make this easier.
382+
if(EXTRA_KCONFIG_OPTIONS_FILE)
383+
import_kconfig(${KCONFIG_NAMESPACE} ${EXTRA_KCONFIG_OPTIONS_FILE})
384+
foreach (name ${cache_variable_names})
385+
if(DEFINED ${name})
386+
set(temp_${name} "${${name}}")
387+
unset(${name})
388+
endif()
389+
endforeach()
390+
endif()
391+
379392
# Import the .config file and make all settings available in CMake processing.
380393
import_kconfig(${KCONFIG_NAMESPACE} ${DOTCONFIG})
381394

382395
# Cache the CLI Kconfig symbols that survived through Kconfig, prefixed with CLI_.
383396
# Remove those who might have changed compared to earlier runs, if they no longer appears.
384-
foreach (name ${cli_config_list})
385-
if(DEFINED ${name})
397+
foreach (name ${cache_variable_names})
398+
# Note: "${CLI_${name}}" is the verbatim value of ${name} from command-line,
399+
# while "${temp_${name}}" is the same value processed by 'import_kconfig'.
400+
if(((NOT DEFINED ${name}) AND (NOT DEFINED temp_${name})) OR
401+
((DEFINED ${name}) AND (DEFINED temp_${name}) AND (${name} STREQUAL temp_${name})))
386402
set(CLI_${name} ${CLI_${name}} CACHE INTERNAL "")
387403
else()
388404
unset(CLI_${name} CACHE)
389405
endif()
406+
unset(temp_${name})
390407
endforeach()

0 commit comments

Comments
 (0)