@@ -1,3 +1,5 @@
1+#!/usr/bin/env bash
2+
13declare -a autoPatchelfLibs
24declare -Ag autoPatchelfFailedDeps
35
@@ -11,6 +13,8 @@ runPatchelf() {
1113 patchelf "$@" || (echo "Command failed: patchelf $*" && exit 1)
1214}
1315
16+# shellcheck disable=SC2154
17+# (targetOffset is referenced but not assigned.)
1418addEnvHooks "$targetOffset" gatherLibraries
1519
1620isExecutable() {
@@ -116,6 +120,8 @@ autoPatchelfFile() {
116120 interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
117121 if isExecutable "$toPatch"; then
118122 runPatchelf --set-interpreter "$interpreter" "$toPatch"
123+ # shellcheck disable=SC2154
124+ # (runtimeDependencies is referenced but not assigned.)
119125 if [ -n "$runtimeDependencies" ]; then
120126 for dep in $runtimeDependencies; do
121127 rpath="$rpath${rpath:+:}$dep/lib"
@@ -129,10 +135,11 @@ autoPatchelfFile() {
129135 # clear the RPATH first.
130136 runPatchelf --remove-rpath "$toPatch"
131137
132− local missing="$(
138+ local missing
139+ missing="$(
133140 ldd "$toPatch" 2> /dev/null | \
134141 sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p'
135− )"
142+ )" || return 0
136143
137144 # This ensures that we get the output of all missing dependencies instead
138145 # of failing at the first one, because it's more useful when working on a
@@ -174,10 +181,10 @@ addAutoPatchelfSearchPath() {
174181 esac
175182 done
176183
177− for file in \
178− $(find "$@" "${findOpts[@]}" \! -type d \
179− \( -name '*.so' -o -name '*.so.*' \))
180− do addToDepCache "$file"; done
184+ while IFS= read -r -d '' file; do
185+ addToDepCache "$file"
186+ done < <(find "$@" "${findOpts[@]}" \! -type d \
187+ \( -name '*.so' -o -name '*.so.*' \) -print0)
181188}
182189
183190autoPatchelf() {
@@ -230,6 +237,8 @@ autoPatchelf() {
230237 echo "autoPatchelfHook could not satisfy dependency $failedDep wanted by ${autoPatchelfFailedDeps[$failedDep]}"
231238 depsMissing=1
232239 done
240+ # shellcheck disable=SC2154
241+ # (autoPatchelfIgnoreMissingDeps is referenced but not assigned.)
233242 if [[ $depsMissing == 1 && -z "$autoPatchelfIgnoreMissingDeps" ]]; then
234243 echo "Add the missing dependencies to the build inputs or set autoPatchelfIgnoreMissingDeps=true"
235244 exit 1