summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-04-30 15:55:49 (GMT)
committerNico Weber <nicolasweber@gmx.de>2013-04-30 15:55:49 (GMT)
commitf70a90edc6681fef7e75c7bc7f2860d40c2490ee (patch)
tree1372a4c94e1357c28fd4013b6b1de948eafcca15 /src
parent20942b8cf86da96eb4288138fba72c2609cfd54d (diff)
downloadNinja-f70a90edc6681fef7e75c7bc7f2860d40c2490ee.zip
Ninja-f70a90edc6681fef7e75c7bc7f2860d40c2490ee.tar.gz
Ninja-f70a90edc6681fef7e75c7bc7f2860d40c2490ee.tar.bz2
Let DepsLog::RecordDeps() update its in-memory representation.
This is a behavior change, but it should be safe: Graph only queries the deps log at startup, before running any command. Nothing else currently queries the deps log.
Diffstat (limited to 'src')
-rw-r--r--src/deps_log.cc7
-rw-r--r--src/deps_log_test.cc22
2 files changed, 21 insertions, 8 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index 8d90765..fd7d107 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -106,6 +106,7 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
if (!made_change)
return true;
+ // Update on-disk representation.
uint16_t size = 4 * (1 + 1 + (uint16_t)node_count);
size |= 0x8000; // Deps record: set high bit.
fwrite(&size, 2, 1, file_);
@@ -118,6 +119,12 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
fwrite(&id, 4, 1, file_);
}
+ // Update in-memory representation.
+ Deps* deps = new Deps(mtime, node_count);
+ for (int i = 0; i < node_count; ++i)
+ deps->nodes[i] = nodes[i];
+ UpdateDeps(node->id(), deps);
+
return true;
}
diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc
index 14f1572..31f0414 100644
--- a/src/deps_log_test.cc
+++ b/src/deps_log_test.cc
@@ -49,6 +49,13 @@ TEST_F(DepsLogTest, WriteRead) {
deps.push_back(state1.GetNode("foo.h"));
deps.push_back(state1.GetNode("bar2.h"));
log1.RecordDeps(state1.GetNode("out2.o"), 2, deps);
+
+ DepsLog::Deps* log_deps = log1.GetDeps(state1.GetNode("out.o"));
+ ASSERT_TRUE(log_deps);
+ ASSERT_EQ(1, log_deps->mtime);
+ ASSERT_EQ(2, log_deps->node_count);
+ ASSERT_EQ("foo.h", log_deps->nodes[0]->path());
+ ASSERT_EQ("bar.h", log_deps->nodes[1]->path());
}
log1.Close();
@@ -66,14 +73,13 @@ TEST_F(DepsLogTest, WriteRead) {
ASSERT_EQ(node1->id(), node2->id());
}
- // log1 has no deps entries, as it was only used for writing.
- // Manually check the entries in log2.
- DepsLog::Deps* deps = log2.GetDeps(state2.GetNode("out.o"));
- ASSERT_TRUE(deps);
- ASSERT_EQ(1, deps->mtime);
- ASSERT_EQ(2, deps->node_count);
- ASSERT_EQ("foo.h", deps->nodes[0]->path());
- ASSERT_EQ("bar.h", deps->nodes[1]->path());
+ // Spot-check the entries in log2.
+ DepsLog::Deps* log_deps = log2.GetDeps(state2.GetNode("out2.o"));
+ ASSERT_TRUE(log_deps);
+ ASSERT_EQ(2, log_deps->mtime);
+ ASSERT_EQ(2, log_deps->node_count);
+ ASSERT_EQ("foo.h", log_deps->nodes[0]->path());
+ ASSERT_EQ("bar2.h", log_deps->nodes[1]->path());
}
// Verify that adding the same deps twice doesn't grow the file.