summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-05-01 02:42:41 (GMT)
committerEvan Martin <martine@danga.com>2011-05-01 02:51:59 (GMT)
commite783554ff5297711ef4c28a01e0c7e0d59a808d5 (patch)
treea8cd0541bd1fd76b66616b29f65dc25bb55ca90d /src
parentb95343a7745c7b717d039fc532f857acd5796874 (diff)
downloadNinja-e783554ff5297711ef4c28a01e0c7e0d59a808d5.zip
Ninja-e783554ff5297711ef4c28a01e0c7e0d59a808d5.tar.gz
Ninja-e783554ff5297711ef4c28a01e0c7e0d59a808d5.tar.bz2
refactor out adding "all" to graph tool
Diffstat (limited to 'src')
-rw-r--r--src/ninja.cc52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 2ed897a..950c610 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -40,6 +40,8 @@
#include "util.h"
#include "clean.h"
+namespace {
+
option options[] = {
{ "help", no_argument, NULL, 'h' },
{ }
@@ -104,35 +106,41 @@ struct RealFileReader : public ManifestParser::FileReader {
}
};
-int CmdGraph(State* state, int argc, char* argv[]) {
- int status = 0;
- GraphViz graph;
- graph.Start();
+bool CollectTargetsFromArgs(State* state, int argc, char* argv[],
+ vector<Node*>* targets, string* err) {
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;
- }
+ *targets = state->RootNodes(err);
+ if (!err->empty())
+ return false;
} 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;
+ if (node) {
+ targets->push_back(node);
+ } else {
+ *err = string("unknown target '") + argv[i] + "'";
+ return false;
}
}
}
+ return true;
+}
+
+int CmdGraph(State* state, int argc, char* argv[]) {
+ vector<Node*> nodes;
+ string err;
+ if (!CollectTargetsFromArgs(state, argc, argv, &nodes, &err)) {
+ Error("%s", err.c_str());
+ return 1;
+ }
+
+ GraphViz graph;
+ graph.Start();
+ for (vector<Node*>::const_iterator n = nodes.begin(); n != nodes.end(); ++n)
+ graph.AddTarget(*n);
graph.Finish();
- return status;
+
+ return 0;
}
int CmdQuery(State* state, int argc, char* argv[]) {
@@ -326,6 +334,8 @@ int CmdClean(State* state,
}
}
+} // anonymous namespace
+
int main(int argc, char** argv) {
BuildConfig config;
const char* input_file = "build.ninja";