2022-12-12 22:24:33 +00:00
|
|
|
# shellcheck shell=bash
|
2020-12-14 06:27:58 +00:00
|
|
|
|
2018-02-01 21:54:18 +00:00
|
|
|
declare -a autoPatchelfLibs
|
2022-02-04 09:08:27 +00:00
|
|
|
declare -a extraAutoPatchelfLibs
|
2018-02-01 21:54:18 +00:00
|
|
|
|
|
|
|
gatherLibraries() {
|
|
|
|
autoPatchelfLibs+=("$1/lib")
|
|
|
|
}
|
|
|
|
|
2020-12-14 06:27:58 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
# (targetOffset is referenced but not assigned.)
|
2018-02-01 21:54:18 +00:00
|
|
|
addEnvHooks "$targetOffset" gatherLibraries
|
|
|
|
|
2018-11-25 15:17:14 +00:00
|
|
|
# Can be used to manually add additional directories with shared object files
|
|
|
|
# to be included for the next autoPatchelf invocation.
|
|
|
|
addAutoPatchelfSearchPath() {
|
2018-11-19 22:23:38 +00:00
|
|
|
local -a findOpts=()
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--) shift; break;;
|
|
|
|
--no-recurse) shift; findOpts+=("-maxdepth" 1);;
|
2018-11-25 15:17:14 +00:00
|
|
|
--*)
|
|
|
|
echo "addAutoPatchelfSearchPath: ERROR: Invalid command line" \
|
|
|
|
"argument: $1" >&2
|
|
|
|
return 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-02-04 09:08:27 +00:00
|
|
|
local dir=
|
|
|
|
while IFS= read -r -d '' dir; do
|
|
|
|
extraAutoPatchelfLibs+=("$dir")
|
2020-12-14 06:27:58 +00:00
|
|
|
done < <(find "$@" "${findOpts[@]}" \! -type d \
|
2022-02-04 09:08:27 +00:00
|
|
|
\( -name '*.so' -o -name '*.so.*' \) -print0 \
|
|
|
|
| sed -z 's#/[^/]*$##' \
|
|
|
|
| uniq -z
|
|
|
|
)
|
2018-11-25 15:17:14 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 09:08:27 +00:00
|
|
|
|
2018-11-25 15:17:14 +00:00
|
|
|
autoPatchelf() {
|
2018-11-26 00:13:59 +00:00
|
|
|
local norecurse=
|
2018-11-25 15:17:14 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--) shift; break;;
|
|
|
|
--no-recurse) shift; norecurse=1;;
|
2018-11-19 22:23:38 +00:00
|
|
|
--*)
|
|
|
|
echo "autoPatchelf: ERROR: Invalid command line" \
|
|
|
|
"argument: $1" >&2
|
|
|
|
return 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-12-07 19:26:39 +00:00
|
|
|
if [ -n "$__structuredAttrs" ]; then
|
|
|
|
local ignoreMissingDepsArray=( "${autoPatchelfIgnoreMissingDeps[@]}" )
|
|
|
|
local appendRunpathsArray=( "${appendRunpaths[@]}" )
|
|
|
|
local runtimeDependenciesArray=( "${runtimeDependencies[@]}" )
|
|
|
|
local patchelfFlagsArray=( "${patchelfFlags[@]}" )
|
2024-08-14 06:54:27 +00:00
|
|
|
local autoPatchelfFlagsArray=( "${autoPatchelfFlags[@]}" )
|
2023-12-07 19:26:39 +00:00
|
|
|
else
|
|
|
|
readarray -td' ' ignoreMissingDepsArray < <(echo -n "$autoPatchelfIgnoreMissingDeps")
|
|
|
|
local appendRunpathsArray=($appendRunpaths)
|
|
|
|
local runtimeDependenciesArray=($runtimeDependencies)
|
|
|
|
local patchelfFlagsArray=($patchelfFlags)
|
2024-08-14 06:54:27 +00:00
|
|
|
local autoPatchelfFlagsArray=($autoPatchelfFlags)
|
2023-12-07 19:26:39 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-14 16:53:34 +00:00
|
|
|
# Check if ignoreMissingDepsArray contains "1" and if so, replace it with
|
|
|
|
# "*", printing a deprecation warning.
|
|
|
|
for dep in "${ignoreMissingDepsArray[@]}"; do
|
|
|
|
if [ "$dep" == "1" ]; then
|
|
|
|
echo "autoPatchelf: WARNING: setting 'autoPatchelfIgnoreMissingDeps" \
|
|
|
|
"= true;' is deprecated and will be removed in a future release." \
|
|
|
|
"Use 'autoPatchelfIgnoreMissingDeps = [ \"*\" ];' instead." >&2
|
|
|
|
ignoreMissingDepsArray=( "*" )
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2022-04-11 01:28:55 +00:00
|
|
|
|
2022-02-04 09:08:27 +00:00
|
|
|
@pythonInterpreter@ @autoPatchelfScript@ \
|
|
|
|
${norecurse:+--no-recurse} \
|
2022-04-14 03:47:59 +00:00
|
|
|
--ignore-missing "${ignoreMissingDepsArray[@]}" \
|
2022-02-04 09:08:27 +00:00
|
|
|
--paths "$@" \
|
|
|
|
--libs "${autoPatchelfLibs[@]}" \
|
|
|
|
"${extraAutoPatchelfLibs[@]}" \
|
2023-04-13 00:41:22 +00:00
|
|
|
--runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \
|
2023-09-21 15:49:49 +00:00
|
|
|
--append-rpaths "${appendRunpathsArray[@]}" \
|
2024-08-14 06:54:27 +00:00
|
|
|
"${autoPatchelfFlagsArray[@]}" \
|
2023-09-21 15:49:49 +00:00
|
|
|
--extra-args "${patchelfFlagsArray[@]}"
|
2018-02-01 21:54:18 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 15:29:22 +00:00
|
|
|
autoPatchelfPostFixup() {
|
|
|
|
# XXX: This should ultimately use fixupOutputHooks but we currently don't have
|
|
|
|
# a way to enforce the order. If we have $runtimeDependencies set, the setup
|
|
|
|
# hook of patchelf is going to ruin everything and strip out those additional
|
|
|
|
# RPATHs.
|
|
|
|
#
|
|
|
|
# So what we do here is basically run in postFixup and emulate the same
|
|
|
|
# behaviour as fixupOutputHooks because the setup hook for patchelf is run in
|
|
|
|
# fixupOutput and the postFixup hook runs later.
|
|
|
|
if [[ -z "${dontAutoPatchelf-}" ]]; then
|
2022-05-31 21:34:59 +00:00
|
|
|
autoPatchelf -- $(for output in $(getAllOutputNames); do
|
2018-11-19 16:36:22 +00:00
|
|
|
[ -e "${!output}" ] || continue
|
|
|
|
echo "${!output}"
|
|
|
|
done)
|
|
|
|
fi
|
2024-03-11 15:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
postFixupHooks+=(autoPatchelfPostFixup)
|