cmake: support snippets scope for zephyr_get()
Fixes: #57139 Snippets provides the possibility of defining EXTRA_DTC_OVERLAY_FILE and EXTRA_CONF_FILE in snippets. Snippets must co-exist with existing infrastructure of EXTRA_DTC_OVERLAY_FILE and EXTRA_CONF_FILE, and a user specifying a snippet must be able to specify extra files for adjusting the snippet. This means that if the following is specified: `-DSNIPPET=some_snippet -DEXTRA_CONF_FILE=extra.conf` then `extra.conf` may contain adjustments to the snippet. Similar to sysbuild. Imagine a sysbuild controlled image uses a default snippet for building, by ensuring that any extra `-D<image>_EXTRA_CONF_FILE=extra.conf` arguments takes precedence over the snippet we allow users to make adjustments if they need. This commit introduces a snippets scope where snippet scoped variables can be set with `zephyr_set()` and then `zephyr_get()` will take the snippet scoped variables into consideration before returning. Adjust calls to `zephyr_get(EXTRA_DTC_OVERLAY_FILE)` and `zephyr_get(EXTRA_CONF_FILE)` to use `MERGE` to ensure all scopes are considered. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
a6d9105d51
commit
ba48dd8763
|
@ -116,5 +116,5 @@ DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\"")
|
||||||
# The DTC_OVERLAY_FILE variable is now set to its final value.
|
# The DTC_OVERLAY_FILE variable is now set to its final value.
|
||||||
zephyr_boilerplate_watch(DTC_OVERLAY_FILE)
|
zephyr_boilerplate_watch(DTC_OVERLAY_FILE)
|
||||||
|
|
||||||
zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG)
|
zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG MERGE REVERSE)
|
||||||
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL)
|
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL MERGE REVERSE)
|
||||||
|
|
|
@ -2568,9 +2568,13 @@ function(zephyr_get variable)
|
||||||
else()
|
else()
|
||||||
set(sysbuild_${var})
|
set(sysbuild_${var})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(TARGET snippets_scope)
|
||||||
|
get_property(snippets_${var} TARGET snippets_scope PROPERTY ${var})
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set(scopes "sysbuild;CACHE;ENV;current")
|
set(scopes "sysbuild;CACHE;snippets;ENV;current")
|
||||||
if(GET_VAR_REVERSE)
|
if(GET_VAR_REVERSE)
|
||||||
list(REVERSE scopes)
|
list(REVERSE scopes)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -93,10 +93,6 @@ function(zephyr_process_snippets)
|
||||||
endif()
|
endif()
|
||||||
include(${snippets_generated})
|
include(${snippets_generated})
|
||||||
|
|
||||||
# Propagate include()d build system settings to the caller.
|
|
||||||
set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} PARENT_SCOPE)
|
|
||||||
set(OVERLAY_CONFIG ${OVERLAY_CONFIG} PARENT_SCOPE)
|
|
||||||
|
|
||||||
# Create the 'snippets' target. Each snippet is printed in a
|
# Create the 'snippets' target. Each snippet is printed in a
|
||||||
# separate command because build system files are not fond of
|
# separate command because build system files are not fond of
|
||||||
# newlines.
|
# newlines.
|
||||||
|
|
|
@ -133,6 +133,9 @@ set(SNIPPET_NAMES {' '.join(f'"{name}"' for name in snippet_names)})
|
||||||
# The paths to all the snippet.yml files. One snippet
|
# The paths to all the snippet.yml files. One snippet
|
||||||
# can have multiple snippet.yml files.
|
# can have multiple snippet.yml files.
|
||||||
set(SNIPPET_PATHS {snippet_path_list})
|
set(SNIPPET_PATHS {snippet_path_list})
|
||||||
|
|
||||||
|
# Create variable scope for snippets build variables
|
||||||
|
zephyr_create_scope(snippets)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
for snippet_name in snippet_names:
|
for snippet_name in snippet_names:
|
||||||
|
@ -168,7 +171,7 @@ if("${{BOARD}}" STREQUAL "{board}")''')
|
||||||
space = ' ' * indent
|
space = ' ' * indent
|
||||||
for name, values in appends.items():
|
for name, values in appends.items():
|
||||||
for value in values:
|
for value in values:
|
||||||
self.print(f'{space}list(APPEND {name} {value})')
|
self.print(f'{space}zephyr_set({name} {value} SCOPE snippets APPEND)')
|
||||||
|
|
||||||
def print(self, *args, **kwargs):
|
def print(self, *args, **kwargs):
|
||||||
kwargs['file'] = self.out_file
|
kwargs['file'] = self.out_file
|
||||||
|
|
Loading…
Reference in a new issue