Skip to content

Commit

Permalink
stdenv: make _accumFlagsArray independent of structuredAttrs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wolfgangwalther committed Aug 2, 2024
1 parent 929db7b commit bfd97a6
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -n nameref="$name"
flagsArray+=( ${nameref+"${nameref[@]}"} )
done
else
for name in "$@"; do
local name type
for name in "$@"; do
if type=$(declare -p "$name" 2> /dev/null); then
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.
Expand Down

0 comments on commit bfd97a6

Please sign in to comment.