nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 104 lines 3.8 kB view raw
1# shellcheck shell=bash 2 3declare -a autoPatchelfLibs 4declare -a extraAutoPatchelfLibs 5 6gatherLibraries() { 7 autoPatchelfLibs+=("$1/lib") 8} 9 10# shellcheck disable=SC2154 11# (targetOffset is referenced but not assigned.) 12addEnvHooks "$targetOffset" gatherLibraries 13 14# Can be used to manually add additional directories with shared object files 15# to be included for the next autoPatchelf invocation. 16addAutoPatchelfSearchPath() { 17 local -a findOpts=() 18 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 30 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 38 ) 39} 40 41 42autoPatchelf() { 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 55 56 concatTo ignoreMissingDepsArray autoPatchelfIgnoreMissingDeps 57 concatTo appendRunpathsArray appendRunpaths 58 concatTo runtimeDependenciesArray runtimeDependencies 59 concatTo patchelfFlagsArray patchelfFlags 60 concatTo autoPatchelfFlagsArray autoPatchelfFlags 61 62 # Check if ignoreMissingDepsArray contains "1" and if so, replace it with 63 # "*", printing a deprecation warning. 64 for dep in "${ignoreMissingDepsArray[@]}"; do 65 if [ "$dep" == "1" ]; then 66 echo "autoPatchelf: WARNING: setting 'autoPatchelfIgnoreMissingDeps" \ 67 "= true;' is deprecated and will be removed in a future release." \ 68 "Use 'autoPatchelfIgnoreMissingDeps = [ \"*\" ];' instead." >&2 69 ignoreMissingDepsArray=( "*" ) 70 break 71 fi 72 done 73 74 auto-patchelf \ 75 ${norecurse:+--no-recurse} \ 76 --ignore-missing "${ignoreMissingDepsArray[@]}" \ 77 --paths "$@" \ 78 --libs "${autoPatchelfLibs[@]}" \ 79 "${extraAutoPatchelfLibs[@]}" \ 80 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 81 --append-rpaths "${appendRunpathsArray[@]}" \ 82 "${autoPatchelfFlagsArray[@]}" \ 83 --extra-args "${patchelfFlagsArray[@]}" 84} 85 86autoPatchelfPostFixup() { 87 # XXX: This should ultimately use fixupOutputHooks but we currently don't have 88 # a way to enforce the order. If we have $runtimeDependencies set, the setup 89 # hook of patchelf is going to ruin everything and strip out those additional 90 # RPATHs. 91 # 92 # So what we do here is basically run in postFixup and emulate the same 93 # behaviour as fixupOutputHooks because the setup hook for patchelf is run in 94 # fixupOutput and the postFixup hook runs later. 95 if [[ -z "${dontAutoPatchelf-}" ]]; then 96 autoPatchelf -- $(for output in $(getAllOutputNames); do 97 [ -e "${!output}" ] || continue 98 [ "${output}" = debug ] && continue 99 echo "${!output}" 100 done) 101 fi 102} 103 104postFixupHooks+=(autoPatchelfPostFixup)