|
1 | | -From 662ed0c8d056ab5ee16078f7e9e71a769521d041 Mon Sep 17 00:00:00 2001 |
| 1 | +From f590feca1568a99caf6741cf0f0326a82a2f9e3d Mon Sep 17 00:00:00 2001 |
2 | 2 | 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 |
4 | 4 | Subject: [PATCH] west sysbuild allows using application cmake presets |
5 | 5 |
|
6 | 6 | --- |
7 | | - scripts/west_commands/build.py | 27 +++++++++++++++++++++++++++ |
| 7 | + scripts/west_commands/build.py | 29 +++++++++++++++++++++++++++++ |
8 | 8 | share/sysbuild/.gitignore | 1 + |
9 | | - 2 files changed, 28 insertions(+) |
| 9 | + 2 files changed, 30 insertions(+) |
10 | 10 | create mode 100644 share/sysbuild/.gitignore |
11 | 11 |
|
12 | 12 | diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py |
13 | | -index 1b7bf3b80a..89340a524c 100644 |
| 13 | +index 1b7bf3b80a..ae931c9d46 100644 |
14 | 14 | --- a/scripts/west_commands/build.py |
15 | 15 | +++ 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): |
28 | 17 | config_sysbuild = True |
29 | 18 |
|
30 | 19 | 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' |
31 | 25 | + try: |
| 26 | ++ # Only copy if source exists and build doesn't, or source is newer |
32 | 27 | + 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 |
39 | 31 | + ) |
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) |
42 | 46 | + 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}') |
44 | 48 | + |
45 | 49 | cmake_opts.extend([f'-S{SYSBUILD_PROJ_DIR}', |
46 | 50 | f'-DAPP_DIR:PATH={self.source_dir}']) |
47 | 51 | 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): |
64 | 52 | diff --git a/share/sysbuild/.gitignore b/share/sysbuild/.gitignore |
65 | 53 | new file mode 100644 |
66 | 54 | index 0000000000..71585613e9 |
|
0 commit comments