summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-04-29 17:57:46 (GMT)
committerEvan Martin <martine@danga.com>2011-04-29 17:57:46 (GMT)
commit58744a4227fc19ad08f3981992d8a8ecc8b2ed75 (patch)
tree02438216bb0354be5015d0da4bd714f40921ea88
parentc3c9b66a4261c7b329e07aef6f79ec1364900c2c (diff)
parent535f830f7fae73ea293800045561551c01dec589 (diff)
downloadNinja-58744a4227fc19ad08f3981992d8a8ecc8b2ed75.zip
Ninja-58744a4227fc19ad08f3981992d8a8ecc8b2ed75.tar.gz
Ninja-58744a4227fc19ad08f3981992d8a8ecc8b2ed75.tar.bz2
Merged pull request #31 from polrop/generate-whole-graph.
The 'graph' tool now generates a graph based on all root nodes when called without any target. The build.ninja file is also adjusted so that we get the whole graph generated (including the doxygen part).
-rw-r--r--build.ninja2
-rw-r--r--manual.asciidoc3
-rw-r--r--src/ninja.cc26
3 files changed, 23 insertions, 8 deletions
diff --git a/build.ninja b/build.ninja
index be21296..128ef67 100644
--- a/build.ninja
+++ b/build.ninja
@@ -74,7 +74,7 @@ build ninja_test: link $builddir/build_test.o $builddir/build_log_test.o \
# Generate a graph using the -g flag.
rule gendot
- command = ./ninja -t graph all > $out
+ command = ./ninja -t graph > $out
rule gengraph
command = dot -Tpng $in > $out
diff --git a/manual.asciidoc b/manual.asciidoc
index 7ea3da8..cf7b2c8 100644
--- a/manual.asciidoc
+++ b/manual.asciidoc
@@ -311,7 +311,8 @@ feature requires a Python installation.
`graph`:: output a file in the syntax used by `graphviz`, a automatic
graph layout tool. Use it like: +ninja -t graph _target_ | dot -Tpng
-ograph.png /dev/stdin+ . In the Ninja source tree, `ninja graph`
-generates an image for Ninja itself.
+generates an image for Ninja itself. If no target is given generate a
+graph for all root targets.
`targets`:: output a list of targets either by rule or by depth. If used
like this +ninja -t targets rule _name_+ it prints the list of targets
diff --git a/src/ninja.cc b/src/ninja.cc
index 5a0c00d..c4f78ab 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -106,14 +106,28 @@ int CmdGraph(State* state, int argc, char* argv[]) {
int status = 0;
GraphViz graph;
graph.Start();
- for (int i = 0; i < argc; ++i) {
- Node* node = state->LookupNode(argv[i]);
- if (node)
- graph.AddTarget(node);
- else {
- Error("unknown target '%s'", argv[i]);
+ if (argc == 0) {
+ string err;
+ vector<Node*> root_nodes = state->RootNodes(&err);
+ if (err.empty()) {
+ for (vector<Node*>::const_iterator n = root_nodes.begin();
+ n != root_nodes.end();
+ ++n)
+ graph.AddTarget(*n);
+ } else {
+ Error("%s", err.c_str());
status = 1;
}
+ } else {
+ for (int i = 0; i < argc; ++i) {
+ Node* node = state->LookupNode(argv[i]);
+ if (node)
+ graph.AddTarget(node);
+ else {
+ Error("unknown target '%s'", argv[i]);
+ status = 1;
+ }
+ }
}
graph.Finish();
return status;