pass config into build log
authorEvan Martin <martine@danga.com>
Sun, 23 Jan 2011 19:58:01 +0000 (11:58 -0800)
committerEvan Martin <martine@danga.com>
Sun, 23 Jan 2011 19:58:01 +0000 (11:58 -0800)
src/build.cc
src/build_log.cc
src/build_log.h
src/ninja.cc
src/ninja_jumble.cc

index 9686b74..a75659a 100644 (file)
@@ -373,5 +373,6 @@ void Builder::FinishEdge(Edge* edge) {
     return;
 
   int ms = status_->BuildEdgeFinished(edge);
-  log_->RecordCommand(edge, ms);
+  if (log_)
+    log_->RecordCommand(edge, ms);
 }
index b5b429a..144ae14 100644 (file)
@@ -14,7 +14,8 @@
 // Once the number of redundant entries exceeds a threshold, we write
 // out a new file and replace the existing one with it.
 
-BuildLog::BuildLog() : log_file_(NULL), needs_recompaction_(false) {}
+BuildLog::BuildLog()
+  : log_file_(NULL), config_(NULL), needs_recompaction_(false) {}
 
 bool BuildLog::OpenForWrite(const string& path, string* err) {
   if (needs_recompaction_) {
index 265f378..58a598e 100644 (file)
@@ -2,6 +2,7 @@
 #include <string>
 using namespace std;
 
+struct BuildConfig;
 struct Edge;
 
 // Store a log of every command ran for every build.
@@ -14,6 +15,7 @@ struct Edge;
 struct BuildLog {
   BuildLog();
 
+  void SetConfig(BuildConfig* config) { config_ = config; }
   bool OpenForWrite(const string& path, string* err);
   void RecordCommand(Edge* edge, int time_ms);
   void Close();
@@ -42,5 +44,6 @@ struct BuildLog {
   typedef map<string, LogEntry*> Log;
   Log log_;
   FILE* log_file_;
+  BuildConfig* config_;
   bool needs_recompaction_;
 };
index 5daf2bd..608297e 100644 (file)
@@ -171,13 +171,17 @@ int main(int argc, char** argv) {
   if (browse)
     return CmdBrowse(&state, argc, argv);
 
+  BuildLog build_log;
+  build_log.SetConfig(&config);
+  state.build_log_ = &build_log;
+
   const char* kLogPath = ".ninja_log";
-  if (!state.build_log_->Load(kLogPath, &err)) {
+  if (!build_log.Load(kLogPath, &err)) {
     fprintf(stderr, "error loading build log: %s\n", err.c_str());
     return 1;
   }
 
-  if (!config.dry_run && !state.build_log_->OpenForWrite(kLogPath, &err)) {
+  if (!config.dry_run && !build_log.OpenForWrite(kLogPath, &err)) {
     fprintf(stderr, "error opening build log: %s\n", err.c_str());
     return 1;
   }
index 930ed59..a1ba219 100644 (file)
@@ -118,7 +118,6 @@ const Rule State::kPhonyRule("phony");
 
 State::State() : build_log_(NULL) {
   AddRule(&kPhonyRule);
-  build_log_ = new BuildLog;
 }
 
 const Rule* State::LookupRule(const string& rule_name) {