From 64fe6fd94a3fde6b80c4112b81b9e0255e4e31d6 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sun, 20 Apr 2025 13:54:03 -0600 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/87379 Tested-by: build bot (Jenkins) Reviewed-by: Matt DeVillier --- util/abuild/abuild | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/util/abuild/abuild b/util/abuild/abuild index f1c7edc2a8..5b87cbc2e7 100755 --- a/util/abuild/abuild +++ b/util/abuild/abuild @@ -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