summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2020-08-04 06:39:51 +0100
committerJörg Thalheim <joerg@thalheim.io>2021-01-14 20:00:54 +0100
commitab4c35982269e8f1f15e07afa7fedf65c749f276 (patch)
tree8fbb48e8dcd80a21ae492f2662850df8a23bec2a /pkgs/build-support/setup-hooks
parentb1d838e20efe3ec594b76f0d33b9b318fb5fa74b (diff)
downloadnixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar.gz
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar.bz2
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar.lz
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar.xz
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.tar.zst
nixpkgs-ab4c35982269e8f1f15e07afa7fedf65c749f276.zip
stdenv/patchShebangs: use builtins where possible
builtins for small input sizes should be faster due to less forking.
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/patch-shebangs.sh14
1 files changed, 8 insertions, 6 deletions
diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh
index b48b0c50f57..fa90a6fd805 100644
--- a/pkgs/build-support/setup-hooks/patch-shebangs.sh
+++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh
@@ -50,8 +50,8 @@ patchShebangs() {
     while IFS= read -r -d $'\0' f; do
         isScript "$f" || continue
 
-        oldInterpreterLine=$(head -1 "$f" | tail -c+3)
-        read -r oldPath arg0 args <<< "$oldInterpreterLine"
+        read -r oldInterpreterLine < "$f"
+        read -r oldPath arg0 args <<< "${oldInterpreterLine:3}"
 
         if [ -z "$pathName" ]; then
             if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then
@@ -61,11 +61,11 @@ patchShebangs() {
             fi
         fi
 
-        if $(echo "$oldPath" | grep -q "/bin/env$"); then
+        if [[ "$oldPath" == *"/bin/env" ]]; then
             # Check for unsupported 'env' functionality:
             # - options: something starting with a '-'
             # - environment variables: foo=bar
-            if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then
+            if [[ "$arg0" == "-"* ]] || [[ "$arg0" == *"="* ]]; then
                 echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >&2
                 exit 1
             fi
@@ -84,13 +84,15 @@ patchShebangs() {
         fi
 
         # Strip trailing whitespace introduced when no arguments are present
-        newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')"
+        newInterpreterLine="$newPath $args"
+        newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}}
 
         if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
             if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
                 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
                 # escape the escape chars so that sed doesn't interpret them
-                escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
+                escapedInterpreterLine=${newInterpreterLine//\\/\\\\}
+
                 # Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33281
                 timestamp=$(mktemp)
                 touch -r "$f" "$timestamp"