diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-11-07 13:37:02 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-07 13:37:02 -0600 |
commit | c8aff961100a792fc67f2e9005d5812ebbec1cd5 (patch) | |
tree | 7f96e9a7615a0960fd99f1d6d59b6420ca1c54be /pkgs/build-support/setup-hooks | |
parent | 424c38b92a7f909c695f93a18f72d023acd59953 (diff) | |
parent | 2f2e635dd5431859a01bbbcae0493be90041d495 (diff) | |
download | nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar.gz nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar.bz2 nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar.lz nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar.xz nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.tar.zst nixlib-c8aff961100a792fc67f2e9005d5812ebbec1cd5.zip |
Merge pull request #49608 from matthewbauer/cross-patch-shebangs-2
Restore cross-patch-shebangs branch
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r-- | pkgs/build-support/setup-hooks/patch-shebangs.sh | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index d26bf735d30a..b35c3c876253 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -5,10 +5,32 @@ # rewritten to /nix/store/<hash>/bin/python. Interpreters that are # already in the store are left untouched. -fixupOutputHooks+=('if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi') +fixupOutputHooks+=(patchShebangsAuto) + +# Run patch shebangs on a directory. +# patchShebangs [--build | --host] directory + +# Flags: +# --build : Lookup commands available at build-time +# --host : Lookup commands available at runtime + +# Example use cases, +# $ patchShebangs --host /nix/store/...-hello-1.0/bin +# $ patchShebangs --build configure patchShebangs() { + local pathName + + if [ "$1" = "--host" ]; then + pathName=HOST_PATH + shift + elif [ "$1" = "--build" ]; then + pathName=PATH + shift + fi + local dir="$1" + header "patching script interpreter paths in $dir" local f local oldPath @@ -27,6 +49,14 @@ patchShebangs() { oldInterpreterLine=$(head -1 "$f" | tail -c+3) read -r oldPath arg0 args <<< "$oldInterpreterLine" + if [ -z "$pathName" ]; then + if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then + pathName=HOST_PATH + else + pathName=PATH + fi + fi + if $(echo "$oldPath" | grep -q "/bin/env$"); then # Check for unsupported 'env' functionality: # - options: something starting with a '-' @@ -35,14 +65,17 @@ patchShebangs() { echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" exit 1 fi - newPath="$(command -v "$arg0" || true)" + + newPath="$(PATH="${!pathName}" command -v "$arg0" || true)" else if [ "$oldPath" = "" ]; then # If no interpreter is specified linux will use /bin/sh. Set # oldpath="/bin/sh" so that we get /nix/store/.../sh. oldPath="/bin/sh" fi - newPath="$(command -v "$(basename "$oldPath")" || true)" + + newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)" + args="$arg0 $args" fi @@ -65,3 +98,19 @@ patchShebangs() { stopNest } + +patchShebangsAuto () { + if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then + + if [ -z "${strictDeps-}"]; then + patchShebangs --build "$prefix" + # Dev output will end up being run on the build platform. An + # example case of this is sdl2-config. Otherwise, we can just + # use the runtime path (--host). + elif [ "$output" != out ] && [ "$output" = "${!outputDev}" ]; then + patchShebangs --build "$prefix" + else + patchShebangs --host "$prefix" + fi + fi +} |