Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove config from BuildLog, rename members

  • Loading branch information...
commit 4d9bf949e0fd6976725dea12bcc254fd39da6490 1 parent 3220e62
@martine authored
View
23 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<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);
}
View
18 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<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_;
};
View
4 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");
View
9 src/ninja.cc
@@ -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");
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.