Skip to content

Commit 4ec16a3

Browse files
committed
scripts: extend west build command to support sysbuild CMake project
west build now support the sysbuild CMake project which allows users to easily enable and build a bootloader together with any sample. This will allow for cleaning up samples and boards which already does custom multi image in a non-generic way, for example: - mps2_an521 which includes a build for remote board - samples/ipc/ which includes a samples for remote board - esp32 which includes custom bootloaders Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 86dda45 commit 4ec16a3

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

scripts/west_commands/build.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919

2020
_ARG_SEPARATOR = '--'
2121

22+
SYSBUILD_PROJ_DIR = pathlib.Path(__file__).resolve().parent.parent.parent \
23+
/ pathlib.Path('share/sysbuild')
24+
2225
BUILD_USAGE = '''\
2326
west build [-h] [-b BOARD[@REV]]] [-d BUILD_DIR]
2427
[-t TARGET] [-p {auto, always, never}] [-c] [--cmake-only]
2528
[-n] [-o BUILD_OPT] [-f]
29+
[--sysbuild | --no-sysbuild]
2630
[source_dir] -- [cmake_opt [cmake_opt ...]]
2731
'''
2832

@@ -124,6 +128,13 @@ def do_add_parser(self, parser_adder):
124128
dest='dry_run', action='store_true',
125129
help="just print build commands; don't run them")
126130

131+
group = parser.add_mutually_exclusive_group()
132+
group.add_argument('--sysbuild', action='store_true',
133+
help='''create multi domain build system''')
134+
group.add_argument('--no-sysbuild', action='store_true',
135+
help='''do not create multi domain build system
136+
(default)''')
137+
127138
group = parser.add_argument_group('pristine builds',
128139
PRISTINE_DESCRIPTION)
129140
group.add_argument('-p', '--pristine', choices=['auto', 'always',
@@ -357,9 +368,14 @@ def _sanity_check(self):
357368
# CMake configuration phase.
358369
self.run_cmake = True
359370

360-
cached_app = self.cmake_cache.get('APPLICATION_SOURCE_DIR')
361-
log.dbg('APPLICATION_SOURCE_DIR:', cached_app,
362-
level=log.VERBOSE_EXTREME)
371+
cached_proj = self.cmake_cache.get('APPLICATION_SOURCE_DIR')
372+
cached_app = self.cmake_cache.get('APP_DIR')
373+
# if APP_DIR is None but APPLICATION_SOURCE_DIR is set, that indicates
374+
# an older build folder, this still requires pristine.
375+
if cached_app is None and cached_proj:
376+
cached_app = cached_proj
377+
378+
log.dbg('APP_DIR:', cached_app, level=log.VERBOSE_EXTREME)
363379
source_abs = (os.path.abspath(self.args.source_dir)
364380
if self.args.source_dir else None)
365381
cached_abs = os.path.abspath(cached_app) if cached_app else None
@@ -445,6 +461,14 @@ def _run_cmake(self, board, origin, cmake_opts):
445461
if user_args:
446462
cmake_opts.extend(shlex.split(user_args))
447463

464+
config_sysbuild = config_getboolean('sysbuild', False)
465+
if self.args.sysbuild or (config_sysbuild and not self.args.no_sysbuild):
466+
cmake_opts.extend(['-S{}'.format(SYSBUILD_PROJ_DIR),
467+
'-DAPP_DIR={}'.format(self.source_dir)])
468+
else:
469+
# self.args.no_sysbuild == True or config sysbuild False
470+
cmake_opts.extend(['-S{}'.format(self.source_dir)])
471+
448472
# Invoke CMake from the current working directory using the
449473
# -S and -B options (officially introduced in CMake 3.13.0).
450474
# This is important because users expect invocations like this
@@ -453,7 +477,6 @@ def _run_cmake(self, board, origin, cmake_opts):
453477
# west build -- -DOVERLAY_CONFIG=relative-path.conf
454478
final_cmake_args = ['-DWEST_PYTHON={}'.format(sys.executable),
455479
'-B{}'.format(self.build_dir),
456-
'-S{}'.format(self.source_dir),
457480
'-G{}'.format(config_get('generator',
458481
DEFAULT_CMAKE_GENERATOR))]
459482
if cmake_opts:

0 commit comments

Comments
 (0)