Skip to content

Conversation

@tejlmand
Copy link
Contributor

Cherry-pick series of commits from upstream to have extended build info present in NCS.

pillo79 and others added 9 commits March 10, 2025 12:42
This introductory commit refactors the `yaml_set` function separating
the bodies of list operations into internal functions while preserving
their original behavior.

The conditions that cause the value to be interpreted as a list are also
verified only once, avoiding multiple checks.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
(cherry picked from commit cf5607f)
This commit adds support for generator expressions in values and lists
to the yaml module.

Generator expressions can only be expanded by CMake after all
configuration code has been executed and the final values of the project
properties are defined. This means that contexts that contain generator
expressions are written twice:

 - immediately, during the 'yaml_save()' call, a comment with the raw
   unexpanded string is saved instead of the key that uses generator
   expressions in the YAML file;

 - after the configuration step, a custom command updates the YAML file
   contents with the fully expanded values.

This two-step process also allows to overcome the issue of lists that
are extracted from generator expressions, whose elements would be
expanded into a single string if written directly to the YAML file.
Instead, the lists are stored in their CMake string format with a
special marker, expanded by CMake into a temporary JSON file, and the
conversion to a proper list is performed during the build step.

If the saved YAML file for context <name> is needed by further build
steps in this project, the target '<name>_yaml_saved' must be added as a
dependency to ensure the final contents are ready.

Note that when generator expressions are used in the context, the GENEX
keyword must be provided to yaml_set(). This is necessary to avoid
storing the genexes as raw strings in the YAML.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
(cherry picked from commit cdc7f05)
Use a more concise way to append to a list property, as suggested in a
previous PR review.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
(cherry picked from commit 8e66848)
The schema for build info already contained a `board:path` sequence tag
definition, but boards.cmake did not populate this in the generated
build_info.yml.

Fix this by correctly populating the `board:path` with list of board
directories.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit b78c269)
This commit introduce support for maps in a yaml list.

The yaml_set() function has been extended with the following signature:
> yaml_set(NAME <name> KEY <key>...
>          [APPEND] LIST MAP <map1> MAP <map2> MAP ...
> )

where a `MAP <map>` has the form:
`MAP "<key1>: <value1>, <key2>: <value2>, ...`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit 0828d0b)
Add 'images' as valid list in build info schema.
This allow sysbuild and regular Zephyr images to populate build_info.yml
with images included in the build.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit 4061311)
Populate the build_info.yml created by sysbuild CMake with list of
images and write the build info file afterwards.

This allows users and external tools to examine which images was
included in the build even if one or more of those images fails CMake
configure or generate stage.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit 642e948)
Escape the json input string given to `to_yaml()` function and the
content given to `yaml_set()` function.

This ensures that a string like `foo\bar` becomes `foo\\bar` during
internal CMake json processing and when written to the file it becomes
`foo\bar`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit cdbe424)
Do not escape single escaped quote '\"'.
A single escape quote in CMake indicates the use of literal '"'.
Escaping those results in '\\"' which is a literal '\' and a quote which
encapsulates a string.
This is a result we do not want.
Therefore, exempt the '\"' sequence from further escaping.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit 991396c)
@tejlmand tejlmand force-pushed the extended_build_info branch from f46c86d to 651f056 Compare March 10, 2025 11:43
@tejlmand tejlmand requested a review from kylebonnici March 11, 2025 08:47
Copy link
Contributor

@kylebonnici kylebonnici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was tested upstream (zephyrproject-rtos/zephyr#84906)

@tejlmand tejlmand merged commit eab01fb into nrfconnect:main Mar 27, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants