Don't use mapfile as it isn't bash 3 compatible

pull/564/head
Christoph Blecker 2019-05-06 15:55:12 -07:00
parent 28f2526923
commit 1b18987e57
No known key found for this signature in database
GPG Key ID: B34A59A9D39F838B
2 changed files with 28 additions and 11 deletions

View File

@ -137,8 +137,8 @@ readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}")
# NOTE: All functions that return lists should use newlines. # NOTE: All functions that return lists should use newlines.
# bash functions can't return arrays, and spaces are tricky, so newline # bash functions can't return arrays, and spaces are tricky, so newline
# separators are the preferred pattern. # separators are the preferred pattern.
# To transform a string of newline-separated items to an array, use mapfile -t: # To transform a string of newline-separated items to an array, use kube::util::read-array:
# mapfile -t FOO <<< "$(kube::golang::dups a b c a)" # kube::util::read-array FOO < <(kube::golang::dups a b c a)
# #
# ALWAYS remember to quote your subshells. Not doing so will break in # ALWAYS remember to quote your subshells. Not doing so will break in
# bash 4.3, and potentially cause other issues. # bash 4.3, and potentially cause other issues.
@ -172,33 +172,33 @@ kube::golang::setup_platforms() {
# Deduplicate to ensure the intersection trick with kube::golang::dups # Deduplicate to ensure the intersection trick with kube::golang::dups
# is not defeated by duplicates in user input. # is not defeated by duplicates in user input.
mapfile -t platforms <<< "$(kube::golang::dedup "${platforms[@]}")" kube::util::read-array platforms < <(kube::golang::dedup "${platforms[@]}")
# Use kube::golang::dups to restrict the builds to the platforms in # Use kube::golang::dups to restrict the builds to the platforms in
# KUBE_SUPPORTED_*_PLATFORMS. Items should only appear at most once in each # KUBE_SUPPORTED_*_PLATFORMS. Items should only appear at most once in each
# set, so if they appear twice after the merge they are in the intersection. # set, so if they appear twice after the merge they are in the intersection.
mapfile -t KUBE_SERVER_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_SERVER_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}" \
)" )
readonly KUBE_SERVER_PLATFORMS readonly KUBE_SERVER_PLATFORMS
mapfile -t KUBE_NODE_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_NODE_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_NODE_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_NODE_PLATFORMS[@]}" \
)" )
readonly KUBE_NODE_PLATFORMS readonly KUBE_NODE_PLATFORMS
mapfile -t KUBE_TEST_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_TEST_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_TEST_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_TEST_PLATFORMS[@]}" \
)" )
readonly KUBE_TEST_PLATFORMS readonly KUBE_TEST_PLATFORMS
mapfile -t KUBE_CLIENT_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_CLIENT_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}" \
)" )
readonly KUBE_CLIENT_PLATFORMS readonly KUBE_CLIENT_PLATFORMS
elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then

View File

@ -817,6 +817,23 @@ function kube::util::require-jq {
fi fi
} }
# kube::util::read-array
# Reads in stdin and adds it line by line to the array provided. This can be
# used instead of "mapfile -t", and is bash 3 compatible.
#
# Assumed vars:
# $1 (name of array to create/modify)
#
# Example usage:
# kube::util::read-array files < <(ls -1)
#
function kube::util::read-array {
local i=0
unset -v "$1"
while IFS= read -r "$1[i++]"; do :; done
eval "[[ \${$1[--i]} ]]" || unset "$1[i]" # ensures last element isn't empty
}
# Some useful colors. # Some useful colors.
if [[ -z "${color_start-}" ]]; then if [[ -z "${color_start-}" ]]; then
declare -r color_start="\033[" declare -r color_start="\033["