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