diff --git a/pkgs/build-support/setup-hooks/compress-man-pages.sh b/pkgs/build-support/setup-hooks/compress-man-pages.sh index 74c565ebffc59..1dd9788419b84 100644 --- a/pkgs/build-support/setup-hooks/compress-man-pages.sh +++ b/pkgs/build-support/setup-hooks/compress-man-pages.sh @@ -1,4 +1,4 @@ -addHook fixupOutput 'if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontGzipMan" ]; then compressManPages "$prefix"; fi') compressManPages() { local dir="$1" diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 6b42291358d94..5a7f23b2d816f 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -5,7 +5,7 @@ # rewritten to /nix/store//bin/python. Interpreters that are # already in the store are left untouched. -addHook fixupOutput 'if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontPatchShebangs" ]; then patchShebangs "$prefix"; fi') patchShebangs() { local dir="$1" diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index 1815297cb6dab..6860c9b9cb9ad 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -1,6 +1,6 @@ # This setup hook strips libraries and executables in the fixup phase. -addHook fixupOutput _doStrip +fixupOutputHooks+=(_doStrip) _doStrip() { if [ -z "$dontStrip" ]; then diff --git a/pkgs/development/tools/misc/patchelf/setup-hook.sh b/pkgs/development/tools/misc/patchelf/setup-hook.sh index 6bc918a4610dd..b0d37b73e2b67 100644 --- a/pkgs/development/tools/misc/patchelf/setup-hook.sh +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -2,7 +2,7 @@ # directories from the RPATH of every library or executable in every # output. -addHook fixupOutput 'if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi' +fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi') patchELF() { header "patching ELF executables and libraries in $prefix" diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 6ed94673ae708..cdebf6e4b27e7 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -7,24 +7,15 @@ set -e # Hook handling. -# Add the specified shell code to the named hook, e.g. ‘addHook -# preConfigure "rm ./foo; touch ./bar"’. -addHook() { - local hookName="$1" - local hookCode="$2" - eval "_${hookName}_hooks+=(\"\$hookCode\")" -} - - # 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). Hooks are added using ‘addHooks ’, or -# implicitly by defining a shell function or variable . Note -# that the latter takes precedence over hooks added via ‘addHooks’. +# code). The hooks for are the shell function or variable +# , and the values of the shell array ‘Hooks’. runHook() { local hookName="$1" - local var="_${hookName}_hooks" - eval "local -a dummy=(\"\${_${hookName}_hooks[@]}\")" + local var="$hookName" + if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi + eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do if ! _eval "$hook"; then return 1; fi done @@ -36,8 +27,9 @@ runHook() { # 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[@]}\")" + local var="$hookName" + if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi + eval "local -a dummy=(\"\${$var[@]}\")" for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do if _eval "$hook"; then return 0 @@ -465,7 +457,7 @@ stripHash() { } -addHook unpackCmd _defaultUnpack +unpackCmdHooks+=(_defaultUnpack) _defaultUnpack() { if [ -d "$curSrc" ]; then @@ -856,7 +848,6 @@ genericBuild() { # Execute the post-hooks. -for i in "${postHooks[@]}"; do $i; done runHook postHook diff --git a/pkgs/tools/archivers/unzip/setup-hook.sh b/pkgs/tools/archivers/unzip/setup-hook.sh index 47894ded0230d..4cad0fe7e91b3 100644 --- a/pkgs/tools/archivers/unzip/setup-hook.sh +++ b/pkgs/tools/archivers/unzip/setup-hook.sh @@ -1,4 +1,4 @@ -addHook unpackCmd _tryUnzip +unpackCmdHooks+=(_tryUnzip) _tryUnzip() { if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi unzip -qq "$curSrc"