nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!@shell@
2# shellcheck shell=bash
3
4declare -a autoPatchcilLibs
5declare -a extraAutoPatchcilLibs
6
7gatherLibraries() {
8 if [ -d "$1/lib" ]; then
9 autoPatchcilLibs+=("$1/lib")
10 fi
11}
12
13addEnvHooks "${targetOffset:?}" gatherLibraries
14
15# Can be used to manually add additional directories with shared object files
16# to be included for the next autoPatchcil invocation.
17addAutoPatchcilSearchPath() {
18 local -a findOpts=()
19
20 while [ $# -gt 0 ]; do
21 case "$1" in
22 --)
23 shift
24 break
25 ;;
26 --no-recurse)
27 shift
28 findOpts+=("-maxdepth" 1)
29 ;;
30 --*)
31 echo "addAutoPatchcilSearchPath: ERROR: Invalid command line" \
32 "argument: $1" >&2
33 return 1
34 ;;
35 *) break ;;
36 esac
37 done
38
39 local dir=
40 while IFS= read -r -d '' dir; do
41 extraAutoPatchcilLibs+=("$dir")
42 done < <(
43 find "$@" "${findOpts[@]}" \! -type d \
44 \( -name '*.so' -o -name '*.so.*' \) -print0 |
45 sed -z 's#/[^/]*$##' |
46 uniq -z
47 )
48}
49
50autoPatchcil() {
51 local rid=
52 local norecurse=
53 while [ $# -gt 0 ]; do
54 case "$1" in
55 --)
56 shift
57 break
58 ;;
59 --rid)
60 rid="$2"
61 shift 2
62 ;;
63 --no-recurse)
64 shift
65 norecurse=1
66 ;;
67 --*)
68 echo "autoPatchcil: ERROR: Invalid command line" \
69 "argument: $1" >&2
70 return 1
71 ;;
72 *) break ;;
73 esac
74 done
75
76 if [ -z "$rid" ]; then
77 echo "autoPatchcil: ERROR: No RID (Runtime ID) provided." >&2
78 return 1
79 fi
80
81 local ignoreMissingDepsArray=("--ignore-missing")
82 concatTo ignoreMissingDepsArray autoPatchcilIgnoreMissingDeps
83
84 if [ ${#ignoreMissingDepsArray[@]} -lt 2 ]; then
85 ignoreMissingDepsArray=()
86 fi
87
88 local autoPatchcilFlags=(
89 ${norecurse:+--no-recurse}
90 --rid "$rid"
91 "${ignoreMissingDepsArray[@]}"
92 --paths "$@"
93 --libs "${autoPatchcilLibs[@]}"
94 )
95
96 # shellcheck disable=SC2016
97 echoCmd 'patchcil auto flags' "${autoPatchcilFlags[@]}"
98 @patchcil@ auto "${autoPatchcilFlags[@]}"
99}
100
101autoPatchcilFixupOutput() {
102 if [[ -z "${dontAutoPatchcil-}" ]]; then
103 if [ -n "${dotnetRuntimeIds+x}" ]; then
104 if [[ -n $__structuredAttrs ]]; then
105 local dotnetRuntimeIdsArray=("${dotnetRuntimeIds[@]}")
106 else
107 # shellcheck disable=SC2206 # Intentionally expanding it to preserve old behavior
108 local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
109 fi
110 else
111 local dotnetRuntimeIdsArray=("")
112 fi
113
114 autoPatchcil --rid "${autoPatchcilRuntimeId:-${dotnetRuntimeIdsArray[0]}}" -- "${prefix:?}"
115 fi
116}
117
118fixupOutputHooks+=(autoPatchcilFixupOutput)