Skip to content

Commit 337d796

Browse files
committed
[srock] Add list_srock.sh
Provides a list similar to aomp/clone_aomp.sh list Usage: srock-list [OPTION] -q quick (exclude 'submodule status') -v verbose (include 'submodule status') -u show as unformatted CSV
1 parent d933098 commit 337d796

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

srock-bin/list_srock.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
#
3+
#Copyright © Advanced Micro Devices, Inc., or its affiliates.
4+
#
5+
#SPDX-License-Identifier: MIT
6+
#
7+
# list_srock.sh: List the version of TheRock and submodules
8+
#
9+
# --- Start standard header to set SROCK environment variables ----
10+
realpath=$(realpath "$0")
11+
thisdir=$(dirname "$realpath")
12+
. "$thisdir/srock_common_vars"
13+
# --- end standard header ----
14+
15+
cd "$SROCK_THEROCK_DIR" || exit
16+
17+
do_sub_status=0
18+
show_fmt=1
19+
show_unfmt=0
20+
while [ $# -gt 0 ]; do # check arguments
21+
case "$1" in
22+
-u)
23+
show_fmt=0
24+
show_unfmt=1
25+
;;
26+
-v)
27+
do_sub_status=1
28+
;;
29+
-q|-t)
30+
do_sub_status=0
31+
;;
32+
*)
33+
echo "Usage: srock-list [OPTION]" >& 2
34+
echo " -q quick (exclude 'submodule status')" >& 2
35+
echo " -v verbose (include 'submodule status')" >& 2
36+
echo " -u show as unformatted CSV" >& 2
37+
exit 1 ;;
38+
esac
39+
shift
40+
done
41+
declare -a tr_dtop
42+
declare -a tr_dsub
43+
# shellcheck disable=SC2116 # echo intended
44+
# shellcheck disable=SC2046 # word splitting in subcommands is acceptable
45+
tr_dtop=( "$(echo $(git branch --show-current)\|TheRock\|TheRock\|parent\|$(git log -1 --format="%H|%as|%cn|%an"))" )
46+
# shellcheck disable=SC2016 # single quotes intended
47+
# shellcheck disable=SC2207 # intended split on newline
48+
IFS=$'\n' tr_dsub=( $(git submodule -q foreach 'echo $(git branch --show-current)\|$sm_path\|$name\|$sha1\|$(git log -1 --format="%H|%as|%cn|%an")') )
49+
# shellcheck disable=SC2207 # intended split on newline
50+
declare -a tr_data
51+
tr_data=( "${tr_dtop[@]}" "${tr_dsub[@]}" )
52+
53+
declare -a tr_fields
54+
declare -a tr_unders
55+
tr_fields=("branch" "path" "repo name" "sub SHA" "head SHA" "updated" "commitor" "for author")
56+
tr_unders=("------" "----" "---------" "-------" "--------" "-------" "--------" "----------")
57+
if [[ $do_sub_status -ne 0 ]]; then
58+
tr_fields+=("sub SHA tag")
59+
tr_unders+=("-----------")
60+
fi
61+
declare -A tr_htags
62+
63+
# collect SHA tags from submodule status
64+
if [[ $do_sub_status -ne 0 ]]; then
65+
declare -a tr_stat
66+
# shellcheck disable=SC2207 # intended split on newline
67+
IFS=$'\n' tr_stat=( $(git submodule status) )
68+
for entry in "${tr_stat[@]}"; do
69+
IFS=" " read -r -a en_split <<< "$entry"
70+
sub_sha=${en_split[0]}
71+
sub_tag=${en_split[2]}
72+
# echo "$entry: $sub_sha -> $sub_tag"
73+
tr_htags[$sub_sha]=$sub_tag
74+
done
75+
fi
76+
77+
# formatted output
78+
if [[ $show_fmt -ne 0 ]]; then
79+
echo "TheRock submodules:"
80+
fmt="%-20.20s %-44.44s %-21.21s %-10.10s %-10.10s %-10.10s %-10.10s %-19.19s %s\n"
81+
# shellcheck disable=SC2059 # variable format intended
82+
printf "$fmt" "${tr_fields[@]}"
83+
# shellcheck disable=SC2059 # variable format intended
84+
printf "$fmt" "${tr_unders[@]}"
85+
for entry in "${tr_data[@]}"; do
86+
IFS='|' read -r -a en_split <<< "$entry"
87+
sub_sha=${en_split[3]}
88+
head_sha=${en_split[4]}
89+
if [ "$sub_sha" == "$head_sha" ]; then
90+
en_split[4]="same"
91+
fi
92+
tag=""
93+
if [[ -v tr_htags[$sub_sha] ]]; then
94+
tag=${tr_htags[$sub_sha]}
95+
fi
96+
# shellcheck disable=SC2059 # variable format intended
97+
printf "$fmt" "${en_split[@]}" "$tag"
98+
done
99+
fi
100+
101+
# unformatted output
102+
if [[ $show_unfmt -ne 0 ]]; then
103+
echo "TheRock submodules versions (unformatted):"
104+
fmt="%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n"
105+
# shellcheck disable=SC2059 # variable format intended
106+
printf "$fmt" "${tr_fields[@]}"
107+
for entry in "${tr_data[@]}"; do
108+
IFS='|' read -r -a en_split <<< "$entry"
109+
sub_sha=${en_split[3]}
110+
tag=${tr_htags[$sub_sha]}
111+
echo "$entry|$tag"
112+
done
113+
fi

0 commit comments

Comments
 (0)