From 81d3bd60a46d0f3eba92ca2659b4cbef50745368 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 1 May 2019 03:18:35 +0200 Subject: [PATCH 1/3] patchShebangs: Explain that script must be executable --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index f4a865e96687..1dac1ca4d7b3 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -4,6 +4,8 @@ # /usr/bin/env gets special treatment so that ".../bin/env python" is # rewritten to /nix/store//bin/python. Interpreters that are # already in the store are left untouched. +# A script file must be marked as executable, otherwise it will not be +# considered. fixupOutputHooks+=(patchShebangsAuto) From 4a1e51f957b57f781fbdd2e40ca48ebac886e974 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 1 May 2019 03:19:02 +0200 Subject: [PATCH 2/3] patchShebangs: Allow for multiple arguments It's tempting to think patchShebangs supports multiple arguments. Without this patch it just silently ignores all but the first. Now it patches the shebangs in all of its arguments. Fixes: #57695 --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 1dac1ca4d7b3..3a879db2c0ac 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -9,8 +9,9 @@ fixupOutputHooks+=(patchShebangsAuto) -# Run patch shebangs on a directory. -# patchShebangs [--build | --host] directory +# Run patch shebangs on a directory or file. +# Can take multiple paths as arguments. +# patchShebangs [--build | --host] PATH... # Flags: # --build : Lookup commands available at build-time @@ -31,9 +32,7 @@ patchShebangs() { shift fi - local dir="$1" - - header "patching script interpreter paths in $dir" + header "patching script interpreter paths in $@" local f local oldPath local newPath @@ -42,8 +41,6 @@ patchShebangs() { local oldInterpreterLine local newInterpreterLine - [ -e "$dir" ] || return 0 - local f while IFS= read -r -d $'\0' f; do isScript "$f" || continue @@ -97,7 +94,7 @@ patchShebangs() { rm "$timestamp" fi fi - done < <(find "$dir" -type f -perm -0100 -print0) + done < <(find "$@" -type f -perm -0100 -print0) stopNest } From 7c3d7521f0d3e1a2562b0b341be52639248811bb Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 25 May 2019 16:21:56 +0200 Subject: [PATCH 3/3] patchShebangs: Exit if no arguments were given Commit "patchShebangs: Allow for multiple arguments" 4a1e51f957b57f78 removed the check. We don't want to break existing usages so this introduces it again with a successful exit code. --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 3a879db2c0ac..3e900d0704cf 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -32,7 +32,7 @@ patchShebangs() { shift fi - header "patching script interpreter paths in $@" + echo "patching script interpreter paths in $@" local f local oldPath local newPath @@ -41,6 +41,11 @@ patchShebangs() { local oldInterpreterLine local newInterpreterLine + if [ $# -eq 0 ]; then + echo "No arguments supplied to patchShebangs" >0 + return 0 + fi + local f while IFS= read -r -d $'\0' f; do isScript "$f" || continue @@ -61,7 +66,7 @@ patchShebangs() { # - options: something starting with a '-' # - environment variables: foo=bar if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then - echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" + echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >0 exit 1 fi