summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavHau <hsngrmpf+github@gmail.com>2020-12-14 13:27:58 +0700
committerFrederik Rietdijk <freddyrietdijk@fridh.nl>2020-12-25 12:13:03 +0100
commit2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f (patch)
tree9dbdec3ea0680d73a967bd422d88c242f2a1c1a8
parent4ac5d226541c32622730d7d6c967457c7ec6bc38 (diff)
downloadnixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar.gz
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar.bz2
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar.lz
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar.xz
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.tar.zst
nixpkgs-2fde1e63ba2c8dd22bc2622ac3edb2f8c662379f.zip
autoPatchelfHook: fix shellcheck errors
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh21
1 files changed, 15 insertions, 6 deletions
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index cfca3f1c904..3c0997a0dcd 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
 declare -a autoPatchelfLibs
 declare -Ag autoPatchelfFailedDeps
 
@@ -11,6 +13,8 @@ runPatchelf() {
   patchelf "$@" || (echo "Command failed: patchelf $*" && exit 1)
 }
 
+# shellcheck disable=SC2154
+# (targetOffset is referenced but not assigned.)
 addEnvHooks "$targetOffset" gatherLibraries
 
 isExecutable() {
@@ -116,6 +120,8 @@ autoPatchelfFile() {
     interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
     if isExecutable "$toPatch"; then
         runPatchelf --set-interpreter "$interpreter" "$toPatch"
+        # shellcheck disable=SC2154
+        # (runtimeDependencies is referenced but not assigned.)
         if [ -n "$runtimeDependencies" ]; then
             for dep in $runtimeDependencies; do
                 rpath="$rpath${rpath:+:}$dep/lib"
@@ -129,10 +135,11 @@ autoPatchelfFile() {
     # clear the RPATH first.
     runPatchelf --remove-rpath "$toPatch"
 
-    local missing="$(
+    local missing
+    missing="$(
         ldd "$toPatch" 2> /dev/null | \
             sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p'
-    )"
+    )" || return 0
 
     # This ensures that we get the output of all missing dependencies instead
     # of failing at the first one, because it's more useful when working on a
@@ -174,10 +181,10 @@ addAutoPatchelfSearchPath() {
         esac
     done
 
-    for file in \
-      $(find "$@" "${findOpts[@]}" \! -type d \
-          \( -name '*.so' -o -name '*.so.*' \))
-    do addToDepCache "$file"; done
+    while IFS= read -r -d '' file; do
+    addToDepCache "$file"
+    done <  <(find "$@" "${findOpts[@]}" \! -type d \
+            \( -name '*.so' -o -name '*.so.*' \) -print0)
 }
 
 autoPatchelf() {
@@ -230,6 +237,8 @@ autoPatchelf() {
       echo "autoPatchelfHook could not satisfy dependency $failedDep wanted by ${autoPatchelfFailedDeps[$failedDep]}"
       depsMissing=1
     done
+    # shellcheck disable=SC2154
+    # (autoPatchelfIgnoreMissingDeps is referenced but not assigned.)
     if [[ $depsMissing == 1 && -z "$autoPatchelfIgnoreMissingDeps" ]]; then
       echo "Add the missing dependencies to the build inputs or set autoPatchelfIgnoreMissingDeps=true"
       exit 1