autoPatchelfHook: fix shellcheck errors

This commit is contained in:
DavHau 2020-12-14 13:27:58 +07:00 committed by Frederik Rietdijk
parent 4ac5d22654
commit 2fde1e63ba

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
declare -a autoPatchelfLibs declare -a autoPatchelfLibs
declare -Ag autoPatchelfFailedDeps declare -Ag autoPatchelfFailedDeps
@ -11,6 +13,8 @@ runPatchelf() {
patchelf "$@" || (echo "Command failed: patchelf $*" && exit 1) patchelf "$@" || (echo "Command failed: patchelf $*" && exit 1)
} }
# shellcheck disable=SC2154
# (targetOffset is referenced but not assigned.)
addEnvHooks "$targetOffset" gatherLibraries addEnvHooks "$targetOffset" gatherLibraries
isExecutable() { isExecutable() {
@ -116,6 +120,8 @@ autoPatchelfFile() {
interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")" interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
if isExecutable "$toPatch"; then if isExecutable "$toPatch"; then
runPatchelf --set-interpreter "$interpreter" "$toPatch" runPatchelf --set-interpreter "$interpreter" "$toPatch"
# shellcheck disable=SC2154
# (runtimeDependencies is referenced but not assigned.)
if [ -n "$runtimeDependencies" ]; then if [ -n "$runtimeDependencies" ]; then
for dep in $runtimeDependencies; do for dep in $runtimeDependencies; do
rpath="$rpath${rpath:+:}$dep/lib" rpath="$rpath${rpath:+:}$dep/lib"
@ -129,10 +135,11 @@ autoPatchelfFile() {
# clear the RPATH first. # clear the RPATH first.
runPatchelf --remove-rpath "$toPatch" runPatchelf --remove-rpath "$toPatch"
local missing="$( local missing
missing="$(
ldd "$toPatch" 2> /dev/null | \ ldd "$toPatch" 2> /dev/null | \
sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p' sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p'
)" )" || return 0
# This ensures that we get the output of all missing dependencies instead # 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 # of failing at the first one, because it's more useful when working on a
@ -174,10 +181,10 @@ addAutoPatchelfSearchPath() {
esac esac
done done
for file in \ while IFS= read -r -d '' file; do
$(find "$@" "${findOpts[@]}" \! -type d \ addToDepCache "$file"
\( -name '*.so' -o -name '*.so.*' \)) done < <(find "$@" "${findOpts[@]}" \! -type d \
do addToDepCache "$file"; done \( -name '*.so' -o -name '*.so.*' \) -print0)
} }
autoPatchelf() { autoPatchelf() {
@ -230,6 +237,8 @@ autoPatchelf() {
echo "autoPatchelfHook could not satisfy dependency $failedDep wanted by ${autoPatchelfFailedDeps[$failedDep]}" echo "autoPatchelfHook could not satisfy dependency $failedDep wanted by ${autoPatchelfFailedDeps[$failedDep]}"
depsMissing=1 depsMissing=1
done done
# shellcheck disable=SC2154
# (autoPatchelfIgnoreMissingDeps is referenced but not assigned.)
if [[ $depsMissing == 1 && -z "$autoPatchelfIgnoreMissingDeps" ]]; then if [[ $depsMissing == 1 && -z "$autoPatchelfIgnoreMissingDeps" ]]; then
echo "Add the missing dependencies to the build inputs or set autoPatchelfIgnoreMissingDeps=true" echo "Add the missing dependencies to the build inputs or set autoPatchelfIgnoreMissingDeps=true"
exit 1 exit 1