Skip to content

Commit eaafa59

Browse files
committed
Don't use mapfile as it isn't bash 3 compatible
1 parent a6e5cb2 commit eaafa59

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

hack/lib/golang.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}")
137137
# NOTE: All functions that return lists should use newlines.
138138
# bash functions can't return arrays, and spaces are tricky, so newline
139139
# separators are the preferred pattern.
140-
# To transform a string of newline-separated items to an array, use mapfile -t:
141-
# mapfile -t FOO <<< "$(kube::golang::dups a b c a)"
140+
# To transform a string of newline-separated items to an array, use kube::util::read-array:
141+
# kube::util::read-array FOO < <(kube::golang::dups a b c a)
142142
#
143143
# ALWAYS remember to quote your subshells. Not doing so will break in
144144
# bash 4.3, and potentially cause other issues.
@@ -172,33 +172,33 @@ kube::golang::setup_platforms() {
172172

173173
# Deduplicate to ensure the intersection trick with kube::golang::dups
174174
# is not defeated by duplicates in user input.
175-
mapfile -t platforms <<< "$(kube::golang::dedup "${platforms[@]}")"
175+
kube::util::read-array platforms < <(kube::golang::dedup "${platforms[@]}")
176176

177177
# Use kube::golang::dups to restrict the builds to the platforms in
178178
# KUBE_SUPPORTED_*_PLATFORMS. Items should only appear at most once in each
179179
# set, so if they appear twice after the merge they are in the intersection.
180-
mapfile -t KUBE_SERVER_PLATFORMS <<< "$(kube::golang::dups \
180+
kube::util::read-array KUBE_SERVER_PLATFORMS < <(kube::golang::dups \
181181
"${platforms[@]}" \
182182
"${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}" \
183-
)"
183+
)
184184
readonly KUBE_SERVER_PLATFORMS
185185

186-
mapfile -t KUBE_NODE_PLATFORMS <<< "$(kube::golang::dups \
186+
kube::util::read-array KUBE_NODE_PLATFORMS < <(kube::golang::dups \
187187
"${platforms[@]}" \
188188
"${KUBE_SUPPORTED_NODE_PLATFORMS[@]}" \
189-
)"
189+
)
190190
readonly KUBE_NODE_PLATFORMS
191191

192-
mapfile -t KUBE_TEST_PLATFORMS <<< "$(kube::golang::dups \
192+
kube::util::read-array KUBE_TEST_PLATFORMS < <(kube::golang::dups \
193193
"${platforms[@]}" \
194194
"${KUBE_SUPPORTED_TEST_PLATFORMS[@]}" \
195-
)"
195+
)
196196
readonly KUBE_TEST_PLATFORMS
197197

198-
mapfile -t KUBE_CLIENT_PLATFORMS <<< "$(kube::golang::dups \
198+
kube::util::read-array KUBE_CLIENT_PLATFORMS < <(kube::golang::dups \
199199
"${platforms[@]}" \
200200
"${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}" \
201-
)"
201+
)
202202
readonly KUBE_CLIENT_PLATFORMS
203203

204204
elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then

hack/lib/util.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,23 @@ function kube::util::require-jq {
702702
fi
703703
}
704704

705+
# kube::util::read-array
706+
# Reads in stdin and adds it line by line to the array provided. This can be
707+
# used instead of "mapfile -t", and is bash 3 compatible.
708+
#
709+
# Assumed vars:
710+
# $1 (name of array to create/modify)
711+
#
712+
# Example usage:
713+
# kube::util::read-array files < <(ls -1)
714+
#
715+
function kube::util::read-array {
716+
local i=0
717+
unset -v "$1"
718+
while IFS= read -r "$1[i++]"; do :; done
719+
eval "[[ \${$1[--i]} ]]" || unset "$1[i]" # ensures last element isn't empty
720+
}
721+
705722
# Some useful colors.
706723
if [[ -z "${color_start-}" ]]; then
707724
declare -r color_start="\033["

0 commit comments

Comments
 (0)