diff options
author | Michał Górny <mgorny@gentoo.org> | 2022-04-28 12:44:02 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2022-05-01 09:30:36 +0200 |
commit | a00223eb88742885325b8863ba080e7d94202d8f (patch) | |
tree | 2b0f3c32ee47a52f3b1a0e51fa85350d53ac8686 /eclass | |
parent | ninja-utils.eclass: Prepare for makeopts_jobs default inf change (diff) | |
download | gentoo-a00223eb88742885325b8863ba080e7d94202d8f.tar.gz gentoo-a00223eb88742885325b8863ba080e7d94202d8f.tar.bz2 gentoo-a00223eb88742885325b8863ba080e7d94202d8f.zip |
multiprocessing.eclass: Default makeopts_jobs to inf=nproc+1
Change the default value for 'inf' argument to makeopts_jobs from 999
to $(get_nproc) + 1. 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 <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/multiprocessing.eclass | 11 | ||||
-rwxr-xr-x | eclass/tests/multiprocessing_makeopts_jobs.sh | 15 |
2 files changed, 15 insertions, 11 deletions
diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass index c32bfaac2e6b..e55be636a02c 100644 --- a/eclass/multiprocessing.eclass +++ b/eclass/multiprocessing.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2022 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: multiprocessing.eclass @@ -65,22 +65,21 @@ get_nproc() { } # @FUNCTION: makeopts_jobs -# @USAGE: [${MAKEOPTS}] [${inf:-999}] +# @USAGE: [${MAKEOPTS}] [${inf:-$(( $(get_nproc) + 1 ))}] # @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) + 1 ))}:p") echo ${jobs:-1} } diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh b/eclass/tests/multiprocessing_makeopts_jobs.sh index 70a6085d5362..37d5a7257775 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 41 +} + tests=( - 999 "-j" - 999 "--jobs" - 999 "-j -l9" + 42 "-j" + 42 "--jobs" + 42 "-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" + 42 "-kj" 4 "-kj4" 5 "-kj 5" ) |