Skip to content

Commit ba87527

Browse files
committed
[nrf fromtree] scripts: support number of jobs and verbosity in west build.
Calling `west build --build-opt="-v" --build-opt="-j=<n>"` passes the build options to `cmake --build ... -- <build-opt>` which again is passed to the native build tool, such as ninja or make. However, when ExternalProjects are used in CMake, such as in TF-M or sysbuild builds then those extra build options are only passed to the first image build and not those build as external projects. CMake supports environment variables for those flags, so translate verbosity and number of jobs to those environment variables and thereby support those flags for all images when specified by the user. Signed-off-by: Torsten Rasmussen <[email protected]> (cherry picked from commit 63cf79b)
1 parent 1b05ede commit ba87527

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scripts/west_commands/zcmake.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'''
1111

1212
from collections import OrderedDict
13+
import argparse
1314
import os.path
1415
import re
1516
import subprocess
@@ -26,7 +27,7 @@
2627
'''Name of the default CMake generator.'''
2728

2829

29-
def run_cmake(args, cwd=None, capture_output=False, dry_run=False):
30+
def run_cmake(args, cwd=None, capture_output=False, dry_run=False, env=None):
3031
'''Run cmake to (re)generate a build system, a script, etc.
3132
3233
:param args: arguments to pass to CMake
@@ -36,6 +37,7 @@ def run_cmake(args, cwd=None, capture_output=False, dry_run=False):
3637
dry_run is also True)
3738
:param dry_run: don't actually execute the command, just print what
3839
would have been run
40+
:param env: used adjusted environment when running CMake
3941
4042
If capture_output is set to True, returns the output of the command instead
4143
of displaying it on stdout/stderr..'''
@@ -60,7 +62,7 @@ def run_cmake(args, cwd=None, capture_output=False, dry_run=False):
6062
return None
6163

6264
log.dbg('Running CMake:', quote_sh_list(cmd), level=log.VERBOSE_NORMAL)
63-
p = subprocess.Popen(cmd, **kwargs)
65+
p = subprocess.Popen(cmd, env=env, **kwargs)
6466
out, _ = p.communicate()
6567
if p.returncode == 0:
6668
if out:
@@ -82,8 +84,29 @@ def run_build(build_directory, **kwargs):
8284
8385
Any additional keyword arguments are passed as-is to run_cmake().
8486
'''
87+
cmake_env = None
8588
extra_args = kwargs.pop('extra_args', [])
86-
return run_cmake(['--build', build_directory] + extra_args, **kwargs)
89+
90+
try:
91+
index = extra_args.index('--') + 1
92+
build_opt_parser = argparse.ArgumentParser(allow_abbrev=False)
93+
build_opt_parser.add_argument('-j', '--jobs')
94+
build_opt_parser.add_argument('-v', '--verbose', action='store_true')
95+
build_opts, native_args = build_opt_parser.parse_known_args(extra_args[index:])
96+
extra_args = extra_args[:index] + native_args
97+
98+
if build_opts:
99+
cmake_env = os.environ.copy()
100+
if build_opts.jobs:
101+
cmake_env["CMAKE_BUILD_PARALLEL_LEVEL"] = build_opts.jobs
102+
103+
if build_opts.verbose:
104+
cmake_env["VERBOSE"] = "1"
105+
106+
except ValueError:
107+
pass # Ignore, no presence of '--' so nothing to do.
108+
109+
return run_cmake(['--build', build_directory] + extra_args, env=cmake_env, **kwargs)
87110

88111

89112
def make_c_identifier(string):

0 commit comments

Comments
 (0)