Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #12229: cpp-graph

File cpp-graph, 5.7 KB (added by rleigh, 10 years ago)

Generate dependency graphs from OmeroCpp sources

Line 
1#!/bin/sh
2
3set -e
4
5merge=1
6
7file="$1"
8if [ -z "$file" ]; then
9  file="deps"
10fi
11
12dot="${file}.dot"
13svg="${file}.svg"
14
15norm()
16{
17    echo $1 | tr / _
18}
19
20colour()
21{
22    case $1 in
23        Ice) col=lightblue;;
24        IceUtil) col=blue;;
25        Glacier2) col=navy;;
26        stdlib) col=green;;
27        omero) col=red;;
28        omero/model) col=yellowgreen;;
29        omero/api) col=plum;;
30        omero/cmd) col=orange;;
31        omero/util) col=turquoise;;
32        *) col=black;;
33    esac
34    echo $col
35}
36
37group()
38{
39    unit=$1
40    case "${1%/*}" in
41        omero/api|omero/cmd|omero/model|omero/util|Ice|IceUtil|Glacier2)
42            unit="${unit%/*}";;
43        typeinfo|map|stdexcept|iosfwd|sstream|ostream|iostream|exception|vector|algorithm|string)
44            unit="stdlib";;
45       
46    esac
47    echo "$unit"
48}
49
50cat <<EOF > "$dot"
51strict digraph G {
52  graph [compound=true];
53EOF
54
55if [ "$merge" = "1" ]; then
56    cat <<EOF >> "$dot"
57  $(norm Ice) [label="Ice",color=$(colour Ice)];
58  $(norm IceUtil) [label="IceUtil",color=$(colour IceUtil)];
59  $(norm Glacier2) [label="Glacier2",color=$(colour Glacier2)];
60  $(norm stdlib) [label="stdlib",color=$(colour stdlib)];
61EOF
62else
63    cat <<EOF >> "$dot"
64  subgraph cluster_$(norm Ice) {
65    label = "Ice";
66    style = solid;
67    node [shape=box,color=lightblue];
68
69    $(norm Ice/BasicStream) [label="BasicStream"];
70    $(norm Ice/BuiltinSequences) [label="BuiltinSequences"];
71    $(norm Ice/Current) [label="Current"];
72    $(norm Ice/Direct) [label="Direct"];
73    $(norm Ice/Exception) [label="Exception"];
74    $(norm Ice/FactoryTableInit) [label="FactoryTableInit"];
75    $(norm Ice/IncomingAsync) [label="IncomingAsync"];
76    $(norm Ice/Incoming) [label="Incoming"];
77    $(norm Ice/LocalException) [label="LocalException"];
78    $(norm Ice/LocalObject) [label="LocalObject"];
79    $(norm Ice/ObjectFactory) [label="ObjectFactory"];
80    $(norm Ice/ObjectF) [label="ObjectF"];
81    $(norm Ice/Object) [label="Object"];
82    $(norm Ice/OutgoingAsync) [label="OutgoingAsync"];
83    $(norm Ice/Outgoing) [label="Outgoing"];
84    $(norm Ice/ProxyF) [label="ProxyF"];
85    $(norm Ice/Proxy) [label="Proxy"];
86    $(norm Ice/SlicedDataF) [label="SlicedDataF"];
87    $(norm Ice/SlicedData) [label="SlicedData"];
88    $(norm Ice/StreamF) [label="StreamF"];
89    $(norm Ice/StreamHelpers) [label="StreamHelpers"];
90    $(norm Ice/UndefSysMacros) [label="UndefSysMacros"];
91  }
92  subgraph cluster_$(norm IceUtil) {
93    label ="IceUtil";
94    style = solid;
95    node [shape=box,color=lightblue];
96
97    $(norm IceUtil/Config) [label="Config"];
98    $(norm IceUtil/Iterator) [label="Iterator"];
99    $(norm IceUtil/Optional) [label="Optional"];
100    $(norm IceUtil/ScopedArray) [label="ScopedArray"];
101  }
102  subgraph cluster_$(norm Glacier2) {
103    label ="Glacier2";
104    style = solid;
105    node [shape=box,color=lightblue];
106
107    $(norm Glacier2/Session) [label="Session"];
108  }
109  subgraph cluster_$(norm stdlib) {
110    label = "stdlib";
111    style = solid;
112    node [shape=box,color=$(colour stdlib)];
113
114    $(norm typeinfo) [label="typeinfo"];
115    $(norm map) [label="map"];
116    $(norm stdexcept) [label="stdexcept"];
117    $(norm iosfwd) [label="iosfwd"];
118    $(norm sstream) [label="sstream"];
119    $(norm ostream) [label="ostream"];
120    $(norm iostream) [label="iostream"];
121    $(norm exception) [label="exception"];
122    $(norm vector) [label="vector"];
123    $(norm algorithm) [label="algorithm"];
124    $(norm string) [label="string"];
125  }
126EOF
127fi
128
129for component in omero omero/model omero/cmd omero/api omero/util; do
130    echo "Processing component: $component"
131
132    if [ "$component" != "omero" -a "$merge" = "1" ]; then
133        cat <<EOF >> "$dot"
134  $(norm $component) [label="$component",color=$(colour $component)];
135EOF
136    else
137        cat <<EOF >> "$dot"
138  subgraph cluster_$(norm $component) {
139    label ="$component";
140    style = solid;
141    colour = $(colour $component);
142    node [shape=box,color=$(colour $component)];
143
144EOF
145
146        sources=$( (find "$component" -maxdepth 1 -name "*.h"; find "$component" -maxdepth 1 -name "*.cpp") | sort)
147        units=$(echo "$sources" | sed -e "s;\.h\$;;" -e "s;\.cpp\$;;" | uniq)
148        echo "$units"
149
150        for unit in $units; do
151            echo "  Processing unit: $unit"
152            name=${unit#*/}
153            name=${name#*/}
154            cat <<EOF >> "$dot"
155    $(norm $unit) [label="$name"];
156EOF
157        done
158        if [ component != "omero" ]; then
159            cat <<EOF >> "$dot"
160  }
161EOF
162        fi
163    fi
164done
165
166# Process deps
167for component in omero omero/model omero/cmd omero/api omero/util; do
168    sources=$( (find "$component" -maxdepth 1 -name "*.h"; find "$component" -maxdepth 1 -name "*.cpp") | sort)
169
170    for source in $sources; do
171        echo -n "  Processing source: $source"
172        unit=$(echo "$source" | sed -e "s;\.h\$;;" -e "s;\.cpp\$;;")
173        name=${unit#*/}
174        name=${name#*/}
175        deps=$(grep "#include" "$source" | sed -e "s;#include.*<\(.*\)>.*;\1;")
176        for dep in $deps; do
177            dep=$(echo "$dep" | sed -e "s;\.h\$;;" -e "s;\.cpp\$;;")
178            echo -n "."
179            # Drop self-references
180            if [ "$(norm $unit)" = "$(norm $dep)" ]; then continue; fi
181            # Don't generate inter-module deps except for the omero component
182#            if [ "${unit%/*}" != "$component" -o "$component" = "omero" ]; then
183                if [ "$merge" = "1" ]; then
184                    unit=$(group "$unit")
185                    dep=$(group "$dep")
186                fi
187                cat <<EOF >> "$dot"
188      $(norm $unit) -> $(norm $dep) [color=$(colour $dep)];
189EOF
190#            fi
191        done
192        echo "done."
193    done
194done
195
196cat <<EOF >> "$dot"
197}
198EOF
199
200ccomps -Cx "$dot" | dot | gvpack -array_1 | neato -n2 -Tsvg > "$svg"
201egrep -v -- "->.*(Ice|Glacier|stdlib)" "$dot" | ccomps -C | dot | gvpack -array_1 | neato -n2 -Tsvg > "noice-$svg"

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.38162 sec.)

We're Hiring!