Skip to content

Commit 0933a4b

Browse files
tejlmandde-nordic
authored andcommitted
[nrf fromtree] 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 <[email protected]> (cherry picked from commit ba48dd8) (cherry picked from commit b9d092e)
1 parent 1a2b276 commit 0933a4b

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

cmake/modules/configuration_files.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,5 @@ DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\"")
116116
# The DTC_OVERLAY_FILE variable is now set to its final value.
117117
zephyr_boilerplate_watch(DTC_OVERLAY_FILE)
118118

119-
zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG)
120-
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL)
119+
zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG MERGE REVERSE)
120+
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL MERGE REVERSE)

cmake/modules/extensions.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2568,9 +2568,13 @@ function(zephyr_get variable)
25682568
else()
25692569
set(sysbuild_${var})
25702570
endif()
2571+
2572+
if(TARGET snippets_scope)
2573+
get_property(snippets_${var} TARGET snippets_scope PROPERTY ${var})
2574+
endif()
25712575
endforeach()
25722576

2573-
set(scopes "sysbuild;CACHE;ENV;current")
2577+
set(scopes "sysbuild;CACHE;snippets;ENV;current")
25742578
if(GET_VAR_REVERSE)
25752579
list(REVERSE scopes)
25762580
endif()

cmake/modules/snippets.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ function(zephyr_process_snippets)
9393
endif()
9494
include(${snippets_generated})
9595

96-
# Propagate include()d build system settings to the caller.
97-
set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} PARENT_SCOPE)
98-
set(OVERLAY_CONFIG ${OVERLAY_CONFIG} PARENT_SCOPE)
99-
10096
# Create the 'snippets' target. Each snippet is printed in a
10197
# separate command because build system files are not fond of
10298
# newlines.

scripts/snippets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def print_cmake(self):
133133
# The paths to all the snippet.yml files. One snippet
134134
# can have multiple snippet.yml files.
135135
set(SNIPPET_PATHS {snippet_path_list})
136+
137+
# Create variable scope for snippets build variables
138+
zephyr_create_scope(snippets)
136139
''')
137140

138141
for snippet_name in snippet_names:
@@ -168,7 +171,7 @@ def print_appends(self, appends: Appends, indent: int):
168171
space = ' ' * indent
169172
for name, values in appends.items():
170173
for value in values:
171-
self.print(f'{space}list(APPEND {name} {value})')
174+
self.print(f'{space}zephyr_set({name} {value} SCOPE snippets APPEND)')
172175

173176
def print(self, *args, **kwargs):
174177
kwargs['file'] = self.out_file

0 commit comments

Comments
 (0)