cmake: extensions: Change zephyr_file() argument parser prefix

Replace `FILE` with `ZFILE` as the prefix for `cmake_parse_arguments()`.
This is because `zephyr_file()` accepts `SUFFIX` as function argument,
and it should not be accessible as `FILE_SUFFIX` as it would conflict
with the CMake cache variable of the same name. Accessing the argument
as `ZFILE_SUFFIX` prevents the cached value from slipping into the
function scope.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
This commit is contained in:
Grzegorz Swiderski 2024-03-12 18:42:45 +01:00 committed by Fabio Baltieri
parent 438c95458f
commit 50f0454fbd

View file

@ -2535,75 +2535,75 @@ Please provide one of following: APPLICATION_ROOT, CONF_FILES")
set(multi_args CONF_FILES NAMES)
endif()
cmake_parse_arguments(FILE "${options}" "${single_args}" "${multi_args}" ${ARGN})
if(FILE_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "zephyr_file(${ARGV0} <val> ...) given unknown arguments: ${FILE_UNPARSED_ARGUMENTS}")
cmake_parse_arguments(ZFILE "${options}" "${single_args}" "${multi_args}" ${ARGN})
if(ZFILE_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "zephyr_file(${ARGV0} <val> ...) given unknown arguments: ${ZFILE_UNPARSED_ARGUMENTS}")
endif()
if(FILE_APPLICATION_ROOT)
if(ZFILE_APPLICATION_ROOT)
# Note: user can do: `-D<var>=<relative-path>` and app can at same
# time specify `list(APPEND <var> <abs-path>)`
# Thus need to check and update only CACHED variables (-D<var>).
set(CACHED_PATH $CACHE{${FILE_APPLICATION_ROOT}})
set(CACHED_PATH $CACHE{${ZFILE_APPLICATION_ROOT}})
foreach(path ${CACHED_PATH})
# The cached variable is relative path, i.e. provided by `-D<var>` or
# `set(<var> CACHE)`, so let's update current scope variable to absolute
# path from `APPLICATION_SOURCE_DIR`.
if(NOT IS_ABSOLUTE ${path})
set(abs_path ${APPLICATION_SOURCE_DIR}/${path})
list(FIND ${FILE_APPLICATION_ROOT} ${path} index)
list(FIND ${ZFILE_APPLICATION_ROOT} ${path} index)
if(NOT ${index} LESS 0)
list(REMOVE_AT ${FILE_APPLICATION_ROOT} ${index})
list(INSERT ${FILE_APPLICATION_ROOT} ${index} ${abs_path})
list(REMOVE_AT ${ZFILE_APPLICATION_ROOT} ${index})
list(INSERT ${ZFILE_APPLICATION_ROOT} ${index} ${abs_path})
endif()
endif()
endforeach()
# Now all cached relative paths has been updated.
# Let's check if anyone uses relative path as scoped variable, and fail
foreach(path ${${FILE_APPLICATION_ROOT}})
foreach(path ${${ZFILE_APPLICATION_ROOT}})
if(NOT IS_ABSOLUTE ${path})
message(FATAL_ERROR
"Relative path encountered in scoped variable: ${FILE_APPLICATION_ROOT}, value=${path}\n \
Please adjust any `set(${FILE_APPLICATION_ROOT} ${path})` or `list(APPEND ${FILE_APPLICATION_ROOT} ${path})`\n \
"Relative path encountered in scoped variable: ${ZFILE_APPLICATION_ROOT}, value=${path}\n \
Please adjust any `set(${ZFILE_APPLICATION_ROOT} ${path})` or `list(APPEND ${ZFILE_APPLICATION_ROOT} ${path})`\n \
to absolute path using `\${CMAKE_CURRENT_SOURCE_DIR}/${path}` or similar. \n \
Relative paths are only allowed with `-D${ARGV1}=<path>`")
endif()
endforeach()
# This updates the provided argument in parent scope (callers scope)
set(${FILE_APPLICATION_ROOT} ${${FILE_APPLICATION_ROOT}} PARENT_SCOPE)
set(${ZFILE_APPLICATION_ROOT} ${${ZFILE_APPLICATION_ROOT}} PARENT_SCOPE)
endif()
if(FILE_CONF_FILES)
if(DEFINED FILE_BOARD_REVISION AND NOT FILE_BOARD)
if(ZFILE_CONF_FILES)
if(DEFINED ZFILE_BOARD_REVISION AND NOT ZFILE_BOARD)
message(FATAL_ERROR
"zephyr_file(${ARGV0} <path> BOARD_REVISION ${FILE_BOARD_REVISION} ...)"
"zephyr_file(${ARGV0} <path> BOARD_REVISION ${ZFILE_BOARD_REVISION} ...)"
" given without BOARD argument, please specify BOARD"
)
endif()
if(NOT DEFINED FILE_BOARD)
if(NOT DEFINED ZFILE_BOARD)
# Defaulting to system wide settings when BOARD is not given as argument
set(FILE_BOARD ${BOARD})
set(ZFILE_BOARD ${BOARD})
if(DEFINED BOARD_REVISION)
set(FILE_BOARD_REVISION ${BOARD_REVISION})
set(ZFILE_BOARD_REVISION ${BOARD_REVISION})
endif()
if(DEFINED BOARD_QUALIFIERS)
set(FILE_BOARD_QUALIFIERS ${BOARD_QUALIFIERS})
set(ZFILE_BOARD_QUALIFIERS ${BOARD_QUALIFIERS})
endif()
endif()
if(FILE_NAMES)
set(dts_filename_list ${FILE_NAMES})
set(kconf_filename_list ${FILE_NAMES})
if(ZFILE_NAMES)
set(dts_filename_list ${ZFILE_NAMES})
set(kconf_filename_list ${ZFILE_NAMES})
else()
zephyr_build_string(filename_list
BOARD ${FILE_BOARD}
BOARD_REVISION ${FILE_BOARD_REVISION}
BOARD_QUALIFIERS ${FILE_BOARD_QUALIFIERS}
BUILD ${FILE_BUILD}
BOARD ${ZFILE_BOARD}
BOARD_REVISION ${ZFILE_BOARD_REVISION}
BOARD_QUALIFIERS ${ZFILE_BOARD_QUALIFIERS}
BUILD ${ZFILE_BUILD}
MERGE REVERSE
)
list(REMOVE_DUPLICATES filename_list)
@ -2614,24 +2614,24 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
list(TRANSFORM kconf_filename_list APPEND ".conf")
endif()
if(FILE_DTS)
foreach(path ${FILE_CONF_FILES})
if(ZFILE_DTS)
foreach(path ${ZFILE_CONF_FILES})
foreach(filename ${dts_filename_list})
if(NOT IS_ABSOLUTE ${filename})
set(test_file ${path}/${filename})
else()
set(test_file ${filename})
endif()
zephyr_file_suffix(test_file SUFFIX ${FILE_SUFFIX})
zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX})
if(EXISTS ${test_file})
list(APPEND ${FILE_DTS} ${test_file})
list(APPEND ${ZFILE_DTS} ${test_file})
if(DEFINED FILE_BUILD)
if(DEFINED ZFILE_BUILD)
set(deprecated_file_found y)
endif()
if(FILE_NAMES)
if(ZFILE_NAMES)
break()
endif()
endif()
@ -2639,31 +2639,31 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
endforeach()
# This updates the provided list in parent scope (callers scope)
set(${FILE_DTS} ${${FILE_DTS}} PARENT_SCOPE)
set(${ZFILE_DTS} ${${ZFILE_DTS}} PARENT_SCOPE)
if(NOT ${FILE_DTS})
if(NOT ${ZFILE_DTS})
set(not_found ${dts_filename_list})
endif()
endif()
if(FILE_KCONF)
foreach(path ${FILE_CONF_FILES})
if(ZFILE_KCONF)
foreach(path ${ZFILE_CONF_FILES})
foreach(filename ${kconf_filename_list})
if(NOT IS_ABSOLUTE ${filename})
set(test_file ${path}/${filename})
else()
set(test_file ${filename})
endif()
zephyr_file_suffix(test_file SUFFIX ${FILE_SUFFIX})
zephyr_file_suffix(test_file SUFFIX ${ZFILE_SUFFIX})
if(EXISTS ${test_file})
list(APPEND ${FILE_KCONF} ${test_file})
list(APPEND ${ZFILE_KCONF} ${test_file})
if(DEFINED FILE_BUILD)
if(DEFINED ZFILE_BUILD)
set(deprecated_file_found y)
endif()
if(FILE_NAMES)
if(ZFILE_NAMES)
break()
endif()
endif()
@ -2671,16 +2671,16 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
endforeach()
# This updates the provided list in parent scope (callers scope)
set(${FILE_KCONF} ${${FILE_KCONF}} PARENT_SCOPE)
set(${ZFILE_KCONF} ${${ZFILE_KCONF}} PARENT_SCOPE)
if(NOT ${FILE_KCONF})
if(NOT ${ZFILE_KCONF})
set(not_found ${kconf_filename_list})
endif()
endif()
if(FILE_REQUIRED AND DEFINED not_found)
if(ZFILE_REQUIRED AND DEFINED not_found)
message(FATAL_ERROR
"No ${not_found} file(s) was found in the ${FILE_CONF_FILES} folder(s), "
"No ${not_found} file(s) was found in the ${ZFILE_CONF_FILES} folder(s), "
"please read the Zephyr documentation on application development."
)
endif()
@ -2690,17 +2690,17 @@ Relative paths are only allowed with `-D${ARGV1}=<path>`")
" you should switch to using -DFILE_SUFFIX instead")
endif()
if(FILE_DEFCONFIG)
foreach(path ${FILE_CONF_FILES})
if(ZFILE_DEFCONFIG)
foreach(path ${ZFILE_CONF_FILES})
foreach(filename ${filename_list})
if(EXISTS ${path}/${filename}_defconfig)
list(APPEND ${FILE_DEFCONFIG} ${path}/${filename}_defconfig)
list(APPEND ${ZFILE_DEFCONFIG} ${path}/${filename}_defconfig)
endif()
endforeach()
endforeach()
# This updates the provided list in parent scope (callers scope)
set(${FILE_DEFCONFIG} ${${FILE_DEFCONFIG}} PARENT_SCOPE)
set(${ZFILE_DEFCONFIG} ${${ZFILE_DEFCONFIG}} PARENT_SCOPE)
endif()
endif()
endfunction()