1 |
Change the default value for 'inf' argument to makeopts_jobs from 999 |
2 |
to $(get_nproc). This means that if MAKEOPTS specifies a `-j` argument |
3 |
without a specific value, nproc will be used rather than infinity-ish |
4 |
number of jobs. |
5 |
|
6 |
The old default made sense for ebuilds using both makeopts_jobs |
7 |
and makeopts_loadavg. However, these are very rare — only 4 packages |
8 |
and 3 eclass at this time. For the remaining ebuilds, they meant |
9 |
uncontrollably using up to 999 jobs. |
10 |
|
11 |
The new default is both safer and more correct for the vast majority |
12 |
of Gentoo packages, removing the necessity of repeating: |
13 |
|
14 |
$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)") |
15 |
|
16 |
The ebuilds and eclasses using makeopts_loadavg have been updated |
17 |
to pass the old default. |
18 |
|
19 |
Signed-off-by: Michał Górny <mgorny@g.o> |
20 |
--- |
21 |
eclass/multiprocessing.eclass | 9 ++++----- |
22 |
eclass/tests/multiprocessing_makeopts_jobs.sh | 15 ++++++++++----- |
23 |
2 files changed, 14 insertions(+), 10 deletions(-) |
24 |
|
25 |
diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass |
26 |
index c32bfaac2e6b..0aa33ff81cbc 100644 |
27 |
--- a/eclass/multiprocessing.eclass |
28 |
+++ b/eclass/multiprocessing.eclass |
29 |
@@ -65,22 +65,21 @@ get_nproc() { |
30 |
} |
31 |
|
32 |
# @FUNCTION: makeopts_jobs |
33 |
-# @USAGE: [${MAKEOPTS}] [${inf:-999}] |
34 |
+# @USAGE: [${MAKEOPTS}] [${inf:-$(get_nproc)}] |
35 |
# @DESCRIPTION: |
36 |
# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number |
37 |
# specified therein. Useful for running non-make tools in parallel too. |
38 |
# i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the |
39 |
# number as bash normalizes it to [0, 255]. If the flags haven't specified a |
40 |
-# -j flag, then "1" is shown as that is the default `make` uses. Since there's |
41 |
-# no way to represent infinity, we return ${inf} (defaults to 999) if the user |
42 |
-# has -j without a number. |
43 |
+# -j flag, then "1" is shown as that is the default `make` uses. If the flags |
44 |
+# specify -j without a number, ${inf} is returned (defaults to nproc). |
45 |
makeopts_jobs() { |
46 |
[[ $# -eq 0 ]] && set -- "${MAKEOPTS}" |
47 |
# This assumes the first .* will be more greedy than the second .* |
48 |
# since POSIX doesn't specify a non-greedy match (i.e. ".*?"). |
49 |
local jobs=$(echo " $* " | sed -r -n \ |
50 |
-e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \ |
51 |
- -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p") |
52 |
+ -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-$(get_nproc)}:p") |
53 |
echo ${jobs:-1} |
54 |
} |
55 |
|
56 |
diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh b/eclass/tests/multiprocessing_makeopts_jobs.sh |
57 |
index 70a6085d5362..e2793ba61462 100755 |
58 |
--- a/eclass/tests/multiprocessing_makeopts_jobs.sh |
59 |
+++ b/eclass/tests/multiprocessing_makeopts_jobs.sh |
60 |
@@ -16,14 +16,19 @@ test-makeopts_jobs() { |
61 |
tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'" |
62 |
else |
63 |
[[ ${direct} == "${exp}" ]] |
64 |
- tend $? "Got back: ${act}" |
65 |
+ tend $? "Got back: ${direct}" |
66 |
fi |
67 |
} |
68 |
|
69 |
+# override to avoid relying on a specific value |
70 |
+get_nproc() { |
71 |
+ echo nproc |
72 |
+} |
73 |
+ |
74 |
tests=( |
75 |
- 999 "-j" |
76 |
- 999 "--jobs" |
77 |
- 999 "-j -l9" |
78 |
+ nproc "-j" |
79 |
+ nproc "--jobs" |
80 |
+ nproc "-j -l9" |
81 |
1 "" |
82 |
1 "-l9 -w" |
83 |
1 "-l9 -w-j4" |
84 |
@@ -37,7 +42,7 @@ tests=( |
85 |
7 "-l3 --jobs 7 -w" |
86 |
4 "-j1 -j 2 --jobs 3 --jobs=4" |
87 |
8 " -j 8 " |
88 |
- 999 "-kj" |
89 |
+ nproc "-kj" |
90 |
4 "-kj4" |
91 |
5 "-kj 5" |
92 |
) |
93 |
-- |
94 |
2.35.1 |