Merge pull request #238525 from tie/patch-shebang-update-store-paths

authored by Artturi and committed by GitHub c0731df1 5f0e7501

+49 -10
+31 -9
pkgs/build-support/setup-hooks/patch-shebangs.sh
··· 11 11 12 12 # Run patch shebangs on a directory or file. 13 13 # Can take multiple paths as arguments. 14 - # patchShebangs [--build | --host] PATH... 14 + # patchShebangs [--build | --host | --update] [--] PATH... 15 15 16 16 # Flags: 17 17 # --build : Lookup commands available at build-time 18 18 # --host : Lookup commands available at runtime 19 + # --update : Update shebang paths that are in Nix store 19 20 20 21 # Example use cases, 21 22 # $ patchShebangs --host /nix/store/...-hello-1.0/bin ··· 23 24 24 25 patchShebangs() { 25 26 local pathName 27 + local update 26 28 27 - if [[ "$1" == "--host" ]]; then 28 - pathName=HOST_PATH 29 - shift 30 - elif [[ "$1" == "--build" ]]; then 31 - pathName=PATH 32 - shift 33 - fi 29 + while [[ $# -gt 0 ]]; do 30 + case "$1" in 31 + --host) 32 + pathName=HOST_PATH 33 + shift 34 + ;; 35 + --build) 36 + pathName=PATH 37 + shift 38 + ;; 39 + --update) 40 + update=true 41 + shift 42 + ;; 43 + --) 44 + shift 45 + break 46 + ;; 47 + -*|--*) 48 + echo "Unknown option $1 supplied to patchShebangs" >&2 49 + return 1 50 + ;; 51 + *) 52 + break 53 + ;; 54 + esac 55 + done 34 56 35 57 echo "patching script interpreter paths in $@" 36 58 local f ··· 93 115 newInterpreterLine="$newPath $args" 94 116 newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}} 95 117 96 - if [[ -n "$oldPath" && "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]]; then 118 + if [[ -n "$oldPath" && ( "$update" == true || "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ) ]]; then 97 119 if [[ -n "$newPath" && "$newPath" != "$oldPath" ]]; then 98 120 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" 99 121 # escape the escape chars so that sed doesn't interpret them
+18 -1
pkgs/test/stdenv/patch-shebangs.nix
··· 39 39 }; 40 40 }; 41 41 42 + updates-nix-store = stdenv.mkDerivation { 43 + name = "updates-nix-store"; 44 + strictDeps = false; 45 + dontUnpack = true; 46 + installPhase = '' 47 + mkdir -p $out/bin 48 + echo "#!$NIX_STORE/path/to/bash" > $out/bin/test 49 + echo "echo -n hello" >> $out/bin/test 50 + chmod +x $out/bin/test 51 + patchShebangs --update $out/bin/test 52 + dontPatchShebangs=1 53 + ''; 54 + passthru = { 55 + assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; 56 + }; 57 + }; 58 + 42 59 split-string = stdenv.mkDerivation { 43 60 name = "split-string"; 44 61 strictDeps = false; ··· 59 76 in 60 77 stdenv.mkDerivation { 61 78 name = "test-patch-shebangs"; 62 - passthru = { inherit (tests) bad-shebang ignores-nix-store split-string; }; 79 + passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string; }; 63 80 buildCommand = '' 64 81 validate() { 65 82 local name=$1