commit:     59c00cecd895d2299df40b1e860dc63db6943810
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun 26 02:51:27 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 28 02:30:16 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=59c00cec

phase-functions.sh: support xargs -r across more platforms

Presently, the "isolated-functions.sh" exports a variable by the name of
'XARGS', which is intended to be a string containing both the name of
the ideal xargs(1) implementation and the -r option, if supported.
However, it is implemented in such a way that it may unnecessarily avoid
the use of the -r option. Specifically, it will conclude that the option
is unsupported where both of the following conditions hold true.

- the value of the 'USERLAND' variable is "BSD"
- there is no command available whose name is "gxargs"

It is not a sensible conclusion to draw. Not only is -r a standard
option as of POSIX-1.2024, but various BSD implementations have
supported it for many years. For example, OpenBSD has supported it since
3.8 (2005), FreeBSD since 7.1 (2009) and NetBSD since 5.2 (2012).

Address the issue by first checking whether gxargs is available. If it
is, assume it to be GNU xargs(1). Otherwise, perform a test that
empirically determines whether the option is supported.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/isolated-functions.sh | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 21acaffdde..acf945eb99 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -479,18 +479,13 @@ if [[ -z ${USERLAND} ]] ; then
 fi
 
 if [[ -z ${XARGS} ]] ; then
-       case ${USERLAND} in
-       BSD)
-               if type -P gxargs > /dev/null; then
-                       export XARGS="gxargs -r"
-               else
-                       export XARGS="xargs"
-               fi
-               ;;
-       *)
+       if XARGS=$(type -P gxargs); then
+               export XARGS+=" -r"
+       elif : | xargs -r 2>/dev/null; then
                export XARGS="xargs -r"
-               ;;
-       esac
+       else
+               export XARGS="xargs"
+       fi
 fi
 
 ___makeopts_jobs() {

Reply via email to