stdenv: Make unpackFile extensible via the hook mechanism
unpackCmd is now a regular hook, so there can be multiple functions hooking into it.
This commit is contained in:
parent
1a44dbbbb9
commit
3e33c975fb
|
@ -23,25 +23,41 @@ runHook() {
|
||||||
local hookName="$1"
|
local hookName="$1"
|
||||||
local var="_${hookName}_hooks"
|
local var="_${hookName}_hooks"
|
||||||
eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")"
|
eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")"
|
||||||
for hook in "runSingleHook $hookName" "${dummy[@]}"; do
|
for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do
|
||||||
if ! _eval "$hook"; then return 1; fi
|
if ! _eval "$hook"; then return 1; fi
|
||||||
done
|
done
|
||||||
return 0
|
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 hookName="$1"
|
||||||
|
local var="_${hookName}_hooks"
|
||||||
|
eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")"
|
||||||
|
for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do
|
||||||
|
if _eval "$hook"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Run the named hook, either by calling the function with that name or
|
# Run the named hook, either by calling the function with that name or
|
||||||
# by evaluating the variable with that name. This allows convenient
|
# by evaluating the variable with that name. This allows convenient
|
||||||
# setting of hooks both from Nix expressions (as attributes /
|
# setting of hooks both from Nix expressions (as attributes /
|
||||||
# environment variables) and from shell scripts (as functions). If you
|
# environment variables) and from shell scripts (as functions). If you
|
||||||
# want to allow multiple hooks, use runHook instead.
|
# want to allow multiple hooks, use runHook instead.
|
||||||
runSingleHook() {
|
_callImplicitHook() {
|
||||||
local hookName="$1"
|
local def="$1"
|
||||||
|
local hookName="$2"
|
||||||
case "$(type -t $hookName)" in
|
case "$(type -t $hookName)" in
|
||||||
(function|alias|builtin) $hookName;;
|
(function|alias|builtin) $hookName;;
|
||||||
(file) source $hookName;;
|
(file) source $hookName;;
|
||||||
(keyword) :;;
|
(keyword) :;;
|
||||||
(*) eval "${!hookName}";;
|
(*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,12 +485,8 @@ stripHash() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unpackFile() {
|
addHook unpackCmd _defaultUnpack
|
||||||
curSrc="$1"
|
_defaultUnpack() {
|
||||||
local cmd
|
|
||||||
|
|
||||||
header "unpacking source archive $curSrc" 3
|
|
||||||
|
|
||||||
if [ -d "$curSrc" ]; then
|
if [ -d "$curSrc" ]; then
|
||||||
|
|
||||||
stripHash $curSrc
|
stripHash $curSrc
|
||||||
|
@ -496,16 +508,21 @@ unpackFile() {
|
||||||
unzip -qq $curSrc
|
unzip -qq $curSrc
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ -z "$unpackCmd" ]; then
|
return 1
|
||||||
echo "source archive $curSrc has unknown type"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
runSingleHook unpackCmd
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unpackFile() {
|
||||||
|
curSrc="$1"
|
||||||
|
header "unpacking source archive $curSrc" 3
|
||||||
|
if ! runOneHook unpackCmd; then
|
||||||
|
echo "do not know how to unpack source archive $curSrc"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
stopNest
|
stopNest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,7 +556,7 @@ unpackPhase() {
|
||||||
|
|
||||||
# Find the source directory.
|
# Find the source directory.
|
||||||
if [ -n "$setSourceRoot" ]; then
|
if [ -n "$setSourceRoot" ]; then
|
||||||
runSingleHook setSourceRoot
|
runOneHook setSourceRoot
|
||||||
elif [ -z "$sourceRoot" ]; then
|
elif [ -z "$sourceRoot" ]; then
|
||||||
sourceRoot=
|
sourceRoot=
|
||||||
for i in *; do
|
for i in *; do
|
||||||
|
|
Loading…
Reference in New Issue