summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 5e26f6a..6359aaf 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -19,7 +19,6 @@
#include "getopt.h"
#else
#include <getopt.h>
-#include <limits.h>
#endif
#include <stdio.h>
#include <string.h>
@@ -99,15 +98,27 @@ struct RealFileReader : public ManifestParser::FileReader {
};
int CmdGraph(State* state, int argc, char* argv[]) {
+ int status = 0;
GraphViz graph;
graph.Start();
- for (int i = 0; i < argc; ++i)
- graph.AddTarget(state->GetNode(argv[i]));
+ 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 0;
+ return status;
}
int CmdQuery(State* state, int argc, char* argv[]) {
+ if (argc == 0) {
+ Error("expected a target to query");
+ return 1;
+ }
for (int i = 0; i < argc; ++i) {
Node* node = state->GetNode(argv[i]);
if (node) {
@@ -137,6 +148,10 @@ int CmdQuery(State* state, int argc, char* argv[]) {
int CmdBrowse(State* state, int argc, char* argv[]) {
#ifndef WIN32
+ if (argc < 1) {
+ Error("expected a target to browse");
+ return 1;
+ }
RunBrowsePython(state, argv[0]);
#else
Error("browse mode not yet supported on Windows");
@@ -176,7 +191,7 @@ int main(int argc, char** argv) {
return 1;
}
}
- if (optind >= argc) {
+ if (optind >= argc && tool.empty()) {
Error("expected target to build");
usage(config);
return 1;
@@ -184,12 +199,6 @@ int main(int argc, char** argv) {
argv += optind;
argc -= optind;
- char cwd[PATH_MAX];
- if (!getcwd(cwd, sizeof(cwd))) {
- perror("getcwd");
- return 1;
- }
-
State state;
RealFileReader file_reader;
ManifestParser parser(&state, &file_reader);