python311Packages.moto: 4.2.6 -> 4.2.10
[NixPkgs.git] / pkgs / build-support / setup-hooks / auto-patchelf.sh
blob371389df427bc672a64b7fa6e399a297a708bfb4
1 # shellcheck shell=bash
3 declare -a autoPatchelfLibs
4 declare -a extraAutoPatchelfLibs
6 gatherLibraries() {
7 autoPatchelfLibs+=("$1/lib")
10 # shellcheck disable=SC2154
11 # (targetOffset is referenced but not assigned.)
12 addEnvHooks "$targetOffset" gatherLibraries
14 # Can be used to manually add additional directories with shared object files
15 # to be included for the next autoPatchelf invocation.
16 addAutoPatchelfSearchPath() {
17 local -a findOpts=()
19 while [ $# -gt 0 ]; do
20 case "$1" in
21 --) shift; break;;
22 --no-recurse) shift; findOpts+=("-maxdepth" 1);;
23 --*)
24 echo "addAutoPatchelfSearchPath: ERROR: Invalid command line" \
25 "argument: $1" >&2
26 return 1;;
27 *) break;;
28 esac
29 done
31 local dir=
32 while IFS= read -r -d '' dir; do
33 extraAutoPatchelfLibs+=("$dir")
34 done < <(find "$@" "${findOpts[@]}" \! -type d \
35 \( -name '*.so' -o -name '*.so.*' \) -print0 \
36 | sed -z 's#/[^/]*$##' \
37 | uniq -z
42 autoPatchelf() {
43 local norecurse=
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 --) shift; break;;
47 --no-recurse) shift; norecurse=1;;
48 --*)
49 echo "autoPatchelf: ERROR: Invalid command line" \
50 "argument: $1" >&2
51 return 1;;
52 *) break;;
53 esac
54 done
56 readarray -td' ' ignoreMissingDepsArray < <(echo -n "$autoPatchelfIgnoreMissingDeps")
57 if [ "$autoPatchelfIgnoreMissingDeps" == "1" ]; then
58 echo "autoPatchelf: WARNING: setting 'autoPatchelfIgnoreMissingDeps" \
59 "= true;' is deprecated and will be removed in a future release." \
60 "Use 'autoPatchelfIgnoreMissingDeps = [ \"*\" ];' instead." >&2
61 ignoreMissingDepsArray=( "*" )
64 local appendRunpathsArray=($appendRunpaths)
65 local runtimeDependenciesArray=($runtimeDependencies)
66 local patchelfFlagsArray=($patchelfFlags)
67 @pythonInterpreter@ @autoPatchelfScript@ \
68 ${norecurse:+--no-recurse} \
69 --ignore-missing "${ignoreMissingDepsArray[@]}" \
70 --paths "$@" \
71 --libs "${autoPatchelfLibs[@]}" \
72 "${extraAutoPatchelfLibs[@]}" \
73 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \
74 --append-rpaths "${appendRunpathsArray[@]}" \
75 --extra-args "${patchelfFlagsArray[@]}"
78 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
79 # a way to enforce the order. If we have $runtimeDependencies set, the setup
80 # hook of patchelf is going to ruin everything and strip out those additional
81 # RPATHs.
83 # So what we do here is basically run in postFixup and emulate the same
84 # behaviour as fixupOutputHooks because the setup hook for patchelf is run in
85 # fixupOutput and the postFixup hook runs later.
87 # shellcheck disable=SC2016
88 # (Expressions don't expand in single quotes, use double quotes for that.)
89 postFixupHooks+=('
90 if [ -z "${dontAutoPatchelf-}" ]; then
91 autoPatchelf -- $(for output in $(getAllOutputNames); do
92 [ -e "${!output}" ] || continue
93 echo "${!output}"
94 done)