commit:     bde3d41e27af56e0ce096c04108b4843507ae2a6
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Tue Feb  3 18:42:48 2026 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Sun Feb  8 08:16:16 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bde3d41e

sysroot.eclass: Add sysroot_try_run_prefixed to allow wrapper failure

There are some cases where failing to run a command under a sysroot
should be fatal like `openssl fipsinstall`. There are other cases, like
help2man or shell completion, where failure is permissible when QEMU is
missing or broken.

Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 eclass/sysroot.eclass | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/eclass/sysroot.eclass b/eclass/sysroot.eclass
index 03e5705c14a0..3427c421bf22 100644
--- a/eclass/sysroot.eclass
+++ b/eclass/sysroot.eclass
@@ -80,7 +80,9 @@ qemu_arch_if_needed() {
 # @DESCRIPTION:
 # Create a wrapper script for directly running executables within a (sys)root
 # without changing the root directory. The path to that script is returned. If
-# no sysroot has been set, then this function returns unsuccessfully.
+# no (sys)root has been set, then return status code 1. If the wrapper cannot 
be
+# created for a permissible reason like QEMU being missing or broken, then
+# return status code 2.
 #
 # The script explicitly uses QEMU if this is necessary and it is available in
 # this environment. It may otherwise implicitly use a QEMU outside this
@@ -118,7 +120,7 @@ sysroot_make_run_prefixed() {
        if [[ ${CHOST} = *-mingw32 ]]; then
                if ! type -P wine >/dev/null; then
                        einfo "Wine not found. Continuing without ${SCRIPT##*/} 
wrapper."
-                       return 1
+                       return 2
                fi
 
                # UNIX paths can work, but programs will not expect this in 
%PATH%.
@@ -169,7 +171,7 @@ sysroot_make_run_prefixed() {
 
                if ! "${SCRIPT}" "${test}" &>/dev/null; then
                        einfo "Failed to run ${test##*/}. Continuing without 
${SCRIPT##*/} wrapper."
-                       return 1
+                       return 2
                fi
        fi
 
@@ -180,11 +182,30 @@ sysroot_make_run_prefixed() {
 # @DESCRIPTION:
 # Create a wrapper script with sysroot_make_run_prefixed if necessary, and use
 # it to execute the given command, otherwise just execute the command directly.
+# Return unsuccessfully if the wrapper cannot be created.
 sysroot_run_prefixed() {
        local script
-       if script=$(sysroot_make_run_prefixed); then
-               "${script}" "${@}"
-       else
-               "${@}"
-       fi
+       script=$(sysroot_make_run_prefixed)
+
+       case $? in
+               0) "${script}" "${@}" ;;
+               1) "${@}" ;;
+               *) return $? ;;
+       esac
+}
+
+# @FUNCTION: sysroot_try_run_prefixed
+# @DESCRIPTION:
+# Create a wrapper script with sysroot_make_run_prefixed if necessary, and use
+# it to execute the given command, otherwise just execute the command directly.
+# Print a warning and return successfully if the wrapper cannot be created.
+sysroot_try_run_prefixed() {
+       local script
+       script=$(sysroot_make_run_prefixed)
+
+       case $? in
+               0) "${script}" "${@}" ;;
+               1) "${@}" ;;
+               *) ewarn "Unable to run command under prefix: $*" ;;
+       esac
 }

Reply via email to