diff options
author | Evan Martin <martine@danga.com> | 2011-04-28 07:45:00 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-04-28 07:45:00 (GMT) |
commit | fcd3e881dfa8068c7db1dcf5d7660c319593baa8 (patch) | |
tree | b0c87d4a334fb53b5ac6937a8bed61814312b02a /src | |
parent | 2f6ac73dad3806e771761af3a58d43d434337a4b (diff) | |
parent | 8c7e87bb0801e07c6c4d8499be965901b917a207 (diff) | |
download | Ninja-fcd3e881dfa8068c7db1dcf5d7660c319593baa8.zip Ninja-fcd3e881dfa8068c7db1dcf5d7660c319593baa8.tar.gz Ninja-fcd3e881dfa8068c7db1dcf5d7660c319593baa8.tar.bz2 |
Merged pull request #29 from polrop/minor-bug-fix.
Minor bug fix
Diffstat (limited to 'src')
-rw-r--r-- | src/browse.cc | 10 | ||||
-rw-r--r-- | src/ninja.cc | 31 | ||||
-rw-r--r-- | src/ninja.h | 2 | ||||
-rw-r--r-- | src/ninja_jumble.cc | 11 | ||||
-rw-r--r-- | src/parsers.cc | 2 | ||||
-rw-r--r-- | src/subprocess.cc | 2 |
6 files changed, 34 insertions, 24 deletions
diff --git a/src/browse.cc b/src/browse.cc index db89db0..f65e537 100644 --- a/src/browse.cc +++ b/src/browse.cc @@ -25,13 +25,13 @@ void RunBrowsePython(State* state, const char* ninja_command) { // (Actually the Python process becomes the parent.) int pipefd[2]; if (pipe(pipefd) < 0) { - perror("pipe"); + perror("ninja: pipe"); return; } pid_t pid = fork(); if (pid < 0) { - perror("fork"); + perror("ninja: fork"); return; } @@ -39,7 +39,7 @@ void RunBrowsePython(State* state, const char* ninja_command) { close(pipefd[1]); do { if (dup2(pipefd[0], 0) < 0) { - perror("dup2"); + perror("ninja: dup2"); break; } @@ -48,7 +48,7 @@ void RunBrowsePython(State* state, const char* ninja_command) { "python", "-", ninja_command, NULL }; execvp(command[0], (char**)command); - perror("execvp"); + perror("ninja: execvp"); } while (false); _exit(1); } else { // Child. @@ -57,7 +57,7 @@ void RunBrowsePython(State* state, const char* ninja_command) { // Write the script file into the stdin of the Python process. ssize_t len = write(pipefd[1], kBrowsePy, sizeof(kBrowsePy)); if (len < (ssize_t)sizeof(kBrowsePy)) - perror("write"); + perror("ninja: write"); close(pipefd[1]); exit(0); } 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); diff --git a/src/ninja.h b/src/ninja.h index 706cb9c..2590e63 100644 --- a/src/ninja.h +++ b/src/ninja.h @@ -75,7 +75,9 @@ struct State { void AddOut(Edge* edge, const string& path); StatCache stat_cache_; + /// All the rules used in the graph. map<string, const Rule*> rules_; + /// All the edges of the graph. vector<Edge*> edges_; BindingEnv bindings_; struct BuildLog* build_log_; diff --git a/src/ninja_jumble.cc b/src/ninja_jumble.cc index a935c21..fd2ee18 100644 --- a/src/ninja_jumble.cc +++ b/src/ninja_jumble.cc @@ -24,6 +24,7 @@ #include "build_log.h" #include "graph.h" +#include "util.h" int ReadFile(const string& path, string* contents, string* err) { FILE* f = fopen(path.c_str(), "r"); @@ -53,7 +54,7 @@ int RealDiskInterface::Stat(const string& path) { if (errno == ENOENT) { return 0; } else { - fprintf(stderr, "stat(%s): %s\n", path.c_str(), strerror(errno)); + Error("stat(%s): %s", path.c_str(), strerror(errno)); return -1; } } @@ -100,7 +101,7 @@ string RealDiskInterface::ReadFile(const string& path, string* err) { bool RealDiskInterface::MakeDir(const string& path) { if (mkdir(path.c_str(), 0777) < 0) { - fprintf(stderr, "mkdir(%s): %s\n", path.c_str(), strerror(errno)); + Error("mkdir(%s): %s", path.c_str(), strerror(errno)); return false; } return true; @@ -115,8 +116,6 @@ FileStat* StatCache::GetFile(const string& path) { return file; } -#include <stdio.h> - void StatCache::Dump() { for (Paths::iterator i = paths_.begin(); i != paths_.end(); ++i) { FileStat* file = i->second; @@ -178,8 +177,8 @@ void State::AddOut(Edge* edge, const string& path) { Node* node = GetNode(path); edge->outputs_.push_back(node); if (node->in_edge_) { - fprintf(stderr, "WARNING: multiple rules generate %s. " - "build will not be correct; continuing anyway\n", path.c_str()); + Error("WARNING: multiple rules generate %s. " + "build will not be correct; continuing anyway", path.c_str()); } node->in_edge_ = edge; } diff --git a/src/parsers.cc b/src/parsers.cc index 82b7111..fed52cd 100644 --- a/src/parsers.cc +++ b/src/parsers.cc @@ -295,7 +295,7 @@ bool ManifestParser::Parse(const string& input, string* err) { // XXX remove this hack, or make it more principled. char cwd[1024]; if (!getcwd(cwd, sizeof(cwd))) { - perror("getcwd"); + perror("ninja: getcwd"); return 1; } value = cwd + value.substr(9); diff --git a/src/subprocess.cc b/src/subprocess.cc index 1043e65..cef0ad3 100644 --- a/src/subprocess.cc +++ b/src/subprocess.cc @@ -157,7 +157,7 @@ void SubprocessSet::DoWork() { int ret = poll(fds.data(), fds.size(), -1); if (ret == -1) { if (errno != EINTR) - perror("poll"); + perror("ninja: poll"); return; } |