Skip to content

Commit

Permalink
autoPatchelfHook: fix shellcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DavHau authored and FRidh committed Dec 25, 2020
1 parent 4ac5d22 commit 2fde1e6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

declare -a autoPatchelfLibs
declare -Ag autoPatchelfFailedDeps

Expand All @@ -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() {
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fde1e6

Please sign in to comment.