Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir
"-j",
"--jobs",
metavar="N_JOBS",
help="Number of parallel tasks to launch",
type=int,
help="Number of parallel tasks to launch. Can be set to `auto` to use all cores.",
)
@click.option("--clean", is_flag=True, help="Clean build directory before build")
@click.option(
Expand Down Expand Up @@ -364,9 +363,24 @@ def build(

# Any other conditions that warrant a reconfigure?

if jobs is not None:
if jobs == "auto":
jobs = str(os.cpu_count() or 1)
else:
try:
jobs = str(int(jobs))
except ValueError as err:
raise click.BadParameter(
f"Expected an integer or 'auto', got '{jobs}'", param_hint="'-j'"
) from err

compile_flags = ["-v"] if verbose else []
if jobs:
compile_flags += ["-j", str(jobs)]
if not quiet:
click.secho(
f"Building with {jobs} parallel jobs", bold=True, fg="bright_blue"
)
compile_flags += ["-j", jobs]

p = _run(
_meson_cli()
Expand Down
14 changes: 14 additions & 0 deletions spin/tests/test_build_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ def test_debug_builds(example_pkg):
assert len(list(debug_files)) != 0, "debug files not generated for gcov build"


def test_build_jobs_auto(example_pkg):
"""Does `spin build -j auto` work?"""
p = spin("build", "-j", "auto")
assert b"Building with" in p.stdout
assert b"parallel jobs" in p.stdout


def test_build_jobs_invalid(example_pkg):
"""Does `spin build -j nan` fail with a clear error?"""
p = spin("build", "-j", "nan", sys_exit=False)
assert p.returncode != 0
assert b"Expected an integer or 'auto'" in p.stderr


def test_prefix_builds(example_pkg):
"""does spin build --prefix create a build-install directory with the correct structure?"""
spin("build", "--prefix=/foobar/")
Expand Down
Loading