zephyr/tests/cmake
Luca Burelli a90870da4c cmake: yaml: improve escaping of strings with backslashes and quotes
Switching the intermediate file format from JSON to YAML has a very
significant benefit: the file is now loaded via yaml_load(), which
internally calls Python to parse the file into the JSON format that
CMake expects. This means that the file contents are now automatically
escaped properly for JSON; it is a huge improvement over the previous
implementation, which was escaping everything given as input to
to_yaml().

With the removal of the now-redundant call in to_yaml(), escaping is
applied exactly once per value or list, when it is passed to yaml_set().
This allows to convert the logic in zephyr_string(ESCAPE ...) to a more
robust "escape everything" approach.

These changes fix the handling of strings with backslashes and different
types of quotes passed either directly or via generator expression. The
existing tests are updated to cover these cases.

Two other small changes are made in this commit:

- a small check in internal_yaml_list_append() is removed, as the same
  issue is already detected by the caller yaml_set() logic.

- the to_yaml() function is modified to initialize the YAML output
  variable at the top level, which is the expected behavior. This
  resulted in genex temp files sometimes having duplicate lines.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
..
app_version tests: cmake: app_version: test app_version.h 2024-06-24 08:28:54 -04:00
config_dir tests/cmake/*: Switch to native_sim 2023-11-27 16:06:42 +00:00
hwm/board_extend boards: arm: mps2: add pinctrl support for mps2 board 2025-04-07 15:18:10 +02:00
overlays tests: cmake: fix test identifier 2024-07-18 06:47:57 -04:00
snippets tests: cmake: snippets: Exclude sysbuild 2024-12-27 07:18:13 +01:00
sysbuild_snippets tests: cmake: Add sysbuild snippets test 2024-12-27 07:18:13 +01:00
yaml cmake: yaml: improve escaping of strings with backslashes and quotes 2025-04-10 10:11:47 +02:00
zephyr_get tests: cmake: run zephyr_get() tests in script mode 2024-12-26 09:31:11 +01:00