summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build_log.cc9
-rw-r--r--src/build_log.h9
-rw-r--r--src/build_log_perftest.cc7
-rw-r--r--src/build_log_test.cc16
-rw-r--r--src/build_test.cc4
-rw-r--r--src/ninja.cc6
6 files changed, 30 insertions, 21 deletions
diff --git a/src/build_log.cc b/src/build_log.cc
index 825a8f5..c041514 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -108,9 +108,10 @@ BuildLog::~BuildLog() {
Close();
}
-bool BuildLog::OpenForWrite(const string& path, IsDead* is_dead, string* err) {
+bool BuildLog::OpenForWrite(const string& path, BuildLogUser& user,
+ string* err) {
if (needs_recompaction_) {
- if (!Recompact(path, is_dead, err))
+ if (!Recompact(path, user, err))
return false;
}
@@ -350,7 +351,7 @@ bool BuildLog::WriteEntry(FILE* f, const LogEntry& entry) {
entry.output.c_str(), entry.command_hash) > 0;
}
-bool BuildLog::Recompact(const string& path, IsDead* is_dead, string* err) {
+bool BuildLog::Recompact(const string& path, BuildLogUser& user, string* err) {
METRIC_RECORD(".ninja_log recompact");
printf("Recompacting log...\n");
@@ -370,7 +371,7 @@ bool BuildLog::Recompact(const string& path, IsDead* is_dead, string* err) {
vector<StringPiece> dead_outputs;
for (Entries::iterator i = entries_.begin(); i != entries_.end(); ++i) {
- if (is_dead->IsPathDead(i->first)) {
+ if (user.IsPathDead(i->first)) {
dead_outputs.push_back(i->first);
continue;
}
diff --git a/src/build_log.h b/src/build_log.h
index bb474fc..fc44854 100644
--- a/src/build_log.h
+++ b/src/build_log.h
@@ -25,7 +25,10 @@ using namespace std;
struct Edge;
-struct IsDead {
+/// Can answer questions about the manifest for the BuildLog.
+struct BuildLogUser {
+ /// Return if a given output no longer part of the build manifest.
+ /// This is only called during recompaction and doesn't have to be fast.
virtual bool IsPathDead(StringPiece s) = 0;
};
@@ -40,7 +43,7 @@ struct BuildLog {
BuildLog();
~BuildLog();
- bool OpenForWrite(const string& path, IsDead* is_dead, string* err); // XXX
+ bool OpenForWrite(const string& path, BuildLogUser& user, string* err);
bool RecordCommand(Edge* edge, int start_time, int end_time,
TimeStamp restat_mtime = 0);
void Close();
@@ -76,7 +79,7 @@ struct BuildLog {
bool WriteEntry(FILE* f, const LogEntry& entry);
/// Rewrite the known log entries, throwing away old data.
- bool Recompact(const string& path, IsDead* is_dead, string* err); // XXX
+ bool Recompact(const string& path, BuildLogUser& user, string* err);
typedef ExternalStringHashMap<LogEntry*>::Type Entries;
const Entries& entries() const { return entries_; }
diff --git a/src/build_log_perftest.cc b/src/build_log_perftest.cc
index a09beb8..12cae99 100644
--- a/src/build_log_perftest.cc
+++ b/src/build_log_perftest.cc
@@ -28,10 +28,15 @@
const char kTestFilename[] = "BuildLogPerfTest-tempfile";
+struct NoDeadPaths : public BuildLogUser {
+ virtual bool IsPathDead(StringPiece) { return false; }
+};
+
bool WriteTestData(string* err) {
BuildLog log;
- if (!log.OpenForWrite(kTestFilename, err))
+ NoDeadPaths no_dead_paths;
+ if (!log.OpenForWrite(kTestFilename, no_dead_paths, err))
return false;
/*
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index db1e0be..55f8560 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -30,7 +30,7 @@ namespace {
const char kTestFilename[] = "BuildLogTest-tempfile";
-struct BuildLogTest : public StateTestWithBuiltinRules, public IsDead {
+struct BuildLogTest : public StateTestWithBuiltinRules, public BuildLogUser {
virtual void SetUp() {
// In case a crashing test left a stale file behind.
unlink(kTestFilename);
@@ -48,7 +48,7 @@ TEST_F(BuildLogTest, WriteRead) {
BuildLog log1;
string err;
- EXPECT_TRUE(log1.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log1.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
log1.RecordCommand(state_.edges_[0], 15, 18);
log1.RecordCommand(state_.edges_[1], 20, 25);
@@ -76,7 +76,7 @@ TEST_F(BuildLogTest, FirstWriteAddsSignature) {
BuildLog log;
string contents, err;
- EXPECT_TRUE(log.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
log.Close();
@@ -87,7 +87,7 @@ TEST_F(BuildLogTest, FirstWriteAddsSignature) {
EXPECT_EQ(kExpectedVersion, contents);
// Opening the file anew shouldn't add a second version string.
- EXPECT_TRUE(log.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
log.Close();
@@ -123,7 +123,7 @@ TEST_F(BuildLogTest, Truncate) {
BuildLog log1;
string err;
- EXPECT_TRUE(log1.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log1.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
log1.RecordCommand(state_.edges_[0], 15, 18);
log1.RecordCommand(state_.edges_[1], 20, 25);
@@ -138,7 +138,7 @@ TEST_F(BuildLogTest, Truncate) {
for (off_t size = statbuf.st_size; size > 0; --size) {
BuildLog log2;
string err;
- EXPECT_TRUE(log2.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log2.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
log2.RecordCommand(state_.edges_[0], 15, 18);
log2.RecordCommand(state_.edges_[1], 20, 25);
@@ -273,7 +273,7 @@ TEST_F(BuildLogRecompactTest, Recompact) {
BuildLog log1;
string err;
- EXPECT_TRUE(log1.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log1.OpenForWrite(kTestFilename, *this, &err));
ASSERT_EQ("", err);
// Record the same edge several times, to trigger recompaction
// the next time the log is opened.
@@ -290,7 +290,7 @@ TEST_F(BuildLogRecompactTest, Recompact) {
ASSERT_TRUE(log2.LookupByOutput("out"));
ASSERT_TRUE(log2.LookupByOutput("out2"));
// ...and force a recompaction.
- EXPECT_TRUE(log2.OpenForWrite(kTestFilename, this, &err));
+ EXPECT_TRUE(log2.OpenForWrite(kTestFilename, *this, &err));
log2.Close();
// "out2" is dead, it should've been removed.
diff --git a/src/build_test.cc b/src/build_test.cc
index 19625c6..8a7fc20 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -412,7 +412,7 @@ struct FakeCommandRunner : public CommandRunner {
VirtualFileSystem* fs_;
};
-struct BuildTest : public StateTestWithBuiltinRules, public IsDead {
+struct BuildTest : public StateTestWithBuiltinRules, public BuildLogUser {
BuildTest() : config_(MakeConfig()), command_runner_(&fs_),
builder_(&state_, config_, NULL, NULL, &fs_),
status_(config_) {
@@ -471,7 +471,7 @@ void BuildTest::RebuildTarget(const string& target, const char* manifest,
BuildLog build_log, *pbuild_log = NULL;
if (log_path) {
ASSERT_TRUE(build_log.Load(log_path, &err));
- ASSERT_TRUE(build_log.OpenForWrite(log_path, this, &err));
+ ASSERT_TRUE(build_log.OpenForWrite(log_path, *this, &err));
ASSERT_EQ("", err);
pbuild_log = &build_log;
}
diff --git a/src/ninja.cc b/src/ninja.cc
index 095132e..5bf8221 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -68,7 +68,7 @@ struct Options {
/// The Ninja main() loads up a series of data structures; various tools need
/// to poke into these, so store them as fields on an object.
-struct NinjaMain : public IsDead {
+struct NinjaMain : public BuildLogUser {
NinjaMain(const char* ninja_command, const BuildConfig& config) :
ninja_command_(ninja_command), config_(config) {}
@@ -792,14 +792,14 @@ bool NinjaMain::OpenBuildLog(bool recompact_only) {
}
if (recompact_only) {
- bool success = build_log_.Recompact(log_path, this, &err);
+ bool success = build_log_.Recompact(log_path, *this, &err);
if (!success)
Error("failed recompaction: %s", err.c_str());
return success;
}
if (!config_.dry_run) {
- if (!build_log_.OpenForWrite(log_path, this, &err)) {
+ if (!build_log_.OpenForWrite(log_path, *this, &err)) {
Error("opening build log: %s", err.c_str());
return false;
}