-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreq-expand-recursive-slow.sh
75 lines (64 loc) · 1.33 KB
/
req-expand-recursive-slow.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
#
# XXX - memoization, slow
#
set -eu
set -o pipefail
if [ ! -e /usr/local/crosware/etc/vars ] ; then
echo "$(basename ${0}): this does not appear to be crosware"
exit 1
fi
. /usr/local/crosware/etc/vars
. ${cwtop}/etc/functions
declare -A q
declare -A e
declare -A x
#f="${cwtop}/tmp/reqs.out"
#readarray -t a < ${f}
readarray -t a < <(crosware list-recipe-reqs)
function uniqueify() {
echo "${@}" | tr ' ' '\n' | sort -u | xargs echo -n
}
for i in ${!a[@]} ; do
l="${a[${i}]}"
r="${a[${i}]}"
r="${r// /}"
r="${r%%:*}"
d="${l##${r} : }"
d="$(uniqueify ${d})"
q["${r}"]="${d}"
done
function reqcount() {
local r="${1}"
local c=0
local d="$(uniqueify ${q[${r}]})"
local i
d="${d# }"
d="${d% }"
for i in ${d} ; do
((c++))
done
echo "${c}"
}
function expandreqs() {
local r="${1}"
local o="${2}"
local n
for d in ${q[${r}]} ; do
q["${r}"]="$(uniqueify ${q[${r}]} ${q[${d}]})"
done
n="$(reqcount ${r})"
if [[ $o != $n ]] ; then
expandreqs "${r}" "${n}"
fi
}
#for r in $(echo ${!q[@]} | tr ' ' '\n' | sort) ; do
# echo "${r} : $(reqcount ${r}) : '${q[${r}]}'"
#done
for r in $(echo ${!q[@]} | tr ' ' '\n' | sort) ; do
c="$(reqcount ${r})"
echo -n "${r} : ${c} : ${q[${r}]} : "
expandreqs "${r}" "${c}"
n="$(reqcount ${r})"
echo "${n} : ${q[${r}]}"
done