-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreq-expand-recursive.sh
More file actions
76 lines (66 loc) · 1.41 KB
/
req-expand-recursive.sh
File metadata and controls
76 lines (66 loc) · 1.41 KB
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
76
#!/usr/bin/env bash
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 a
declare -A q
declare -A e
declare -A m
readarray -t a < <(${cwtop}/bin/crosware list-recipe-reqs)
function uniqueify() {
echo "${@}" | tr ' ' '\n' | sort -u | xargs echo
}
for i in ${!a[@]} ; do
l="${a[${i}]}"
r="${l// /}"
r="${r%%:*}"
d="${l##${r} : }"
d="$(uniqueify ${d})"
q["${r}"]="${d}"
e["${r}"]="${d}"
m["${r}"]=0
done
function reqcount() {
echo ${#}
}
function expandreqs() {
local r="${1}"
if [ "${m[${r}]}" -eq 1 ] ; then
return
fi
if [ $(reqcount ${q[${r}]}) -eq 0 ] ; then
m["${r}"]=1
return
fi
local o="${2}"
local n
for d in ${e[${r}]} ; do
if [ ${m[${d}]} -ne 1 ] ; then
if [ $(reqcount ${q[${d}]}) -ge 1 ] ; then
expandreqs "${d}" "$(reqcount ${q[${d}]})"
fi
fi
m["${d}"]=1
done
for d in ${e[${r}]} ; do
e["${r}"]+=" ${e[${d}]}"
done
e["${r}"]="$(uniqueify ${e[${r}]})"
n="$(reqcount ${e[${r}]})"
if [[ ${o} != ${n} ]] ; then
expandreqs "${r}" "${n}"
fi
m["${r}"]=1
}
for r in $(echo ${!q[@]} | tr ' ' '\n' | sort) ; do
c="$(reqcount ${q[${r}]})"
echo -n "${r} : ${c} : ${q[${r}]} : "
expandreqs "${r}" "${c}"
n="$(reqcount ${e[${r}]})"
echo "${n} : ${e[${r}]}"
done