From 2ad2295bb3d6093b93f6a3a0617119e54e162156 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 11 Mar 2024 09:29:22 -0600 Subject: [PATCH] autoPatchelfHook: move multiline hook into a function In NixOS/nixpkgs#290081 it came to attention that autoPatchelfHook is one of if not the only hook in Nixpkgs that is a multiline string expression. Almost all hooks are functions, which guard with something like `if [ -z "${dontDoTheThing-}" ]; then ...` in the function, or single-line strings which include that guard inline and then call the real function, e.g. `if [ -z "${dontDoTheThing-} ]; then doTheThing; fi`. This commit moves autoPatchelfHook to the former, which seems to be the most common style now. --- .../setup-hooks/auto-patchelf.sh | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh index 9f6366b3feae..783ea45f8eeb 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -88,22 +88,21 @@ autoPatchelf() { --extra-args "${patchelfFlagsArray[@]}" } -# 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. -# -# shellcheck disable=SC2016 -# (Expressions don't expand in single quotes, use double quotes for that.) -postFixupHooks+=(' - if [ -z "${dontAutoPatchelf-}" ]; then +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)