1 |
Support passing custom values for 'infinity' in makeopts_jobs() |
2 |
and makeopts_loadavg(). This can be used e.g. when a build system does |
3 |
not support --loadavg, and therefore '--jobs 999' would most likely |
4 |
be a really bad idea. Combined with get_nproc(), this can be used to |
5 |
provide a sane replacement instead. |
6 |
--- |
7 |
eclass/multiprocessing.eclass | 17 ++++++++++------- |
8 |
1 file changed, 10 insertions(+), 7 deletions(-) |
9 |
|
10 |
diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass |
11 |
index 0d241cdc15b6..b7d5f435f888 100644 |
12 |
--- a/eclass/multiprocessing.eclass |
13 |
+++ b/eclass/multiprocessing.eclass |
14 |
@@ -79,26 +79,27 @@ get_nproc() { |
15 |
} |
16 |
|
17 |
# @FUNCTION: makeopts_jobs |
18 |
-# @USAGE: [${MAKEOPTS}] |
19 |
+# @USAGE: [${MAKEOPTS}] [${inf:-999}] |
20 |
# @DESCRIPTION: |
21 |
# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number |
22 |
# specified therein. Useful for running non-make tools in parallel too. |
23 |
# i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the |
24 |
# number as bash normalizes it to [0, 255]. If the flags haven't specified a |
25 |
# -j flag, then "1" is shown as that is the default `make` uses. Since there's |
26 |
-# no way to represent infinity, we return 999 if the user has -j without a number. |
27 |
+# no way to represent infinity, we return ${inf} (defaults to 999) if the user |
28 |
+# has -j without a number. |
29 |
makeopts_jobs() { |
30 |
[[ $# -eq 0 ]] && set -- ${MAKEOPTS} |
31 |
# This assumes the first .* will be more greedy than the second .* |
32 |
# since POSIX doesn't specify a non-greedy match (i.e. ".*?"). |
33 |
local jobs=$(echo " $* " | sed -r -n \ |
34 |
-e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \ |
35 |
- -e 's:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:999:p') |
36 |
+ -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p") |
37 |
echo ${jobs:-1} |
38 |
} |
39 |
|
40 |
# @FUNCTION: makeopts_loadavg |
41 |
-# @USAGE: [${MAKEOPTS}] |
42 |
+# @USAGE: [${MAKEOPTS}] [${inf:-999}] |
43 |
# @DESCRIPTION: |
44 |
# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the value set |
45 |
# for load-average. For make and ninja based builds this will mean new jobs are |
46 |
@@ -106,15 +107,17 @@ makeopts_jobs() { |
47 |
# get excessive due to I/O and not just due to CPU load. |
48 |
# Be aware that the returned number might be a floating-point number. Test |
49 |
# whether your software supports that. |
50 |
+# If no limit is specified or --load-average is used without a number, ${inf} |
51 |
+# (defaults to 999) is returned. |
52 |
makeopts_loadavg() { |
53 |
[[ $# -eq 0 ]] && set -- ${MAKEOPTS} |
54 |
# This assumes the first .* will be more greedy than the second .* |
55 |
# since POSIX doesn't specify a non-greedy match (i.e. ".*?"). |
56 |
local lavg=$(echo " $* " | sed -r -n \ |
57 |
-e 's:.*[[:space:]](-[a-z]*l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p' \ |
58 |
- -e 's:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:999:p') |
59 |
- # Default to 999 since the default is to not use a load limit. |
60 |
- echo ${lavg:-999} |
61 |
+ -e "s:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:${2:-999}:p") |
62 |
+ # Default to ${inf} since the default is to not use a load limit. |
63 |
+ echo ${lavg:-${2:-999}} |
64 |
} |
65 |
|
66 |
# @FUNCTION: multijob_init |
67 |
-- |
68 |
2.11.0 |