mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 20:56:47 +08:00
cmake:bugfix generate config.h contain ; characters will be handled incorrectly
`;` is treated as a list separator in CMake. the file(STRING) function will read the wrong .config value string(REGEX REPLACE) will also incorrectly handle lines containing `;` so here we can only parse character by character. Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
8f23a2db01
commit
94d8fba629
@@ -18,14 +18,36 @@
|
|||||||
#
|
#
|
||||||
# ##############################################################################
|
# ##############################################################################
|
||||||
|
|
||||||
|
macro(encode_brackets contents)
|
||||||
|
string(REGEX REPLACE "\\[" "__OPEN_BRACKET__" ${contents} "${${contents}}")
|
||||||
|
string(REGEX REPLACE "\\]" "__CLOSE_BRACKET__" ${contents} "${${contents}}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(decode_brackets contents)
|
||||||
|
string(REGEX REPLACE "__OPEN_BRACKET__" "[" ${contents} "${${contents}}")
|
||||||
|
string(REGEX REPLACE "__CLOSE_BRACKET__" "]" ${contents} "${${contents}}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(encode_semicolon contents)
|
||||||
|
string(REGEX REPLACE ";" "__SEMICOLON__" ${contents} "${${contents}}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(decode_semicolon contents)
|
||||||
|
string(REGEX REPLACE "__SEMICOLON__" ";" ${contents} "${${contents}}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
function(nuttx_export_kconfig_by_value kconfigfile config)
|
function(nuttx_export_kconfig_by_value kconfigfile config)
|
||||||
file(STRINGS ${kconfigfile} ConfigContents)
|
file(STRINGS ${kconfigfile} ConfigContents)
|
||||||
|
encode_brackets(ConfigContents)
|
||||||
foreach(NameAndValue ${ConfigContents})
|
foreach(NameAndValue ${ConfigContents})
|
||||||
|
decode_brackets(NameAndValue)
|
||||||
|
encode_semicolon(NameAndValue)
|
||||||
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
||||||
string(REGEX MATCH "^CONFIG[^=]+" Name ${NameAndValue})
|
string(REGEX MATCH "^CONFIG[^=]+" Name ${NameAndValue})
|
||||||
if(Name STREQUAL ${config})
|
if(Name STREQUAL ${config})
|
||||||
string(REPLACE "${Name}=" "" Value ${NameAndValue})
|
string(REPLACE "${Name}=" "" Value ${NameAndValue})
|
||||||
string(REPLACE "\"" "" Value ${Value})
|
string(REPLACE "\"" "" Value ${Value})
|
||||||
|
decode_semicolon(Value)
|
||||||
set(${Name}
|
set(${Name}
|
||||||
${Value}
|
${Value}
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
@@ -41,7 +63,10 @@ function(nuttx_export_kconfig kconfigfile)
|
|||||||
set(${key} PARENT_SCOPE)
|
set(${key} PARENT_SCOPE)
|
||||||
endforeach()
|
endforeach()
|
||||||
file(STRINGS ${kconfigfile} ConfigContents)
|
file(STRINGS ${kconfigfile} ConfigContents)
|
||||||
|
encode_brackets(ConfigContents)
|
||||||
foreach(NameAndValue ${ConfigContents})
|
foreach(NameAndValue ${ConfigContents})
|
||||||
|
decode_brackets(NameAndValue)
|
||||||
|
encode_semicolon(NameAndValue)
|
||||||
# Strip leading spaces
|
# Strip leading spaces
|
||||||
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
||||||
|
|
||||||
@@ -54,7 +79,7 @@ function(nuttx_export_kconfig kconfigfile)
|
|||||||
|
|
||||||
# remove extra quotes
|
# remove extra quotes
|
||||||
string(REPLACE "\"" "" Value ${Value})
|
string(REPLACE "\"" "" Value ${Value})
|
||||||
|
decode_semicolon(Value)
|
||||||
# Set the variable
|
# Set the variable
|
||||||
set(${Name}
|
set(${Name}
|
||||||
${Value}
|
${Value}
|
||||||
|
|||||||
@@ -92,7 +92,10 @@ file(APPEND ${CONFIG_H}
|
|||||||
file(APPEND ${CONFIG_H} "#define CONFIG_BASE_DEFCONFIG \"${BASE_DEFCONFIG}\"\n")
|
file(APPEND ${CONFIG_H} "#define CONFIG_BASE_DEFCONFIG \"${BASE_DEFCONFIG}\"\n")
|
||||||
|
|
||||||
file(STRINGS ${CMAKE_BINARY_DIR}/.config ConfigContents)
|
file(STRINGS ${CMAKE_BINARY_DIR}/.config ConfigContents)
|
||||||
|
encode_brackets(ConfigContents)
|
||||||
foreach(NameAndValue ${ConfigContents})
|
foreach(NameAndValue ${ConfigContents})
|
||||||
|
decode_brackets(NameAndValue)
|
||||||
|
encode_semicolon(NameAndValue)
|
||||||
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
|
||||||
string(REGEX MATCH "^CONFIG[^=]+" NAME ${NameAndValue})
|
string(REGEX MATCH "^CONFIG[^=]+" NAME ${NameAndValue})
|
||||||
# skip BASE_DEFCONFIG here as it is handled above
|
# skip BASE_DEFCONFIG here as it is handled above
|
||||||
@@ -121,6 +124,7 @@ foreach(NameAndValue ${ConfigContents})
|
|||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
if(NOT "${VALUE}" STREQUAL "")
|
if(NOT "${VALUE}" STREQUAL "")
|
||||||
|
decode_semicolon(VALUE)
|
||||||
file(APPEND ${CONFIG_H} "#define ${NAME} ${VALUE}\n")
|
file(APPEND ${CONFIG_H} "#define ${NAME} ${VALUE}\n")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user