Try to guess the number of processors when --jobs is passed without an argument. We can't use a high number equivalent to GNU make behavior (no limit) since SCons does not have an equivalent of --load-avg option. Still, this is better than assuming some random, fixed number. --- eclass/scons-utils.eclass | 30 ++++++++++++++++++++++++++++-- eclass/tests/scons-utils.sh | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/eclass/scons-utils.eclass b/eclass/scons-utils.eclass index 3185282..89618f9 100644 --- a/eclass/scons-utils.eclass +++ b/eclass/scons-utils.eclass @@ -149,6 +149,32 @@ escons() { return ${ret} } +# @FUNCTION: _scons_get_default_jobs +# @INTERNAL +# @DESCRIPTION: +# Output the default number of jobs, used if -j is used without +# argument. Tries to figure out the number of logical CPUs, falling +# back to hardcoded constant. +_scons_get_default_jobs() { + local nproc + + if type -P nproc &>/dev/null; then + # GNU + nproc=$(nproc) + elif type -P python &>/dev/null; then + # fallback to python2.6+ + # note: this may fail (raise NotImplementedError) + nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2>/dev/null) + fi + + if [[ ${nproc} ]]; then + echo $(( nproc + 1 )) + else + # random default + echo 5 + fi +} + # @FUNCTION: _scons_clean_makeopts # @INTERNAL # @USAGE: [makeflags] [...] @@ -192,7 +218,7 @@ _scons_clean_makeopts() { shift else # no value means no limit, let's pass a random int - new_makeopts+=( ${1}=5 ) + new_makeopts+=( ${1}=$(_scons_get_default_jobs) ) fi ;; # strip other long options @@ -215,7 +241,7 @@ _scons_clean_makeopts() { new_optstr+="j ${2}" shift else - new_optstr+="j 5" + new_optstr+="j $(_scons_get_default_jobs)" fi ;; # otherwise, everything after -j is treated as an arg diff --git a/eclass/tests/scons-utils.sh b/eclass/tests/scons-utils.sh index 6355c54..fcb5125 100755 --- a/eclass/tests/scons-utils.sh +++ b/eclass/tests/scons-utils.sh @@ -28,7 +28,7 @@ test-scons_clean_makeopts() { } # jobcount expected for non-specified state -jc=5 +jc=$(_scons_get_default_jobs) # failed test counter failed=0 -- 2.6.4