From bfd97a691f165c2a160d5c86a7dbfd89fcbdb33c Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 9 Jun 2024 14:06:28 +0200 Subject: [PATCH] stdenv: make _accumFlagsArray independent of structuredAttrs structuredAttrs was used here to make an assumption about the type of the named variables passed as arguments. This can be done better by looking at the actual types of those variables. This gives a bit more backwards compatibility as well: Once you turn to structuredAttrs, you should still be able to pass a bare string instead of a list and have it behave as a whitespace-separated string like before. --- pkgs/stdenv/generic/setup.sh | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 8d060493b556..8255f3aaafb7 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -336,34 +336,24 @@ appendToVar() { # Accumulate into `flagsArray` the flags from the named variables. # -# If __structuredAttrs, the variables are all treated as arrays -# and simply concatenated onto `flagsArray`. -# -# If not __structuredAttrs, then: -# * Each variable is treated as a string, and split on whitespace; -# * except variables whose names end in "Array", which are treated -# as arrays. +# Arrays are simply concatenated, strings are split on whitespace. _accumFlagsArray() { - local name - if [ -n "$__structuredAttrs" ]; then - for name in "$@"; do + local name type + for name in "$@"; do + if type=$(declare -p "$name" 2> /dev/null); then local -n nameref="$name" - flagsArray+=( ${nameref+"${nameref[@]}"} ) - done - else - for name in "$@"; do - local -n nameref="$name" - case "$name" in - *Array) - # shellcheck disable=SC2206 - flagsArray+=( ${nameref+"${nameref[@]}"} ) ;; + case "${type#* }" in + -A*) + echo "_accumFlagsArray(): ERROR: trying to use _accumFlagsArray on an associative array." >&2 + return 1 ;; + -a*) + flagsArray+=( "${nameref[@]}" ) ;; *) # shellcheck disable=SC2206 flagsArray+=( ${nameref-} ) ;; esac - done - fi - + fi + done } # Add $1/lib* into rpaths.