Skip to content

Commit

Permalink
Build scripts: Replace mapfile with read loop for old bash versions (#…
Browse files Browse the repository at this point in the history
…1425)

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
jmacd and MrAlias authored Dec 29, 2020
1 parent 2def8c3 commit 045c3ff
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions get_main_pkgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ fi

p=$(pwd)
mod_dirs=()
mapfile -t mod_dirs < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort)

# Note `mapfile` does not exist in older bash versions:
# https://stackoverflow.com/questions/41475261/need-alternative-to-readarray-mapfile-for-script-on-older-version-of-bash

while IFS= read -r line; do
mod_dirs+=("$line")
done < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort)

for mod_dir in "${mod_dirs[@]}"; do
cd "${mod_dir}"
main_dirs=()
mapfile -t main_dirs < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|')
for main_dir in "${main_dirs[@]}"; do
echo ".${main_dir#${p}}"
done

while IFS= read -r line; do
echo ".${line#${p}}"
done < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|')
cd "${p}"
done

0 comments on commit 045c3ff

Please sign in to comment.