Skip to content

Commit

Permalink
[nrf fromtree] cmake: support snippets scope for zephyr_get()
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit ba48dd8)
(cherry picked from commit b9d092e)
  • Loading branch information
tejlmand authored and de-nordic committed May 26, 2023
1 parent 1a2b276 commit 0933a4b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmake/modules/configuration_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\"")
# The DTC_OVERLAY_FILE variable is now set to its final value.
zephyr_boilerplate_watch(DTC_OVERLAY_FILE)

zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG)
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL)
zephyr_get(EXTRA_CONF_FILE SYSBUILD LOCAL VAR EXTRA_CONF_FILE OVERLAY_CONFIG MERGE REVERSE)
zephyr_get(EXTRA_DTC_OVERLAY_FILE SYSBUILD LOCAL MERGE REVERSE)
6 changes: 5 additions & 1 deletion cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2568,9 +2568,13 @@ function(zephyr_get variable)
else()
set(sysbuild_${var})
endif()

if(TARGET snippets_scope)
get_property(snippets_${var} TARGET snippets_scope PROPERTY ${var})
endif()
endforeach()

set(scopes "sysbuild;CACHE;ENV;current")
set(scopes "sysbuild;CACHE;snippets;ENV;current")
if(GET_VAR_REVERSE)
list(REVERSE scopes)
endif()
Expand Down
4 changes: 0 additions & 4 deletions cmake/modules/snippets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ function(zephyr_process_snippets)
endif()
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
# separate command because build system files are not fond of
# newlines.
Expand Down
5 changes: 4 additions & 1 deletion scripts/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def print_cmake(self):
# The paths to all the snippet.yml files. One snippet
# can have multiple snippet.yml files.
set(SNIPPET_PATHS {snippet_path_list})
# Create variable scope for snippets build variables
zephyr_create_scope(snippets)
''')

for snippet_name in snippet_names:
Expand Down Expand Up @@ -168,7 +171,7 @@ def print_appends(self, appends: Appends, indent: int):
space = ' ' * indent
for name, values in appends.items():
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):
kwargs['file'] = self.out_file
Expand Down

0 comments on commit 0933a4b

Please sign in to comment.