From 4d9bf949e0fd6976725dea12bcc254fd39da6490 Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sun, 2 Sep 2012 15:53:59 -0400 Subject: remove config from BuildLog, rename members --- src/build_log.cc | 23 ++++++++++------------- src/build_log.h | 18 +++++++----------- src/build_log_test.cc | 4 ++-- src/ninja.cc | 9 +++++---- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 73c2b5d..a633892 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -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::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); } diff --git a/src/build_log.h b/src/build_log.h index d3994ff..4141ff3 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -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::Type Log; - const Log& log() const { return log_; } + typedef ExternalStringHashMap::Type Entries; + const Entries& entries() const { return entries_; } private: - Log log_; + Entries entries_; FILE* log_file_; - BuildConfig* config_; bool needs_recompaction_; }; diff --git a/src/build_log_test.cc b/src/build_log_test.cc index c465abc..9af95a3 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -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"); diff --git a/src/ninja.cc b/src/ninja.cc index 19438e5..13c0592 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -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 -- cgit v0.12