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:48:30 +0100
committerJörg Thalheim <joerg@thalheim.io>2021-01-14 20:00:57 +0100
commitcb1654ff92299eb8b7ab3ee609e1555fae117097 (patch)
tree3220ee73c44a2f83c5d713dac9944e5a38191e10 /pkgs/build-support/setup-hooks
parentab4c35982269e8f1f15e07afa7fedf65c749f276 (diff)
downloadnixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar.gz
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar.bz2
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar.lz
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar.xz
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.tar.zst
nixpkgs-cb1654ff92299eb8b7ab3ee609e1555fae117097.zip
stdenv/patchShebangs: consistent conditional tests
according to shellcheck [[ foo == "bla" ]] && [[ ... ]] has better posix
semantics over [ foo = "bla" -a ... ]. It is also easier to read.
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/patch-shebangs.sh22
1 files changed, 11 insertions, 11 deletions
diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh
index fa90a6fd805..bd254be24f9 100644
--- a/pkgs/build-support/setup-hooks/patch-shebangs.sh
+++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh
@@ -24,10 +24,10 @@ fixupOutputHooks+=(patchShebangsAuto)
 patchShebangs() {
     local pathName
 
-    if [ "$1" = "--host" ]; then
+    if [[ "$1" == "--host" ]]; then
         pathName=HOST_PATH
         shift
-    elif [ "$1" = "--build" ]; then
+    elif [[ "$1" == "--build" ]]; then
         pathName=PATH
         shift
     fi
@@ -41,7 +41,7 @@ patchShebangs() {
     local oldInterpreterLine
     local newInterpreterLine
 
-    if [ $# -eq 0 ]; then
+    if [[ $# -eq 0 ]]; then
         echo "No arguments supplied to patchShebangs" >&2
         return 0
     fi
@@ -53,8 +53,8 @@ patchShebangs() {
         read -r oldInterpreterLine < "$f"
         read -r oldPath arg0 args <<< "${oldInterpreterLine:3}"
 
-        if [ -z "$pathName" ]; then
-            if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then
+        if [[ -z "$pathName" ]]; then
+            if [[ -n $strictDeps && $f == "$NIX_STORE"* ]]; then
                 pathName=HOST_PATH
             else
                 pathName=PATH
@@ -65,14 +65,14 @@ patchShebangs() {
             # Check for unsupported 'env' functionality:
             # - options: something starting with a '-'
             # - environment variables: foo=bar
-            if [[ "$arg0" == "-"* ]] || [[ "$arg0" == *"="* ]]; then
+            if [[ $arg0 == "-"* || $arg0 == *"="* ]]; then
                 echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >&2
                 exit 1
             fi
 
             newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
         else
-            if [ "$oldPath" = "" ]; then
+            if [[ -z $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"
@@ -87,8 +87,8 @@ patchShebangs() {
         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
+        if [[ -n "$oldPath" && "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]]; then
+            if [[ -n "$newPath" ]] && [[ "$newPath" != "$oldPath" ]]; then
                 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
                 # escape the escape chars so that sed doesn't interpret them
                 escapedInterpreterLine=${newInterpreterLine//\\/\\\\}
@@ -107,12 +107,12 @@ patchShebangs() {
 }
 
 patchShebangsAuto () {
-    if [ -z "${dontPatchShebangs-}" -a -e "$prefix" ]; then
+    if [[ -z "${dontPatchShebangs-}" && -e "$prefix" ]]; then
 
         # 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).
-        if [ "$output" != out ] && [ "$output" = "$outputDev" ]; then
+        if [[ "$output" != out && "$output" = "$outputDev" ]]; then
             patchShebangs --build "$prefix"
         else
             patchShebangs --host "$prefix"