Skip to content

Commit 3b120f4

Browse files
author
linkrope
committed
documentation
1 parent c9292ac commit 3b120f4

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# depend
21
Dependency Tool for D
2+
=====================
3+
4+
This tool checks actual import dependencies against a UML model of target dependencies.
5+
6+
Usage
7+
-----
8+
9+
Run [dmd](http://dlang.org/dmd-linux.html) with the switch `--deps`
10+
to extract the actual dependencies. For example:
11+
12+
dmd -deps=dependencies -c src/depend.d -of/dev/null
13+
14+
Use the _depend_ tool together with the [Graphviz](http://www.graphviz.org) programs
15+
for a visualization of the module dependencies:
16+
17+
src/depend.d --dot dependencies | dot -Tsvg -odependencies.svg
18+
19+
For best results, remove the transitive dependencies:
20+
21+
src/depend.d --dot dependencies | tred | dot -Tsvg -odependencies.svg
22+
23+
Consider switching to package dependencies instead of module dependencies:
24+
25+
src/depend.d --packages --dot dependencies | tred | dot -Tsvg -odependencies.svg
26+
27+
Or filter dependencies of source files matching a regular expression:
28+
29+
src/depend.d --filter 'src|test' --dot dependencies | tred | dot -Tsvg -odependencies.svg
30+
31+
Then, specify the target dependencies as a [PlantUML](http://plantuml.sourceforge.net) model.
32+
For example, create a text file _model.uml_:
33+
34+
package model {}
35+
package view {}
36+
package controller {}
37+
38+
controller ..> view
39+
controller ..> model
40+
view .> model
41+
42+
Finally, use the _depend_ tool for checking actual dependencies against the target dependencies:
43+
44+
src/depend.d --target model.uml dependencies
45+
46+
The tool complains about violations:
47+
48+
error: unintended dependency model -> controller

src/depend.d

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ import std.regex;
66
import std.stdio;
77
import std.typecons;
88

9+
const USAGE = `Usage: %s [options] FILE
10+
Process import dependencies as created by dmd with the --deps switch.
11+
Options:
12+
--dot Print the dependency graph in the DOT language
13+
-f, --filter REGEX Filter source files matching the regular expression
14+
-h, --help Display usage information, then exit
15+
-p, --packages Generalize to package dependencies
16+
-t, --target FILE Check against the PlantUML target dependencies`;
17+
918
alias Dependency = Tuple!(string, "client", string, "supplier");
1019

1120
int main(string[] args)
1221
{
1322
import std.getopt : getopt;
1423

1524
bool dot = false;
25+
bool help = false;
1626
bool packages = false;
1727
string filter;
1828
string target;
@@ -31,6 +41,14 @@ int main(string[] args)
3141
return 1;
3242
}
3343

44+
if (help)
45+
{
46+
import std.path : baseName;
47+
48+
writefln(USAGE, args[0].baseName);
49+
return 0;
50+
}
51+
3452
File file = (args.length > 1) ? File(args[1]) : stdin;
3553
auto pattern = regex(filter);
3654
Dependency[] actualDependencies = moduleDependencies(file, pattern);
@@ -144,7 +162,7 @@ void write(in Dependency[] dependencies)
144162
writeln("digraph Dependencies {");
145163
writeln("node [shape=box];");
146164
foreach (element; dependencies.elements)
147-
writeln('"', element,'"');
165+
writeln('"', element, '"');
148166
foreach (dependency; dependencies)
149167
writeln('"', dependency.client, '"', " -> ", '"', dependency.supplier, '"');
150168
writeln("}");

0 commit comments

Comments
 (0)