summaryrefslogtreecommitdiffstats
path: root/SConstruct
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:10:23 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:10:23 +0200
commitbd04f687f0ae9346aba2e43d077f129c3acb7050 (patch)
treec2e9c522d9a1947a376efdd3e085747e6020da09 /SConstruct
parent109203d472276832121f90b263abf81f113a1717 (diff)
parente4b16e2d71fad873611a8219405a398af328fd6e (diff)
downloadredot-engine-bd04f687f0ae9346aba2e43d077f129c3acb7050.tar.gz
Merge pull request #87376 from shana/add-num-jobs-option
SCons: Add `num_jobs` as an explicit option so it can be set from other sources
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct29
1 files changed, 20 insertions, 9 deletions
diff --git a/SConstruct b/SConstruct
index d2cfe2732c..e1c943bd45 100644
--- a/SConstruct
+++ b/SConstruct
@@ -237,6 +237,11 @@ opts.Add(BoolVariable("ninja", "Use the ninja backend for faster rebuilds", Fals
opts.Add(BoolVariable("ninja_auto_run", "Run ninja automatically after generating the ninja file", True))
opts.Add("ninja_file", "Path to the generated ninja file", "build.ninja")
opts.Add(BoolVariable("compiledb", "Generate compilation DB (`compile_commands.json`) for external tools", False))
+opts.Add(
+ "num_jobs",
+ "Use up to N jobs when compiling (equivalent to `-j N`). Defaults to max jobs - 1. Ignored if -j is used.",
+ "",
+)
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True))
opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no")))
@@ -540,16 +545,22 @@ initial_num_jobs = env.GetOption("num_jobs")
altered_num_jobs = initial_num_jobs + 1
env.SetOption("num_jobs", altered_num_jobs)
if env.GetOption("num_jobs") == altered_num_jobs:
- cpu_count = os.cpu_count()
- if cpu_count is None:
- print_warning("Couldn't auto-detect CPU count to configure build parallelism. Specify it with the -j argument.")
+ num_jobs = env.get("num_jobs", "")
+ if str(num_jobs).isdigit() and int(num_jobs) > 0:
+ env.SetOption("num_jobs", num_jobs)
else:
- safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1
- print(
- "Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the -j argument."
- % (cpu_count, safer_cpu_count)
- )
- env.SetOption("num_jobs", safer_cpu_count)
+ cpu_count = os.cpu_count()
+ if cpu_count is None:
+ print_warning(
+ "Couldn't auto-detect CPU count to configure build parallelism. Specify it with the `-j` or `num_jobs` arguments."
+ )
+ else:
+ safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1
+ print(
+ "Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the `-j` or `num_jobs` arguments."
+ % (cpu_count, safer_cpu_count)
+ )
+ env.SetOption("num_jobs", safer_cpu_count)
env.extra_suffix = ""