blob: 5a9986274f3cba012d0fad46f928644312f8c0f1 [file] [log] [blame] [view]
Googler018c5692022-07-14 12:52:58 -07001Project: /_project.yaml
2Book: /_book.yaml
3
4# Review the dependency graph
5
Googler3b9ed6e2022-11-08 02:19:42 -08006{% include "_buttons.html" %}
7
Googler018c5692022-07-14 12:52:58 -07008A successful build has all of its dependencies explicitly stated in the `BUILD`
9file. Bazel uses those statements to create the project's dependency graph,
10which enables accurate incremental builds.
11
12To visualize the sample project's dependencies, you can generate a text
13representation of the dependency graph by running this command at the
14workspace root:
15
16```
17bazel query --notool_deps --noimplicit_deps "deps(//main:hello-world)" \
18 --output graph
19```
20
21The above command tells Bazel to look for all dependencies for the target
22`//main:hello-world` (excluding host and implicit dependencies) and format the
23output as a graph.
24
25Then, paste the text into [GraphViz](http://www.webgraphviz.com/).
26
27On Ubuntu, you can view the graph locally by installing GraphViz and the xdot
28Dot Viewer:
29
30```
31sudo apt update && sudo apt install graphviz xdot
32```
33
34Then you can generate and view the graph by piping the text output above
35straight to xdot:
36
37```
38xdot <(bazel query --notool_deps --noimplicit_deps "deps(//main:hello-world)" \
39 --output graph)
40```
41
42As you can see, the first stage of the sample project has a single target
43that builds a single source file with no additional dependencies:
44
45![Dependency graph for 'hello-world'](/docs/images/cpp-tutorial-stage1.png "Dependency graph")
46
47**Figure 1.** Dependency graph for `hello-world` displays a single target with a single
48source file.
49
50After you set up your workspace, build your project, and examine its
51dependencies, then you can add some complexity.