set -eu
set -o pipefail
if (( "${NIX_DEBUG:-0}" >= 6 )); then
set -x
fi
: ${outputs:=out}
######################################################################
# Hook handling.
# Run all hooks with the specified name in the order in which they
# were added, stopping if any fails (returns a non-zero exit
# code). The hooks for <hookName> are the shell function or variable
# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
runHook() {
local oldOpts="$(shopt -po nounset)"
set -u # May be called from elsewhere, so do `set -u`.
local hookName="$1"
shift
local hooksSlice="${hookName%Hook}Hooks[@]"
local hook
# Hack around old bash being bad and thinking empty arrays are
# undefined.
for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
_eval "$hook" "$@"
set -u # To balance `_eval`
done
eval "${oldOpts}"
return 0
}
# Run all hooks with the specified name, until one succeeds (returns a
# zero exit code). If none succeed, return a non-zero exit code.
runOneHook() {
local oldOpts="$(shopt -po nounset)"
set -u # May be called from elsewhere, so do `set -u`.
local hookName="$1"
shift
local hooksSlice="${hookName%Hook}Hooks[@]"
local hook ret=1
# Hack around old bash like above
for hook in "_callImplicitHook 1 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do
if _eval "$hook" "$@"; then
ret=0
break
fi
set -u # To balance `_eval`
done
eval "${oldOpts}"
return "