From 269658384e91c3b36ac871ddb2967d41f18db962 Mon Sep 17 00:00:00 2001 From: Nicolas Despres Date: Mon, 21 Mar 2011 21:43:08 +0100 Subject: 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. --- src/ninja.cc | 19 ++++++++++--------- src/util.cc | 11 ++++++++++- 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"); +} diff --git a/src/util.h b/src/util.h index 188528c..e697b92 100644 --- a/src/util.h +++ b/src/util.h @@ -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, ...); -- cgit v0.12