nixpkgs/pkgs/build-support/setup-hooks/auto-patchelf.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
4.1 KiB
Bash
Raw Normal View History

# shellcheck shell=bash
declare -a autoPatchelfLibs
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
declare -a extraAutoPatchelfLibs
gatherLibraries() {
autoPatchelfLibs+=("$1/lib")
}
# shellcheck disable=SC2154
# (targetOffset is referenced but not assigned.)
addEnvHooks "$targetOffset" gatherLibraries
# Can be used to manually add additional directories with shared object files
# to be included for the next autoPatchelf invocation.
addAutoPatchelfSearchPath() {
local -a findOpts=()
while [ $# -gt 0 ]; do
case "$1" in
--) shift; break;;
--no-recurse) shift; findOpts+=("-maxdepth" 1);;
--*)
echo "addAutoPatchelfSearchPath: ERROR: Invalid command line" \
"argument: $1" >&2
return 1;;
*) break;;
esac
done
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
local dir=
while IFS= read -r -d '' dir; do
extraAutoPatchelfLibs+=("$dir")
done < <(find "$@" "${findOpts[@]}" \! -type d \
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
\( -name '*.so' -o -name '*.so.*' \) -print0 \
| sed -z 's#/[^/]*$##' \
| uniq -z
)
}
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
autoPatchelf() {
local norecurse=
while [ $# -gt 0 ]; do
case "$1" in
--) shift; break;;
--no-recurse) shift; norecurse=1;;
--*)
echo "autoPatchelf: ERROR: Invalid command line" \
"argument: $1" >&2
return 1;;
*) break;;
esac
done
if [ -n "$__structuredAttrs" ]; then
local ignoreMissingDepsArray=( "${autoPatchelfIgnoreMissingDeps[@]}" )
local appendRunpathsArray=( "${appendRunpaths[@]}" )
local runtimeDependenciesArray=( "${runtimeDependencies[@]}" )
local patchelfFlagsArray=( "${patchelfFlags[@]}" )
local autoPatchelfFlagsArray=( "${autoPatchelfFlags[@]}" )
else
readarray -td' ' ignoreMissingDepsArray < <(echo -n "$autoPatchelfIgnoreMissingDeps")
local appendRunpathsArray=($appendRunpaths)
local runtimeDependenciesArray=($runtimeDependencies)
local patchelfFlagsArray=($patchelfFlags)
local autoPatchelfFlagsArray=($autoPatchelfFlags)
fi
# 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
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
@pythonInterpreter@ @autoPatchelfScript@ \
${norecurse:+--no-recurse} \
--ignore-missing "${ignoreMissingDepsArray[@]}" \
rewrite autoPatchelfHook in python (#149731) * rewrite autoPatchelfHook in python * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Update pkgs/build-support/setup-hooks/auto-patchelf.py Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * Fix issues discovered during tests * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * fixup line wrapping * autoPatchelfHook: Improve compatibility with bash version * autoPatchelfHook: Fix symlink-reated issues * autoPatchelfHook: Revert dubious patchelf invocation test * autoPatchelfHook: Untangle the executable detection logic * fixup! autoPatchelfHook: Untangle the executable detection logic * autoPatchelfHook: Fix invalid borrow issue * autoPatchelfHook: Handle runtimeDependencies as the bare string it is * autoPatchelfHook: add bintools dependency For the very rare cases where it is not included by default. * autoPatchelfHook: replace old hook with the rewrite * autoPatchelfHook: get rid of the old hook content * autoPatchelfHook: fix wrong ordering of debug info * autoPatchelfHook: persist extra search path across incovations * autoPatchelfHook: fix wrong usage of global variables * Update auto-patchelf.py PEP8: ignoreMissing -> ignore_missing * Apply suggestions from code review Co-authored-by: aszlig <aszlig@redmoonstudios.org> * autoPatchelfHook: remove imprecise and incorrect warning * Apply explicit types from code review Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com> * Complement and polish types and snake_casing Co-authored-by: aszlig <aszlig@redmoonstudios.org> Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2022-02-04 09:08:27 +00:00
--paths "$@" \
--libs "${autoPatchelfLibs[@]}" \
"${extraAutoPatchelfLibs[@]}" \
--runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \
--append-rpaths "${appendRunpathsArray[@]}" \
"${autoPatchelfFlagsArray[@]}" \
--extra-args "${patchelfFlagsArray[@]}"
}
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
autoPatchelf -- $(for output in $(getAllOutputNames); do
[ -e "${!output}" ] || continue
echo "${!output}"
done)
fi
}
postFixupHooks+=(autoPatchelfPostFixup)