|
| 1 | +From 662ed0c8d056ab5ee16078f7e9e71a769521d041 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Benedek Kupper <kupper.benedek@gmail.com> |
| 3 | +Date: Wed, 27 Aug 2025 10:09:00 +0200 |
| 4 | +Subject: [PATCH] west sysbuild allows using application cmake presets |
| 5 | + |
| 6 | +--- |
| 7 | + scripts/west_commands/build.py | 27 +++++++++++++++++++++++++++ |
| 8 | + share/sysbuild/.gitignore | 1 + |
| 9 | + 2 files changed, 28 insertions(+) |
| 10 | + create mode 100644 share/sysbuild/.gitignore |
| 11 | + |
| 12 | +diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py |
| 13 | +index 1b7bf3b80a..89340a524c 100644 |
| 14 | +--- a/scripts/west_commands/build.py |
| 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): |
| 28 | + config_sysbuild = True |
| 29 | + |
| 30 | + if self.args.sysbuild or (config_sysbuild and not self.args.no_sysbuild): |
| 31 | ++ try: |
| 32 | ++ 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)) |
| 39 | ++ ) |
| 40 | ++ with open(sysbuild_presets, 'w') as f: |
| 41 | ++ f.write(content) |
| 42 | ++ except Exception as e: |
| 43 | ++ self.wrn(f'Failed to adopt CMakePresets.json to sysbuild: {e}') |
| 44 | ++ |
| 45 | + cmake_opts.extend([f'-S{SYSBUILD_PROJ_DIR}', |
| 46 | + f'-DAPP_DIR:PATH={self.source_dir}']) |
| 47 | + 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 | +diff --git a/share/sysbuild/.gitignore b/share/sysbuild/.gitignore |
| 65 | +new file mode 100644 |
| 66 | +index 0000000000..71585613e9 |
| 67 | +--- /dev/null |
| 68 | ++++ b/share/sysbuild/.gitignore |
| 69 | +@@ -0,0 +1 @@ |
| 70 | ++CMakePresets.json |
| 71 | +\ No newline at end of file |
| 72 | +-- |
| 73 | +2.43.0 |
| 74 | + |
0 commit comments