From 8e1442adb28858e61d893f943f844d0ce688f2e6 Mon Sep 17 00:00:00 2001 From: Mitchell Allain Date: Sun, 28 Jul 2024 17:16:55 -0700 Subject: [PATCH 1/2] Add return value to runPhase bash function in stdenv --- pkgs/stdenv/generic/setup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 40bf6554183c..0de3edfc7587 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1624,6 +1624,7 @@ showPhaseFooter() { runPhase() { + local status=0 local curPhase="$*" if [[ "$curPhase" = unpackPhase && -n "${dontUnpack:-}" ]]; then return; fi if [[ "$curPhase" = patchPhase && -n "${dontPatch:-}" ]]; then return; fi @@ -1643,6 +1644,11 @@ runPhase() { local startTime endTime startTime=$(date +"%s") + # Evaluate the variable named $curPhase if it exists, otherwise the + # function named $curPhase. Trap errors in subshell to set error status. + trap 'status=1; trap - ERR' ERR + eval "set -o errtrace; ${!curPhase:-$curPhase}" + # Evaluate the variable named $curPhase if it exists, otherwise the # function named $curPhase. eval "${!curPhase:-$curPhase}" @@ -1657,6 +1663,8 @@ runPhase() { cd -- "${sourceRoot:-.}" fi + + return $status } From e93ca9b43cf5aa4e58c9557f561f7dbafbabe893 Mon Sep 17 00:00:00 2001 From: Mitchell Allain Date: Sun, 28 Jul 2024 17:20:44 -0700 Subject: [PATCH 2/2] Change from status to retval --- pkgs/stdenv/generic/setup.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 0de3edfc7587..9043b3c710ad 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1624,7 +1624,7 @@ showPhaseFooter() { runPhase() { - local status=0 + local retval=0 local curPhase="$*" if [[ "$curPhase" = unpackPhase && -n "${dontUnpack:-}" ]]; then return; fi if [[ "$curPhase" = patchPhase && -n "${dontPatch:-}" ]]; then return; fi @@ -1645,14 +1645,10 @@ runPhase() { startTime=$(date +"%s") # Evaluate the variable named $curPhase if it exists, otherwise the - # function named $curPhase. Trap errors in subshell to set error status. - trap 'status=1; trap - ERR' ERR + # function named $curPhase. Trap errors in subshell to set non-zero retval. + trap 'retval=1; trap - ERR' ERR eval "set -o errtrace; ${!curPhase:-$curPhase}" - # Evaluate the variable named $curPhase if it exists, otherwise the - # function named $curPhase. - eval "${!curPhase:-$curPhase}" - endTime=$(date +"%s") showPhaseFooter "$curPhase" "$startTime" "$endTime" @@ -1664,7 +1660,7 @@ runPhase() { cd -- "${sourceRoot:-.}" fi - return $status + return $retval }