remove config from BuildLog, rename members
authorEvan Martin <martine@danga.com>
Sun, 2 Sep 2012 19:53:59 +0000 (15:53 -0400)
committerEvan Martin <martine@danga.com>
Sun, 2 Sep 2012 19:56:08 +0000 (15:56 -0400)
src/build_log.cc
src/build_log.h
src/build_log_test.cc
src/ninja.cc

index 73c2b5d0eccf9ebc42a58611adcf4d02702b487a..a63389270b3ac8023c6e78e31325aef6c9f7c32c 100644 (file)
@@ -92,16 +92,13 @@ uint64_t BuildLog::LogEntry::HashCommand(StringPiece command) {
 }
 
 BuildLog::BuildLog()
-  : log_file_(NULL), config_(NULL), needs_recompaction_(false) {}
+  : log_file_(NULL), needs_recompaction_(false) {}
 
 BuildLog::~BuildLog() {
   Close();
 }
 
 bool BuildLog::OpenForWrite(const string& path, string* err) {
-  if (config_ && config_->dry_run)
-    return true;  // Do nothing, report success.
-
   if (needs_recompaction_) {
     Close();
     if (!Recompact(path, err))
@@ -136,14 +133,14 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time,
   for (vector<Node*>::iterator out = edge->outputs_.begin();
        out != edge->outputs_.end(); ++out) {
     const string& path = (*out)->path();
-    Log::iterator i = log_.find(path);
+    Entries::iterator i = entries_.find(path);
     LogEntry* log_entry;
-    if (i != log_.end()) {
+    if (i != entries_.end()) {
       log_entry = i->second;
     } else {
       log_entry = new LogEntry;
       log_entry->output = path;
-      log_.insert(Log::value_type(log_entry->output, log_entry));
+      entries_.insert(Entries::value_type(log_entry->output, log_entry));
     }
     log_entry->command_hash = LogEntry::HashCommand(command);
     log_entry->start_time = start_time;
@@ -286,13 +283,13 @@ bool BuildLog::Load(const string& path, string* err) {
     end = line_end;
 
     LogEntry* entry;
-    Log::iterator i = log_.find(output);
-    if (i != log_.end()) {
+    Entries::iterator i = entries_.find(output);
+    if (i != entries_.end()) {
       entry = i->second;
     } else {
       entry = new LogEntry;
       entry->output = output;
-      log_.insert(Log::value_type(entry->output, entry));
+      entries_.insert(Entries::value_type(entry->output, entry));
       ++unique_entry_count;
     }
     ++total_entry_count;
@@ -331,8 +328,8 @@ bool BuildLog::Load(const string& path, string* err) {
 }
 
 BuildLog::LogEntry* BuildLog::LookupByOutput(const string& path) {
-  Log::iterator i = log_.find(path);
-  if (i != log_.end())
+  Entries::iterator i = entries_.find(path);
+  if (i != entries_.end())
     return i->second;
   return NULL;
 }
@@ -359,7 +356,7 @@ bool BuildLog::Recompact(const string& path, string* err) {
     return false;
   }
 
-  for (Log::iterator i = log_.begin(); i != log_.end(); ++i) {
+  for (Entries::iterator i = entries_.begin(); i != entries_.end(); ++i) {
     WriteEntry(f, *i->second);
   }
 
index d3994ff30ccd025052be7b92274c767014bca440..4141ff3fb0646d43f3281b6ebb574f9b17a83266 100644 (file)
@@ -22,24 +22,21 @@ using namespace std;
 
 #include "hash_map.h"
 #include "timestamp.h"
-#include "util.h"
+#include "util.h"  // uint64_t
 
-struct BuildConfig;
 struct Edge;
 
 /// Store a log of every command ran for every build.
 /// It has a few uses:
 ///
-/// 1) historical command lines for output files, so we know
+/// 1) (hashes of) command lines for existing output files, so we know
 ///    when we need to rebuild due to the command changing
-/// 2) historical timing information
-/// 3) maybe we can generate some sort of build overview output
-///    from it
+/// 2) timing information, perhaps for generating reports
+/// 3) restat information
 struct BuildLog {
   BuildLog();
   ~BuildLog();
 
-  void SetConfig(BuildConfig* config) { config_ = config; }
   bool OpenForWrite(const string& path, string* err);
   void RecordCommand(Edge* edge, int start_time, int end_time,
                      TimeStamp restat_mtime = 0);
@@ -74,13 +71,12 @@ struct BuildLog {
   /// Rewrite the known log entries, throwing away old data.
   bool Recompact(const string& path, string* err);
 
-  typedef ExternalStringHashMap<LogEntry*>::Type Log;
-  const Log& log() const { return log_; }
+  typedef ExternalStringHashMap<LogEntry*>::Type Entries;
+  const Entries& entries() const { return entries_; }
 
  private:
-  Log log_;
+  Entries entries_;
   FILE* log_file_;
-  BuildConfig* config_;
   bool needs_recompaction_;
 };
 
index c465abc187ff511e14c6aea5ebde7c56002cc858..9af95a33ef951bfec22a16cb3e7896b6c5d0c171 100644 (file)
@@ -53,8 +53,8 @@ TEST_F(BuildLogTest, WriteRead) {
   EXPECT_TRUE(log2.Load(kTestFilename, &err));
   ASSERT_EQ("", err);
 
-  ASSERT_EQ(2u, log1.log().size());
-  ASSERT_EQ(2u, log2.log().size());
+  ASSERT_EQ(2u, log1.entries().size());
+  ASSERT_EQ(2u, log2.entries().size());
   BuildLog::LogEntry* e1 = log1.LookupByOutput("out");
   ASSERT_TRUE(e1);
   BuildLog::LogEntry* e2 = log2.LookupByOutput("out");
index 19438e5bd0f3c5f9a4e46cd09b0e1a8a53846a1a..13c0592c171d7f545c6d65e6fa9f03aa99aa0943 100644 (file)
@@ -740,7 +740,6 @@ reload:
     return RunTool(tool, &globals, argc, argv);
 
   BuildLog build_log;
-  build_log.SetConfig(&globals.config);
   globals.state->build_log_ = &build_log;
 
   const string build_dir = globals.state->bindings_.LookupVariable("builddir");
@@ -765,9 +764,11 @@ reload:
     err.clear();
   }
 
-  if (!build_log.OpenForWrite(log_path, &err)) {
-    Error("opening build log: %s", err.c_str());
-    return 1;
+  if (!globals.config.dry_run) {
+    if (!build_log.OpenForWrite(log_path, &err)) {
+      Error("opening build log: %s", err.c_str());
+      return 1;
+    }
   }
 
   if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild