multiple-outputs.sh: fix with structuredAttrs

The variable `propagatedBuildOutputs` was only allowed to be a string,
so when `__structuredAttrs = true` was set, it was incorrectly detected,
especially for empty arrays. Refactor the code to allow it to be either
an array or string.

Closes: #323126
This commit is contained in:
sempiternal-aurora
2026-08-19 00:19:23 +10:00
parent 7b6bd159cc
commit 009b2db5bb

View File

@@ -192,23 +192,25 @@ _multioutPropagateDev() {
propagaterOutput="$outputFirst"
fi
# Default value: propagate binaries, includes and libraries
if [ -z "${propagatedBuildOutputs+1}" ]; then
local outputsToPropagate=()
if declare -p propagatedBuildOutputs &>/dev/null; then
concatTo outputsToPropagate propagatedBuildOutputs
else
local po_dirty="$outputBin $outputInclude $outputLib"
set +o pipefail
propagatedBuildOutputs=`echo "$po_dirty" \
readarray -t outputsToPropagate < <(echo "$po_dirty" \
| tr -s ' ' '\n' | grep -v -F "$propagaterOutput" \
| sort -u | tr '\n' ' ' `
| sort -u )
set -o pipefail
fi
# The variable was explicitly set to empty or we resolved it so
if [ -z "$propagatedBuildOutputs" ]; then
# Check whether we actually have any outputs to propagate
if [[ "${#outputsToPropagate[@]}" -eq 0 ]]; then
return
fi
mkdir -p "${!propagaterOutput}"/nix-support
for output in $propagatedBuildOutputs; do
for output in "${outputsToPropagate[@]}"; do
echo -n " ${!output}" >> "${!propagaterOutput}"/nix-support/propagated-build-inputs
done
}