diff options
author | Nicolas Despres <nicolas.despres@gmail.com> | 2011-03-21 20:43:08 (GMT) |
---|---|---|
committer | Nicolas Despres <nicolas.despres@gmail.com> | 2011-03-21 20:59:11 (GMT) |
commit | 269658384e91c3b36ac871ddb2967d41f18db962 (patch) | |
tree | 7f4bffddc204c2c61b7ed6dd4d262d3125d16bee | |
parent | 5f0157250c5d304e28959f6e665af6faad903561 (diff) | |
download | Ninja-269658384e91c3b36ac871ddb2967d41f18db962.zip Ninja-269658384e91c3b36ac871ddb2967d41f18db962.tar.gz Ninja-269658384e91c3b36ac871ddb2967d41f18db962.tar.bz2 |
Prefix error messages with program name.
It make it easier while debugging to know who is reporting the error:
Ninja itself or one of the command called by Ninja during the build
process or one of the generator which called Ninja.
-rw-r--r-- | src/ninja.cc | 19 | ||||
-rw-r--r-- | src/util.cc | 11 | ||||
-rw-r--r-- | src/util.h | 3 |
3 files changed, 23 insertions, 10 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index c113bfb..35d25e0 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -34,6 +34,7 @@ #include "graph.h" #include "graphviz.h" #include "parsers.h" +#include "util.h" option options[] = { { "help", no_argument, NULL, 'h' }, @@ -164,7 +165,7 @@ int main(int argc, char** argv) { } } if (optind >= argc) { - fprintf(stderr, "expected target to build\n"); + Error("expected target to build"); usage(config); return 1; } @@ -182,7 +183,7 @@ int main(int argc, char** argv) { ManifestParser parser(&state, &file_reader); string err; if (!parser.Load(input_file, &err)) { - fprintf(stderr, "error loading '%s': %s\n", input_file, err.c_str()); + Error("loading '%s': %s", input_file, err.c_str()); return 1; } @@ -193,7 +194,7 @@ int main(int argc, char** argv) { return CmdQuery(&state, argc, argv); if (tool == "browse") return CmdBrowse(&state, argc, argv); - fprintf(stderr, "unknown tool '%s'\n", tool.c_str()); + Error("unknown tool '%s'", tool.c_str()); } BuildLog build_log; @@ -205,21 +206,21 @@ int main(int argc, char** argv) { string log_path = kLogPath; if (!build_dir.empty()) { if (mkdir(build_dir.c_str(), 0777) < 0 && errno != EEXIST) { - fprintf(stderr, "Error creating build directory %s: %s\n", - build_dir.c_str(), strerror(errno)); + Error("creating build directory %s: %s", + build_dir.c_str(), strerror(errno)); return 1; } log_path = build_dir + "/" + kLogPath; } if (!build_log.Load(log_path.c_str(), &err)) { - fprintf(stderr, "error loading build log %s: %s\n", - log_path.c_str(), err.c_str()); + Error("loading build log %s: %s", + log_path.c_str(), err.c_str()); return 1; } if (!build_log.OpenForWrite(log_path.c_str(), &err)) { - fprintf(stderr, "error opening build log: %s\n", err.c_str()); + Error("opening build log: %s", err.c_str()); return 1; } @@ -227,7 +228,7 @@ int main(int argc, char** argv) { for (int i = 0; i < argc; ++i) { if (!builder.AddTarget(argv[i], &err)) { if (!err.empty()) { - fprintf(stderr, "%s\n", err.c_str()); + Error("%s", err.c_str()); return 1; } else { // Added a target that is already up-to-date; not really diff --git a/src/util.cc b/src/util.cc index 1968702..a2e080f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -20,10 +20,19 @@ void Fatal(const char* msg, ...) { va_list ap; - fprintf(stderr, "FATAL: "); + fprintf(stderr, "ninja: FATAL: "); va_start(ap, msg); vfprintf(stderr, msg, ap); va_end(ap); fprintf(stderr, "\n"); exit(1); } + +void Error(const char* msg, ...) { + va_list ap; + fprintf(stderr, "ninja: error: "); + va_start(ap, msg); + vfprintf(stderr, msg, ap); + va_end(ap); + fprintf(stderr, "\n"); +} @@ -19,3 +19,6 @@ void DumpBacktrace(int skip_frames); // Log a fatal message, dump a backtrace, and exit. void Fatal(const char* msg, ...); + +// Log an error message. +void Error(const char* msg, ...); |