Change the default value for 'inf' argument to makeopts_jobs from 999
to $(get_nproc).  This means that if MAKEOPTS specifies a `-j` argument
without a specific value, nproc will be used rather than infinity-ish
number of jobs.

The old default made sense for ebuilds using both makeopts_jobs
and makeopts_loadavg.  However, these are very rare — only 4 packages
and 3 eclass at this time.  For the remaining ebuilds, they meant
uncontrollably using up to 999 jobs.

The new default is both safer and more correct for the vast majority
of Gentoo packages, removing the necessity of repeating:

    $(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")

The ebuilds and eclasses using makeopts_loadavg have been updated
to pass the old default.

Signed-off-by: Michał Górny <mgo...@gentoo.org>
---
 eclass/multiprocessing.eclass                 |  9 ++++-----
 eclass/tests/multiprocessing_makeopts_jobs.sh | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
index c32bfaac2e6b..0aa33ff81cbc 100644
--- a/eclass/multiprocessing.eclass
+++ b/eclass/multiprocessing.eclass
@@ -65,22 +65,21 @@ get_nproc() {
 }
 
 # @FUNCTION: makeopts_jobs
-# @USAGE: [${MAKEOPTS}] [${inf:-999}]
+# @USAGE: [${MAKEOPTS}] [${inf:-$(get_nproc)}]
 # @DESCRIPTION:
 # Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number
 # specified therein.  Useful for running non-make tools in parallel too.
 # i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the
 # number as bash normalizes it to [0, 255].  If the flags haven't specified a
-# -j flag, then "1" is shown as that is the default `make` uses.  Since there's
-# no way to represent infinity, we return ${inf} (defaults to 999) if the user
-# has -j without a number.
+# -j flag, then "1" is shown as that is the default `make` uses.  If the flags
+# specify -j without a number, ${inf} is returned (defaults to nproc).
 makeopts_jobs() {
        [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"
        # This assumes the first .* will be more greedy than the second .*
        # since POSIX doesn't specify a non-greedy match (i.e. ".*?").
        local jobs=$(echo " $* " | sed -r -n \
                -e 
's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
-               -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p")
+               -e 
"s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-$(get_nproc)}:p")
        echo ${jobs:-1}
 }
 
diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh 
b/eclass/tests/multiprocessing_makeopts_jobs.sh
index 70a6085d5362..e2793ba61462 100755
--- a/eclass/tests/multiprocessing_makeopts_jobs.sh
+++ b/eclass/tests/multiprocessing_makeopts_jobs.sh
@@ -16,14 +16,19 @@ test-makeopts_jobs() {
                tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != 
'${direct}'"
        else
                [[ ${direct} == "${exp}" ]]
-               tend $? "Got back: ${act}"
+               tend $? "Got back: ${direct}"
        fi
 }
 
+# override to avoid relying on a specific value
+get_nproc() {
+       echo nproc
+}
+
 tests=(
-       999 "-j"
-       999 "--jobs"
-       999 "-j -l9"
+       nproc "-j"
+       nproc "--jobs"
+       nproc "-j -l9"
        1 ""
        1 "-l9 -w"
        1 "-l9 -w-j4"
@@ -37,7 +42,7 @@ tests=(
        7 "-l3 --jobs 7 -w"
        4 "-j1 -j 2 --jobs 3 --jobs=4"
        8 "     -j                              8     "
-       999 "-kj"
+       nproc "-kj"
        4 "-kj4"
        5 "-kj 5"
 )
-- 
2.35.1


Reply via email to