Skip to content

Commit

Permalink
remove config from BuildLog, rename members
Browse files Browse the repository at this point in the history
  • Loading branch information
evmar committed Sep 2, 2012
1 parent 3220e62 commit 4d9bf94
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
23 changes: 10 additions & 13 deletions src/build_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
18 changes: 7 additions & 11 deletions src/build_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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_;
};

Expand Down
4 changes: 2 additions & 2 deletions src/build_log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 5 additions & 4 deletions src/ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,6 @@ int NinjaMain(int argc, char** argv) {
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");
Expand All @@ -765,9 +764,11 @@ int NinjaMain(int argc, char** argv) {
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
Expand Down

0 comments on commit 4d9bf94

Please sign in to comment.