-
Notifications
You must be signed in to change notification settings - Fork 10
/
depgraph.sh
executable file
·66 lines (61 loc) · 2.57 KB
/
depgraph.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
#!/usr/bin/env bash
# Adapt to macOS (brew install gsed)
SED=`which gsed 2>/dev/null || which sed`
fn_project=_CoqProject
fn_out="dependencies"
base_style="rounded,filled"
# Some categorical color schemes recognised by dot: pastel19, set312
# http://www.graphviz.org/doc/info/colors.html#brewer
color_scheme=pastel19
n_colors_max=9
function help_msg() {
echo "`basename $0`: Print dependency graph for \"$fn_project\" according to coqdep."
echo "Requires graphviz, coqdep, bash, and sed."
}
if ! [ -z $@ ] ; then
help_msg ; exit 1
fi
( echo "digraph interval_deps {" ;
echo 'node [shape=box, style="'$base_style'", URL="html/\N.html", colorscheme='$color_scheme'];';
coqdep -vos -dyndep var -f $fn_project |
# rewrite prefixes
$SED -f <(sed -nr 's/^ *-Q +(\S+) +(\S+)/s,\1,\2,g/p' < _CoqProject) |
# turn '/' into '.' ,
$SED -n -e 's,/,.,g' \
`# keep lines with [src].vo : [x].v [dst]* , drop [x].v` \
-e 's/[.]vo.*: [^ ]*[.]v//p' |
{
declare -A colmap
while read src dst; do
# pick a color number based on the src node name
prefix=$(echo "$src" | $SED -e '/^[^\.]*$/s/.*/__/' -e '/\./s/\..*//')
color=${colmap[$prefix]}
if [ -z "$color" ] ; then
color=$(( ${#colmap[*]} + 1))
color=$(( color < n_colors_max ? color : n_colors_max ))
colmap[$prefix]=$color
fi
# color=$(echo "$src" | $SED -r \
# -e 's,Crypt[.]examples.*,2,' \
# -e 's,Crypt[.]package[.].*,3,' \
# -e 's,Crypt[.]rhl_semantics[.].*,4,' \
# -e 's,Crypt[.]rules.*,5,' \
# -e 's,Mon[.].*,6,' \
# -e 's,Relational[.].*,7,' \
# -e 's,.*\..*,1,') # default
echo "\"$src\" [fillcolor=$color];"
for d in $dst; do
echo "\"$src\" -> \"${d%.vo*}\" ;"
done
done;
}
echo "}" ) |
# transitively reduce graph
tred |
# double border around modules without further prerequisites
gvpr -c 'N[outdegree == 0]{shape="doubleoctagon"}' |
# fat border around modules without clients
gvpr -c 'N[indegree == 0]{penwidth=3}' > $fn_out.dot
dot -T svg $fn_out.dot > $fn_out.svg
# dot -T png $fn_out.dot > $fn_out.png
# dot -T cmap $fn_out.dot | $SED -e 's,>$,/>,' > $fn_out.map