Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Revert "Revert "Revert "patch-shebangs: respect cross compilation"""

Completely breaks darwin. Every package in the stdenv that has shebangs
in the output will end up with references to bootstrap-tools.

This reverts commit bde99096a80e74692795fa2782619c46a476839e.

+3 -50
+3 -50
pkgs/build-support/setup-hooks/patch-shebangs.sh
··· 5 # rewritten to /nix/store/<hash>/bin/python. Interpreters that are 6 # already in the store are left untouched. 7 8 - fixupOutputHooks+=(patchShebangsAuto) 9 - 10 - # Run patch shebangs on a directory. 11 - # patchShebangs [--build | --host] directory 12 - 13 - # Flags: 14 - # --build : Lookup commands available at build-time 15 - # --host : Lookup commands available at runtime 16 - 17 - # Example use cases, 18 - # $ patchShebangs --host /nix/store/...-hello-1.0/bin 19 - # $ patchShebangs --build configure 20 21 patchShebangs() { 22 - local pathName 23 - 24 - if [ "$1" = "--host" ]; then 25 - pathName=HOST_PATH 26 - shift 27 - elif [ "$1" = "--build" ]; then 28 - pathName=PATH 29 - shift 30 - fi 31 - 32 local dir="$1" 33 - 34 header "patching script interpreter paths in $dir" 35 local f 36 local oldPath ··· 49 oldInterpreterLine=$(head -1 "$f" | tail -c+3) 50 read -r oldPath arg0 args <<< "$oldInterpreterLine" 51 52 - if [ -z "$pathName" ]; then 53 - if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then 54 - pathName=HOST_PATH 55 - else 56 - pathName=PATH 57 - fi 58 - fi 59 - 60 if $(echo "$oldPath" | grep -q "/bin/env$"); then 61 # Check for unsupported 'env' functionality: 62 # - options: something starting with a '-' ··· 65 echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" 66 exit 1 67 fi 68 - 69 - newPath="$(PATH="${!pathName}" command -v "$arg0" || true)" 70 else 71 if [ "$oldPath" = "" ]; then 72 # If no interpreter is specified linux will use /bin/sh. Set 73 # oldpath="/bin/sh" so that we get /nix/store/.../sh. 74 oldPath="/bin/sh" 75 fi 76 - 77 - newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)" 78 - 79 args="$arg0 $args" 80 fi 81 ··· 98 99 stopNest 100 } 101 - 102 - patchShebangsAuto () { 103 - if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then 104 - 105 - # Dev output will end up being run on the build platform. An 106 - # example case of this is sdl2-config. Otherwise, we can just 107 - # use the runtime path (--host). 108 - if [ "$output" != out ] && [ "$output" = "${!outputDev}" ]; then 109 - patchShebangs --build "$prefix" 110 - else 111 - patchShebangs --host "$prefix" 112 - fi 113 - fi 114 - }
··· 5 # rewritten to /nix/store/<hash>/bin/python. Interpreters that are 6 # already in the store are left untouched. 7 8 + fixupOutputHooks+=('if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi') 9 10 patchShebangs() { 11 local dir="$1" 12 header "patching script interpreter paths in $dir" 13 local f 14 local oldPath ··· 27 oldInterpreterLine=$(head -1 "$f" | tail -c+3) 28 read -r oldPath arg0 args <<< "$oldInterpreterLine" 29 30 if $(echo "$oldPath" | grep -q "/bin/env$"); then 31 # Check for unsupported 'env' functionality: 32 # - options: something starting with a '-' ··· 35 echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" 36 exit 1 37 fi 38 + newPath="$(command -v "$arg0" || true)" 39 else 40 if [ "$oldPath" = "" ]; then 41 # If no interpreter is specified linux will use /bin/sh. Set 42 # oldpath="/bin/sh" so that we get /nix/store/.../sh. 43 oldPath="/bin/sh" 44 fi 45 + newPath="$(command -v "$(basename "$oldPath")" || true)" 46 args="$arg0 $args" 47 fi 48 ··· 65 66 stopNest 67 }