From 17399ca4e5c0de7e64036c46cae616c86317e51f Mon Sep 17 00:00:00 2001 From: Maxim Kalaev Date: Sat, 6 Oct 2012 23:16:21 +0200 Subject: build log: Adding test for multiple target edges --- src/build_log_test.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/build_log_test.cc b/src/build_log_test.cc index a6c2a86..5275f25 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -245,3 +245,23 @@ TEST_F(BuildLogTest, VeryLongInputLine) { ASSERT_EQ(789, e->restat_mtime); ASSERT_NO_FATAL_FAILURE(AssertHash("command2", e->command_hash)); } + +TEST_F(BuildLogTest, MultiTargetEdge) { + AssertParse(&state_, +"build out out.d: cat\n"); + + BuildLog log; + log.RecordCommand(state_.edges_[0], 21, 22); + + ASSERT_EQ(2u, log.entries().size()); + BuildLog::LogEntry* e1 = log.LookupByOutput("out"); + ASSERT_TRUE(e1); + BuildLog::LogEntry* e2 = log.LookupByOutput("out.d"); + ASSERT_TRUE(e2); + ASSERT_EQ("out", e1->output); + ASSERT_EQ("out.d", e2->output); + ASSERT_EQ(21, e1->start_time); + ASSERT_EQ(21, e2->start_time); + ASSERT_EQ(22, e2->end_time); + ASSERT_EQ(22, e2->end_time); +} -- cgit v0.12 From 9e8bfe0365ccf78a524c0733a33b5bac2dc66f5a Mon Sep 17 00:00:00 2001 From: Maxim Kalaev Date: Fri, 12 Oct 2012 08:57:23 +0200 Subject: build log: moving HashCommand() calculation out of targets loop --- src/build_log.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/build_log.cc b/src/build_log.cc index 33cbfc4..19e1c14 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -130,6 +130,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time, TimeStamp restat_mtime) { string command = edge->EvaluateCommand(true); + uint64_t command_hash = LogEntry::HashCommand(command); for (vector::iterator out = edge->outputs_.begin(); out != edge->outputs_.end(); ++out) { const string& path = (*out)->path(); @@ -142,7 +143,7 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time, log_entry->output = path; entries_.insert(Entries::value_type(log_entry->output, log_entry)); } - log_entry->command_hash = LogEntry::HashCommand(command); + log_entry->command_hash = command_hash; log_entry->start_time = start_time; log_entry->end_time = end_time; log_entry->restat_mtime = restat_mtime; -- cgit v0.12 From 96e01852b3060f37f20784ee0941d13d8f592794 Mon Sep 17 00:00:00 2001 From: Maxim Kalaev Date: Fri, 12 Oct 2012 08:59:49 +0200 Subject: build log: mini-refactoring to use constructors to initialize entries --- src/build_log.cc | 15 +++++++++++---- src/build_log.h | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 19e1c14..28fcf88 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -91,6 +91,15 @@ uint64_t BuildLog::LogEntry::HashCommand(StringPiece command) { return MurmurHash64A(command.str_, command.len_); } +BuildLog::LogEntry::LogEntry(const string& _output) + : output(_output) {} + +BuildLog::LogEntry::LogEntry(const string& _output, uint64_t _command_hash, + int _start_time, int _end_time, TimeStamp _restat_mtime) + : output(_output), command_hash(_command_hash), + start_time(_start_time), end_time(_end_time), restat_mtime(_restat_mtime) +{} + BuildLog::BuildLog() : log_file_(NULL), needs_recompaction_(false) {} @@ -139,8 +148,7 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time, if (i != entries_.end()) { log_entry = i->second; } else { - log_entry = new LogEntry; - log_entry->output = path; + log_entry = new LogEntry(path); entries_.insert(Entries::value_type(log_entry->output, log_entry)); } log_entry->command_hash = command_hash; @@ -288,8 +296,7 @@ bool BuildLog::Load(const string& path, string* err) { if (i != entries_.end()) { entry = i->second; } else { - entry = new LogEntry; - entry->output = output; + entry = new LogEntry(output); entries_.insert(Entries::value_type(entry->output, entry)); ++unique_entry_count; } diff --git a/src/build_log.h b/src/build_log.h index 4141ff3..5a3b516 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -60,6 +60,9 @@ struct BuildLog { start_time == o.start_time && end_time == o.end_time && restat_mtime == o.restat_mtime; } + + explicit LogEntry(const string& output); + LogEntry(const string& output, uint64_t command_hash, int start_time, int end_time, TimeStamp restat_mtime); }; /// Lookup a previously-run command by its output path. -- cgit v0.12 From 62b136315c6635a64f314dde78dbd8f1235eb306 Mon Sep 17 00:00:00 2001 From: Maxim Kalaev Date: Sun, 14 Oct 2012 20:40:46 +0200 Subject: build log: fixing parameter names --- src/build_log.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 28fcf88..235951f 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -91,13 +91,13 @@ uint64_t BuildLog::LogEntry::HashCommand(StringPiece command) { return MurmurHash64A(command.str_, command.len_); } -BuildLog::LogEntry::LogEntry(const string& _output) - : output(_output) {} +BuildLog::LogEntry::LogEntry(const string& output) + : output(output) {} -BuildLog::LogEntry::LogEntry(const string& _output, uint64_t _command_hash, - int _start_time, int _end_time, TimeStamp _restat_mtime) - : output(_output), command_hash(_command_hash), - start_time(_start_time), end_time(_end_time), restat_mtime(_restat_mtime) +BuildLog::LogEntry::LogEntry(const string& output, uint64_t command_hash, + int start_time, int end_time, TimeStamp restat_mtime) + : output(output), command_hash(command_hash), + start_time(start_time), end_time(end_time), restat_mtime(restat_mtime) {} BuildLog::BuildLog() -- cgit v0.12