-
Notifications
You must be signed in to change notification settings - Fork 125
/
opadep.sh
executable file
·156 lines (128 loc) · 3.47 KB
/
opadep.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# This script is used for generating opa files and packages dependency graphs
# It is meant to be called from any directory containing some .opx/ directories
# it also looks for dot files in any found opx directory (MLSTATELIBS + current directory)
# and call odeplink for adding hyper links.
# it generates a directory _opadep/ in the current directory.
OPADEP=_opadep
# subdirectory of packages
# <!> Keep synchronized with compiler/installDir
OPA_PACKAGES='lib/opa/stdlib'
help() {
cat <<EOF
opadep: generate OPA packages dependency graphs.
Usage: opadep [options]
Packages are expected to be found in the following folders :
. all packages previously compiled in the current path
MLSTATELIBS/$OPA_PACKAGES all installed packages
it generates a folder $OPADEP/ containing the resulting graphs.
Options:
--help|-h|help displays this help
-o <directory> specify a custom directory instead of $OPADEP
-I <directory> add directory to include packages
-n do not compute dependencies, assume that the index was already generated
-d add some log for debug
EOF
}
COMPUTE=true
DEBUG=false
INCLUDES=''
OPAINCLUDES=''
while [ "$#" -gt 0 ]; do
case "$1" in
# h
-h|--help|help)
help
exit 0
;;
-d)
DEBUG=true
;;
-o)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
OPADEP="$1"
;;
-I)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
INCLUDES="$INCLUDES $1"
OPAINCLUDES="$OPAINCLUDES -I $1"
;;
-n)
COMPUTE=false
;;
*)
echo "[!] error: unknown option $1"
help
exit 1
esac
shift
done
if [ "$COMPUTE" = true ] ; then
tmp=$(mktemp /tmp/fileXXXXX)
rm $tmp
all="$tmp".opa
cat > $all <<EOF
import *
EOF
echo "odep: Global Dependencies Graph"
opa --verbose-build $OPAINCLUDES --odep $all
fi
echo "creating directory $OPADEP"
mkdir -p $OPADEP
cp *.dot $OPADEP/.
echo "odep: Get Subgraphs From Packages"
ALLOPX=''
LOCATIONS="$MLSTATELIBS/$OPA_PACKAGES . $INCLUDES"
for loc in $LOCATIONS ; do
if [ "$DEBUG" = true ] ; then
echo "checking for opx in loc: $loc"
fi
opx=$(find $loc -maxdepth 1 -name '*.opx')
if [ "$DEBUG" = true ] ; then
echo "finding: $opx"
fi
ALLOPX="$ALLOPX $opx"
done
for opx in $ALLOPX ; do
if [ "$DEBUG" = true ] ; then
echo "checking for dot in $opx"
ls $opx/*.dot
else
ls $opx/*.dot 1> /dev/null 2> /dev/null
fi
code=$?
if [ "$code" = 0 ] ; then
if [ "$DEBUG" = true ] ; then
cp -v $opx/*.dot $OPADEP/.
else
cp $opx/*.dot $OPADEP/.
fi
fi
done
cd $OPADEP
ROOT=$(pwd)
echo "opadep: Transitive Reduction"
mkdir -p full
mkdir -p tred
for dot in *.dot ; do
# transitive reduction
tred $dot > tred/$dot 2> /dev/null
mv $dot full/$dot
done
echo "opadep: DOT to SVG (+odeplink)"
cd full
for dot in *.dot ; do
base=$(basename $dot .dot)
dot -Tsvg $dot > $base.svg
done
odeplink *.svg
cd $ROOT
cd tred
for dot in *.dot ; do
base=$(basename $dot .dot)
dot -Tsvg $dot > $base.svg
done
odeplink *.svg
echo "opadep: Successful generation of graphs in $OPADEP/"