Skip to content

Commit e9e9c76

Browse files
xuxin930acassis
authored andcommitted
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>
1 parent 476b768 commit e9e9c76

File tree

6 files changed

+511
-42
lines changed

6 files changed

+511
-42
lines changed

CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,9 @@ if(NOT EXISTS "${NUTTX_DEFCONFIG}")
166166
endif()
167167

168168
# Process initial defconfig ###################################################
169-
# Process initial defconfig to recursively expand #include in it
170169

170+
# Process initial defconfig to recursively expand #include in it
171171
include(nuttx_process_config)
172-
get_filename_component(NUTTX_DEFCONFIG_DIR "${NUTTX_DEFCONFIG}" DIRECTORY)
173-
process_config(
174-
${CMAKE_BINARY_DIR}/.defconfig.processed
175-
${NUTTX_DEFCONFIG}
176-
INCLUDE_PATHS
177-
${NUTTX_DEFCONFIG_DIR}/../../common/configs
178-
${NUTTX_DEFCONFIG_DIR}/../common
179-
${NUTTX_DEFCONFIG_DIR}
180-
${NUTTX_DIR}/../apps
181-
${NUTTX_DIR}/../nuttx-apps)
182-
set(NUTTX_DEFCONFIG ${CMAKE_BINARY_DIR}/.defconfig.processed)
183172

184173
# Generate initial .config ###################################################
185174
# This is needed right before any other configure step so that we can source

cmake/menuconfig.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ add_custom_target(
9595
${CMAKE_BINARY_DIR}/defconfig.tmp
9696
COMMAND ${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
9797
${CMAKE_BINARY_DIR}/.config ${CMAKE_BINARY_DIR}/defconfig.tmp
98-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/defconfig
99-
${NUTTX_DEFCONFIG}
98+
COMMAND
99+
${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
100+
postprocess ${CMAKE_BINARY_DIR}/config_tree.json
101+
${CMAKE_BINARY_DIR}/defconfig.orig ${CMAKE_BINARY_DIR}/defconfig
102+
${CMAKE_BINARY_DIR}/defconfig.post
103+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
104+
${CMAKE_BINARY_DIR}/defconfig.post ${NUTTX_DEFCONFIG}
105+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
106+
${CMAKE_BINARY_DIR}/defconfig.post ${NUTTX_ORIG_DEFCONFIG}
100107
WORKING_DIRECTORY ${NUTTX_DIR})

cmake/nuttx_kconfig.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ function(nuttx_olddefconfig)
216216
"nuttx_olddefconfig: Failed to initialize Kconfig configuration: ${KCONFIG_OUTPUT}"
217217
)
218218
endif()
219+
220+
# save the orig compressed formatted defconfig at the very beginning
221+
execute_process(COMMAND savedefconfig --out ${CMAKE_BINARY_DIR}/defconfig.tmp
222+
WORKING_DIRECTORY ${NUTTX_DIR})
223+
224+
execute_process(
225+
COMMAND
226+
${CMAKE_COMMAND} -P ${NUTTX_DIR}/cmake/savedefconfig.cmake
227+
${CMAKE_BINARY_DIR}/.config.compressed ${CMAKE_BINARY_DIR}/defconfig.tmp
228+
${CMAKE_BINARY_DIR}/defconfig.orig
229+
WORKING_DIRECTORY ${NUTTX_DIR})
230+
219231
endfunction()
220232

221233
function(nuttx_setconfig)

cmake/nuttx_process_config.cmake

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#
2121
# ##############################################################################
2222

23-
function(process_config OUTPUT INPUT)
23+
# save preprocess defconfig as orig by default
24+
set(NUTTX_ORIG_DEFCONFIG ${NUTTX_DEFCONFIG})
25+
26+
function(process_config OUTPUT INPUT TREE_FILE)
2427
set(options)
2528
set(oneValueArgs)
2629
set(multiValueArgs INCLUDE_PATHS)
@@ -32,10 +35,14 @@ function(process_config OUTPUT INPUT)
3235
list(APPEND include_args "${path}")
3336
endforeach()
3437

35-
message(STATUS "Processing includes: ${INPUT} -> ${OUTPUT}")
38+
if(TREE_FILE)
39+
set(TREE_OPTION --tree)
40+
endif()
41+
message(STATUS "Processing includes: ${INPUT}${OUTPUT}")
3642
execute_process(
37-
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
38-
${OUTPUT} ${INPUT} ${include_args}
43+
COMMAND
44+
${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/process_config.py
45+
preprocess ${OUTPUT} ${INPUT} ${include_args} ${TREE_OPTION} ${TREE_FILE}
3946
RESULT_VARIABLE result
4047
OUTPUT_VARIABLE out
4148
ERROR_VARIABLE err)
@@ -44,3 +51,28 @@ function(process_config OUTPUT INPUT)
4451
message(FATAL_ERROR "Failed to process includes:\n${err}")
4552
endif()
4653
endfunction()
54+
55+
# fetch defconfig content
56+
file(READ "${NUTTX_DEFCONFIG}" FILE_CONTENTS)
57+
string(FIND "${FILE_CONTENTS}" "#include" INCLUDE_FOUND)
58+
59+
if(NOT EXISTS ${CMAKE_BINARY_DIR}/.defconfig.processed)
60+
set(TREE_FILE ${CMAKE_BINARY_DIR}/config_tree.json)
61+
else()
62+
set(TREE_FILE ${CMAKE_BINARY_DIR}/config_tree_dirty.json)
63+
endif()
64+
# Should we preprocess defconfig?
65+
if(INCLUDE_FOUND GREATER -1)
66+
get_filename_component(NUTTX_DEFCONFIG_DIR "${NUTTX_DEFCONFIG}" DIRECTORY)
67+
process_config(
68+
${CMAKE_BINARY_DIR}/.defconfig.processed
69+
${NUTTX_DEFCONFIG}
70+
${TREE_FILE}
71+
INCLUDE_PATHS
72+
${NUTTX_DEFCONFIG_DIR}/../../common/configs
73+
${NUTTX_DEFCONFIG_DIR}/../common
74+
${NUTTX_DEFCONFIG_DIR}
75+
${NUTTX_DIR}/../apps
76+
${NUTTX_DIR}/../nuttx-apps)
77+
set(NUTTX_DEFCONFIG ${CMAKE_BINARY_DIR}/.defconfig.processed)
78+
endif()

cmake/savedefconfig.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ endforeach()
4545

4646
get_filename_component(BINARY_DIR "${TARGET_FILE}" DIRECTORY)
4747

48-
set(OUTPUT_FILE ${BINARY_DIR}/defconfig)
49-
48+
if(CMAKE_ARGV5)
49+
set(OUTPUT_FILE ${CMAKE_ARGV5})
50+
else()
51+
set(OUTPUT_FILE ${BINARY_DIR}/defconfig)
52+
endif()
5053
# cmake-format: off
5154
file(WRITE ${OUTPUT_FILE} "")
5255
file(APPEND ${OUTPUT_FILE} "\#\n")

0 commit comments

Comments
 (0)