1 |
Try to guess the number of processors when --jobs is passed without |
2 |
an argument. We can't use a high number equivalent to GNU make behavior |
3 |
(no limit) since SCons does not have an equivalent of --load-avg option. |
4 |
Still, this is better than assuming some random, fixed number. |
5 |
--- |
6 |
eclass/scons-utils.eclass | 30 ++++++++++++++++++++++++++++-- |
7 |
eclass/tests/scons-utils.sh | 2 +- |
8 |
2 files changed, 29 insertions(+), 3 deletions(-) |
9 |
|
10 |
diff --git a/eclass/scons-utils.eclass b/eclass/scons-utils.eclass |
11 |
index 3185282..89618f9 100644 |
12 |
--- a/eclass/scons-utils.eclass |
13 |
+++ b/eclass/scons-utils.eclass |
14 |
@@ -149,6 +149,32 @@ escons() { |
15 |
return ${ret} |
16 |
} |
17 |
|
18 |
+# @FUNCTION: _scons_get_default_jobs |
19 |
+# @INTERNAL |
20 |
+# @DESCRIPTION: |
21 |
+# Output the default number of jobs, used if -j is used without |
22 |
+# argument. Tries to figure out the number of logical CPUs, falling |
23 |
+# back to hardcoded constant. |
24 |
+_scons_get_default_jobs() { |
25 |
+ local nproc |
26 |
+ |
27 |
+ if type -P nproc &>/dev/null; then |
28 |
+ # GNU |
29 |
+ nproc=$(nproc) |
30 |
+ elif type -P python &>/dev/null; then |
31 |
+ # fallback to python2.6+ |
32 |
+ # note: this may fail (raise NotImplementedError) |
33 |
+ nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2>/dev/null) |
34 |
+ fi |
35 |
+ |
36 |
+ if [[ ${nproc} ]]; then |
37 |
+ echo $(( nproc + 1 )) |
38 |
+ else |
39 |
+ # random default |
40 |
+ echo 5 |
41 |
+ fi |
42 |
+} |
43 |
+ |
44 |
# @FUNCTION: _scons_clean_makeopts |
45 |
# @INTERNAL |
46 |
# @USAGE: [makeflags] [...] |
47 |
@@ -192,7 +218,7 @@ _scons_clean_makeopts() { |
48 |
shift |
49 |
else |
50 |
# no value means no limit, let's pass a random int |
51 |
- new_makeopts+=( ${1}=5 ) |
52 |
+ new_makeopts+=( ${1}=$(_scons_get_default_jobs) ) |
53 |
fi |
54 |
;; |
55 |
# strip other long options |
56 |
@@ -215,7 +241,7 @@ _scons_clean_makeopts() { |
57 |
new_optstr+="j ${2}" |
58 |
shift |
59 |
else |
60 |
- new_optstr+="j 5" |
61 |
+ new_optstr+="j $(_scons_get_default_jobs)" |
62 |
fi |
63 |
;; |
64 |
# otherwise, everything after -j is treated as an arg |
65 |
diff --git a/eclass/tests/scons-utils.sh b/eclass/tests/scons-utils.sh |
66 |
index 6355c54..fcb5125 100755 |
67 |
--- a/eclass/tests/scons-utils.sh |
68 |
+++ b/eclass/tests/scons-utils.sh |
69 |
@@ -28,7 +28,7 @@ test-scons_clean_makeopts() { |
70 |
} |
71 |
|
72 |
# jobcount expected for non-specified state |
73 |
-jc=5 |
74 |
+jc=$(_scons_get_default_jobs) |
75 |
# failed test counter |
76 |
failed=0 |
77 |
|
78 |
-- |
79 |
2.6.4 |