commit: 40d634fe925bda6b3c95067cb7d23f2bce32ce36
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 29 06:37:19 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Sep 29 20:45:40 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=40d634fe
bin: isolated-functions.sh: make ___makeopts_jobs return CPUs as default, not 1
Both Portage and pkgcore interpret no MAKEOPTS as "-jN" where N is the number
of available CPUs but we weren't doing this on the bash side in
___makeopts_jobs.
Switch it to use nproc for consistency (it's also, really, the behaviour
we're expecting).
Signed-off-by: Sam James <sam <AT> gentoo.org>
NEWS | 3 +++
bin/isolated-functions.sh | 9 ++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 21296d5ff..31927c819 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,9 @@ Bug fixes:
* data: Fix PORTAGE_USERNAME default (bug #873088).
+* bin: isolated-functions.sh: return number of CPUs in ___makeopts_jobs as
default
+ instead of 1 to match Portage's behavior on the Python side.
+
* bin: ecompress: zstd: Recognize .zst as a compressed file suffix for the
purposes
of the internal compressed file collision check.
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 0efcd5a7d..882789132 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -475,7 +475,14 @@ ___makeopts_jobs() {
# since POSIX doesn't specify a non-greedy match (i.e. ".*?").
local jobs=$(echo " ${MAKEOPTS} " | sed -r -n \
-e
's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' ||
die)
- echo ${jobs:-1}
+
+ # Fallbacks for if MAKEOPTS parsing failed
+ [[ -n ${jobs} ]] || \
+ jobs=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
+ jobs=$(sysctl -n hw.ncpu 2>/dev/null) || \
+ jobs=1
+
+ echo ${jobs}
}
# Run ${XARGS} in parallel for detected number of CPUs, if supported.