Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Commit 9d39f27

Browse files
committed
rework sysbuild cmake preset handling patch
* the actual file is written to build dir, symlinked to zephyr repo * symlink isn't deleted after a build
1 parent 4084d1b commit 9d39f27

1 file changed

Lines changed: 30 additions & 42 deletions

File tree

patches/zephyr/0001-west-sysbuild-allows-using-application-cmake-presets.patch

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,54 @@
1-
From 662ed0c8d056ab5ee16078f7e9e71a769521d041 Mon Sep 17 00:00:00 2001
1+
From f590feca1568a99caf6741cf0f0326a82a2f9e3d Mon Sep 17 00:00:00 2001
22
From: Benedek Kupper <kupper.benedek@gmail.com>
3-
Date: Wed, 27 Aug 2025 10:09:00 +0200
3+
Date: Sat, 6 Sep 2025 10:30:57 +0200
44
Subject: [PATCH] west sysbuild allows using application cmake presets
55

66
---
7-
scripts/west_commands/build.py | 27 +++++++++++++++++++++++++++
7+
scripts/west_commands/build.py | 29 +++++++++++++++++++++++++++++
88
share/sysbuild/.gitignore | 1 +
9-
2 files changed, 28 insertions(+)
9+
2 files changed, 30 insertions(+)
1010
create mode 100644 share/sysbuild/.gitignore
1111

1212
diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py
13-
index 1b7bf3b80a..89340a524c 100644
13+
index 1b7bf3b80a..ae931c9d46 100644
1414
--- a/scripts/west_commands/build.py
1515
+++ b/scripts/west_commands/build.py
16-
@@ -624,6 +624,10 @@ class Build(Forceable):
17-
if user_args:
18-
cmake_opts.extend(shlex.split(user_args))
19-
20-
+ # sysbuild has its own cmake project directory, so we need to
21-
+ # copy the application's CMakePresets.json file and replace the paths
22-
+ sysbuild_presets = SYSBUILD_PROJ_DIR / 'CMakePresets.json'
23-
+ source_presets = pathlib.Path(self.source_dir) / 'CMakePresets.json'
24-
config_sysbuild = config_getboolean('sysbuild', None)
25-
26-
if config_sysbuild is None:
27-
@@ -631,6 +635,20 @@ class Build(Forceable):
16+
@@ -631,6 +631,35 @@ class Build(Forceable):
2817
config_sysbuild = True
2918

3019
if self.args.sysbuild or (config_sysbuild and not self.args.no_sysbuild):
20+
+ # sysbuild has its own cmake project directory, so we need to
21+
+ # copy the application's CMakePresets.json file and replace the paths
22+
+ sysbuild_presets_link = SYSBUILD_PROJ_DIR / 'CMakePresets.json'
23+
+ build_presets = pathlib.Path(self.build_dir) / 'CMakePresets.json'
24+
+ source_presets = pathlib.Path(self.source_dir) / 'CMakePresets.json'
3125
+ try:
26+
+ # Only copy if source exists and build doesn't, or source is newer
3227
+ if source_presets.exists():
33-
+ with open(source_presets, 'r') as f:
34-
+ content = f.read()
35-
+ content = (content
36-
+ .replace("${sourceDir}", self.source_dir)
37-
+ .replace("${sourceParentDir}", str(pathlib.Path(self.source_dir).parent))
38-
+ .replace("${sourceDirName}", str(pathlib.Path(self.source_dir).name))
28+
+ copy_needed = (
29+
+ not build_presets.exists() or
30+
+ source_presets.stat().st_mtime > build_presets.stat().st_mtime
3931
+ )
40-
+ with open(sysbuild_presets, 'w') as f:
41-
+ f.write(content)
32+
+ if copy_needed:
33+
+ with open(source_presets, 'r') as f:
34+
+ content = f.read()
35+
+ content = (content
36+
+ .replace("${sourceDir}", self.source_dir)
37+
+ .replace("${sourceParentDir}", str(pathlib.Path(self.source_dir).parent))
38+
+ .replace("${sourceDirName}", str(pathlib.Path(self.source_dir).name))
39+
+ )
40+
+ with open(build_presets, 'w') as f:
41+
+ f.write(content)
42+
+ # Create symlink if needed
43+
+ if sysbuild_presets_link.exists() or sysbuild_presets_link.is_symlink():
44+
+ sysbuild_presets_link.unlink()
45+
+ sysbuild_presets_link.symlink_to(build_presets)
4246
+ except Exception as e:
43-
+ self.wrn(f'Failed to adopt CMakePresets.json to sysbuild: {e}')
47+
+ self.wrn(f'Failed to mirror CMakePresets.json to build dir and link: {e}')
4448
+
4549
cmake_opts.extend([f'-S{SYSBUILD_PROJ_DIR}',
4650
f'-DAPP_DIR:PATH={self.source_dir}'])
4751
else:
48-
@@ -650,6 +668,15 @@ class Build(Forceable):
49-
final_cmake_args.extend(cmake_opts)
50-
run_cmake(final_cmake_args, dry_run=self.args.dry_run)
51-
52-
+ # clean up the sysbuild CMakePresets.json file after each run
53-
+ if sysbuild_presets.exists():
54-
+ try:
55-
+ sysbuild_presets.unlink()
56-
+ except FileNotFoundError:
57-
+ pass
58-
+ except Exception as e:
59-
+ self.wrn(f'Failed to remove sysbuild CMakePresets.json: {e}')
60-
+
61-
def _run_pristine(self):
62-
self._banner(f'making build dir {self.build_dir} pristine')
63-
if not is_zephyr_build(self.build_dir):
6452
diff --git a/share/sysbuild/.gitignore b/share/sysbuild/.gitignore
6553
new file mode 100644
6654
index 0000000000..71585613e9

0 commit comments

Comments
 (0)