-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdependency_graph.sh
More file actions
executable file
·66 lines (56 loc) · 1.73 KB
/
dependency_graph.sh
File metadata and controls
executable file
·66 lines (56 loc) · 1.73 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
#!/bin/bash
module_graph=0
gcc_options=""
while true; do
case $1 in
-h|-\?|--help)
echo "-m,--modules : treat each root files or directory as a single node"
echo "-i,--include : additionnal include directory"
exit
;;
-m|--modules)
module_graph=1
;;
-i|--include)
gcc_options+=" -I$2"
shift
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
files="$@"
node_from_path(){
if [[ $module_graph == 0 ]]; then
echo \"$(realpath --relative-to=. $1 | sed "s/\.[hc]$//;s/\.cpp$//")\"
else
echo \"$(realpath --relative-to=. $1 | sed "s/\.[hc]$//;s/\.cpp$//;s,/[^/]*$,,")\"
fi
}
echo "strict digraph dependency_graph {"
for file in $files; do
node=$(node_from_path $file)
[[ $node =~ ".test" ]] && echo "${node} [shape=box]"
(for include_path in `g++ $file -std=c++17 -fconcepts -I. -E -H $gcc_options 2>&1 >/dev/null |grep "^\. [^/]"|sed "s/^\. //"`; do dependancy=$(node_from_path $include_path); [[ $dependancy != $node ]] && echo $dependancy; done)|sed "s@.*@${node} -> \0@"
done
if [[ $module_graph == 0 ]]; then
groups=$((for file in $files; do node_from_path $(dirname $file); done)|sort|uniq)
for group in $groups; do
subgraph=$(echo $group | sed "s,^\"\(.*\)\"$,cluster_\1,;s,/,_,g;s,\.,root,")
echo "subgraph ${subgraph} {"
for file in $files; do
node=$(node_from_path $file)
[[ $(node_from_path $(dirname $file)) == $group ]] && echo "${node}"
done
echo "}"
done
fi
echo "}"