cmake(enhance):include-style defconfig can modified via menuconfig

1. enhanced process_config.py script: supports both preprocess and postprocess modes

2. in preprocess mode: handles include formats and recursively records the include config tree structure to prepare for postprocess

3. In postprocess mode: compares the original file with menuconfig to identify non-#include items that should be written back

4. olddefconfig stores the original compressed include defconfig file at the very beginning

5. savedefconfig saves both the original file and the written back include defconfig

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
xuxin19
2025-09-09 22:05:33 +08:00
committed by Alan C. Assis
parent 476b7684b7
commit e9e9c76a76
6 changed files with 511 additions and 42 deletions
+1 -12
View File
@@ -166,20 +166,9 @@ if(NOT EXISTS "${NUTTX_DEFCONFIG}")
endif()
# Process initial defconfig ###################################################
# Process initial defconfig to recursively expand #include in it
# Process initial defconfig to recursively expand #include in it
include(nuttx_process_config)
get_filename_component(NUTTX_DEFCONFIG_DIR "${NUTTX_DEFCONFIG}" DIRECTORY)
process_config(
${CMAKE_BINARY_DIR}/.defconfig.processed
${NUTTX_DEFCONFIG}
INCLUDE_PATHS
${NUTTX_DEFCONFIG_DIR}/../../common/configs
${NUTTX_DEFCONFIG_DIR}/../common
${NUTTX_DEFCONFIG_DIR}
${NUTTX_DIR}/../apps
${NUTTX_DIR}/../nuttx-apps)
set(NUTTX_DEFCONFIG ${CMAKE_BINARY_DIR}/.defconfig.processed)
# Generate initial .config ###################################################
# This is needed right before any other configure step so that we can source
+9 -2
View File
@@ -95,6 +95,13 @@ add_custom_target(
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/defconfig
${NUTTX_DEFCONFIG}
COMMAND
${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
postprocess ${CMAKE_BINARY_DIR}/config_tree.json
${CMAKE_BINARY_DIR}/defconfig.orig ${CMAKE_BINARY_DIR}/defconfig
${CMAKE_BINARY_DIR}/defconfig.post
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/defconfig.post ${NUTTX_DEFCONFIG}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/defconfig.post ${NUTTX_ORIG_DEFCONFIG}
WORKING_DIRECTORY ${NUTTX_DIR})
+12
View File
@@ -216,6 +216,18 @@ function(nuttx_olddefconfig)
"nuttx_olddefconfig: Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}"
)
endif()
# save the orig compressed formatted defconfig at the very beginning
execute_process(COMMAND savedefconfig --out ${CMAKE_BINARY_DIR}/defconfig.tmp
WORKING_DIRECTORY ${NUTTX_DIR})
execute_process(
COMMAND
${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
${CMAKE_BINARY_DIR}/.config.compressed ${CMAKE_BINARY_DIR}/defconfig.tmp
${CMAKE_BINARY_DIR}/defconfig.orig
WORKING_DIRECTORY ${NUTTX_DIR})
endfunction()
function(nuttx_setconfig)
+36 -4
View File
@@ -20,7 +20,10 @@
#
# ##############################################################################
function(process_config OUTPUT INPUT)
# save preprocess defconfig as orig by default
set(NUTTX_ORIG_DEFCONFIG ${NUTTX_DEFCONFIG})
function(process_config OUTPUT INPUT TREE_FILE)
set(options)
set(oneValueArgs)
set(multiValueArgs INCLUDE_PATHS)
@@ -32,10 +35,14 @@ function(process_config OUTPUT INPUT)
list(APPEND include_args "${path}")
endforeach()
message(STATUS "Processing includes: ${INPUT} -> ${OUTPUT}")
if(TREE_FILE)
set(TREE_OPTION --tree)
endif()
message(STATUS "Processing includes: ${INPUT} → ${OUTPUT}")
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
${OUTPUT} ${INPUT} ${include_args}
COMMAND
${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
preprocess ${OUTPUT} ${INPUT} ${include_args} ${TREE_OPTION} ${TREE_FILE}
RESULT_VARIABLE result
OUTPUT_VARIABLE out
ERROR_VARIABLE err)
@@ -44,3 +51,28 @@ function(process_config OUTPUT INPUT)
message(FATAL_ERROR "Failed to process includes:\n${err}")
endif()
endfunction()
# fetch defconfig content
file(READ "${NUTTX_DEFCONFIG}" FILE_CONTENTS)
string(FIND "${FILE_CONTENTS}" "#include" INCLUDE_FOUND)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/.defconfig.processed)
set(TREE_FILE ${CMAKE_BINARY_DIR}/config_tree.json)
else()
set(TREE_FILE ${CMAKE_BINARY_DIR}/config_tree_dirty.json)
endif()
# Should we preprocess defconfig?
if(INCLUDE_FOUND GREATER -1)
get_filename_component(NUTTX_DEFCONFIG_DIR "${NUTTX_DEFCONFIG}" DIRECTORY)
process_config(
${CMAKE_BINARY_DIR}/.defconfig.processed
${NUTTX_DEFCONFIG}
${TREE_FILE}
INCLUDE_PATHS
${NUTTX_DEFCONFIG_DIR}/../../common/configs
${NUTTX_DEFCONFIG_DIR}/../common
${NUTTX_DEFCONFIG_DIR}
${NUTTX_DIR}/../apps
${NUTTX_DIR}/../nuttx-apps)
set(NUTTX_DEFCONFIG ${CMAKE_BINARY_DIR}/.defconfig.processed)
endif()
+5 -2
View File
@@ -45,8 +45,11 @@ endforeach()
get_filename_component(BINARY_DIR "${TARGET_FILE}" DIRECTORY)
set(OUTPUT_FILE ${BINARY_DIR}/defconfig)
if(CMAKE_ARGV5)
set(OUTPUT_FILE ${CMAKE_ARGV5})
else()
set(OUTPUT_FILE ${BINARY_DIR}/defconfig)
endif()
# cmake-format: off
file(WRITE ${OUTPUT_FILE} "")
file(APPEND ${OUTPUT_FILE} "\#\n")
Regular → Executable
+448 -22
View File
File diff suppressed because it is too large Load Diff