util/abuild: fix TODO and update targets variable to an array

Use an array instead of a variable as suggested by the TODO, so we can
remove the shellcheck disable and fix the warning.

Change-Id: I5e872ebe350f339b932a711fe7f6a68743f002ed
Signed-off-by: Martin Roth <gaumless@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87379
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
This commit is contained in:
Martin Roth 2025-04-20 13:54:03 -06:00 committed by Matt DeVillier
commit 64fe6fd94a

View file

@ -176,22 +176,30 @@ mainboard_vendor()
# If a directory contains multiple boards, returns them all.
normalize_target()
{
# TODO: Change 'targets' variable to an array
local targets
local target_input=$1
local -a targets=() # Initialize as an empty array
local VARIANT_UC
local i
VARIANT_UC=$(echo "${variant}" | tr '[:lower:]' '[:upper:]' | tr '-' '_')
targets=$(get_mainboards "$1")
if [[ -n "${targets}" ]]; then
# shellcheck disable=SC2086
targets="$(grep "${VARIANT_UC}\$" <<< ${targets})"
echo "${targets}"
# Read output of get_mainboards into the targets array
mapfile -t targets < <(get_mainboards "${target_input}")
if [[ ${#targets[@]} -gt 0 ]]; then
# Filter the array using grep
mapfile -t targets < <(printf '%s\n' "${targets[@]}" | grep "${VARIANT_UC}\$")
# Print the filtered targets, one per line
if [[ ${#targets[@]} -gt 0 ]]; then
printf '%s\n' "${targets[@]}"
fi
return
fi
targets=$(echo "$1" | tr ',' ' ')
for i in ${targets}; do
# Handle comma-separated input string
IFS=',' read -ra targets <<< "${target_input}"
for i in "${targets[@]}"; do
# Trim whitespace if necessary (read -ra might include it)
i=$(echo "$i" | xargs)
if [[ -n "$(mainboard_directory "${i}")" ]]; then
printf "%s\n" "${i}"
else