2
2
3
3
### What is this?
4
4
5
- This is a wrapper script that simplifies usage of ` cinclude2dot ` .
5
+ This folder has scripts for C/C++ dependency graphing .
6
6
7
- Credit for ` cinclude2dot ` belongs to https://www.flourish.org/cinclude2dot/
7
+ These scripts use the [ Graphviz] ( https://graphviz.org/ ) ` dot ` tool to produce an
8
+ SVG image visualizing the header-include graph of a C/C++ codebase.
9
+
10
+ You can apply these scripts to your entire C/C++ codebase, or you can visualize
11
+ any subset of your code, bounding the input to specific subdirectories of your
12
+ codebase.
13
+
14
+ Original inspiration taken from https://www.flourish.org/cinclude2dot/ , but here
15
+ we use a novel implementation in python, with different cli options and slightly
16
+ different output (though the output of both is in the ` dot ` graphviz language).
8
17
9
18
You can copy this ` sw_arch_doc ` folder into any project (or just copy it
10
- somewhere on your system) and run the script against any folder of C/C++ source
11
- files you like.
19
+ somewhere on your system) and run the script against any folder or set of
20
+ folders of C/C++ source files you like.
12
21
13
- When choosing which folder of source files to diagram, we recommend not
22
+ When choosing which folder(s) of source files to diagram, we recommend not
14
23
attempting to diagram more than ~ 100 files at a time, or the diagram will be
15
24
very dense and hard to read.
16
25
@@ -24,13 +33,18 @@ apply added styling to your graph(s).
24
33
** TL;DR**
25
34
26
35
```
27
- generate_graph.sh ${PATH_TO_SOURCES } ${PATH_TO_HEADERS }
36
+ ./ generate_graph.sh -s ${SOURCE_PATH_1 } ${SOURCE_PATH_2} -x ${TEXT_FILE_WITH_YOUR_EXCLUDES }
28
37
```
29
38
30
39
The generated diagram will be: ` all_src.svg `
31
40
32
41
** Required:** ` dot ` (from the graphviz package) must be installed on your sytem.
33
42
43
+ For detailed help, run:
44
+ ```
45
+ ./generate_graph.sh --help
46
+ ```
47
+
34
48
If you prefer to alter the appearance of the graph by using different (or
35
49
additional) graph attributes, edit the file ` dot_head.part ` with the
36
50
[ graphviz attributes] ( https://graphviz.org/doc/info/attrs.html ) that you
@@ -45,22 +59,22 @@ your preferred graph attributes.
45
59
#### Exclusions
46
60
47
61
Many projects have header files such as ` defs.h ` or ` utils.h ` , and it is usually
48
- desireable to exclude these headers from the generated diagram.
62
+ desirable to exclude these headers from the generated diagram.
49
63
50
- That is the goal of the lines near the bottom of ` generate_graph.sh ` that look as follows:
64
+ For any/all header(s) you wish to ignore and exclude from the visualization,
65
+ list the * stem* of the header name in a file such as ` excludes.txt ` , listing one
66
+ * stem* name per line. Pass your ` excludes.txt ` to the script like so:
51
67
52
68
```
53
- "${THESED}" -i "/\"\bcli_options\b\"/d" ${ARCH_DOC_DIR}/all_src.dot
54
- "${THESED}" -i "/\"\blogging_tags\b\"/d" ${ARCH_DOC_DIR}/all_src.dot
55
- "${THESED}" -i "/\"\bresource_helper\b\"/d" ${ARCH_DOC_DIR}/all_src.dot
69
+ ./generate_graph.sh -s ${SOURCE_PATH_1} ${SOURCE_PATH_2} -x excludes.txt
56
70
```
57
71
58
- Add more lines as needed for your project .
72
+ See the example ` excludes.txt ` in this folder .
59
73
60
74
For example, to remove ` defs.h ` from the diagram, you would add the following line:
61
75
62
76
```
63
- "${THESED}" -i "/\"\bdefs\b\"/d" ${ARCH_DOC_DIR}/all_src.dot
77
+ defs
64
78
```
65
79
66
80
### My diagram looks like a tangle of spaghetti. Now what?
@@ -69,9 +83,9 @@ There are several reasons that can cause you to end up with spaghetti.
69
83
70
84
First, we recommend not attempting to diagram more than ~ 100 files at a
71
85
time. This means you should make sure that the number of C/C++ source files
72
- residing under whatever directory you chose as the ` ${PATH_TO_SOURCES} ` argument
73
- does not exceed 100 total source files. When counting files under
74
- ` ${PATH_TO_SOURCES} ` , any files in nested subdirectories count, too!
86
+ residing under whatever directory or directories you chose as the ` -s ` (or
87
+ long-name ` --src-dir ` ) argument does not exceed 100 total source files. When
88
+ counting files under ` --src-dir ` , any files in nested subdirectories count, too!
75
89
76
90
Second, please recall the advice above regarding explicit exclusions for common
77
91
files such as ` defs.h ` . If your generated diagram is large, you can usually spot
@@ -91,6 +105,6 @@ such as [deheader](http://www.catb.org/~esr/deheader/). After you identify and
91
105
remove spurious ` #include ` lines from your sources, then re-run
92
106
` generate_graph.sh ` and you should see a smaller diagram.
93
107
94
- You might find that generating the diagram periodically (during CI , even!) gives
95
- you a good way to notice spurious ` #include ` edges and stay on top of your
108
+ You might find that generating the diagram regularly (during every build , even!)
109
+ gives you a good way to notice spurious ` #include ` edges and stay on top of your
96
110
header hygiene.
0 commit comments