Skip to content

Commit

Permalink
Remove addHook
Browse files Browse the repository at this point in the history
Just use bash arrays directly. I.e.

  addHook preConfigure myPreConfigure

is now

  preConfigureHooks+=(myPreConfigure)
  • Loading branch information
edolstra committed Aug 9, 2014
1 parent e387529 commit 2def8e7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/compress-man-pages.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/patch-shebangs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# rewritten to /nix/store/<hash>/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"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/setup-hooks/strip.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/tools/misc/patchelf/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 9 additions & 18 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hookName> <code>’, or
# implicitly by defining a shell function or variable <hookName>. Note
# that the latter takes precedence over hooks added via ‘addHooks’.
# code). The hooks for <hookName> are the shell function or variable
# <hookName>, and the values of the shell array ‘<hookName>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
Expand All @@ -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
Expand Down Expand Up @@ -465,7 +457,7 @@ stripHash() {
}


addHook unpackCmd _defaultUnpack
unpackCmdHooks+=(_defaultUnpack)
_defaultUnpack() {
if [ -d "$curSrc" ]; then

Expand Down Expand Up @@ -856,7 +848,6 @@ genericBuild() {


# Execute the post-hooks.
for i in "${postHooks[@]}"; do $i; done
runHook postHook


Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/archivers/unzip/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addHook unpackCmd _tryUnzip
unpackCmdHooks+=(_tryUnzip)
_tryUnzip() {
if ! [[ "foo.zip" =~ \.zip$ ]]; then return 1; fi
unzip -qq "$curSrc"
Expand Down

0 comments on commit 2def8e7

Please sign in to comment.