summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2012-05-08 15:37:27 (GMT)
committerNico Weber <nicolasweber@gmx.de>2012-05-08 15:37:27 (GMT)
commitfadd5a3e8073ad08662cdf86bd1c9ab624667f4c (patch)
tree4a092eaa1a59393fa956db0a0cba2f3ed3f748b0
parentff16370b605c3f668444484eaea2c10a0b62b72f (diff)
downloadNinja-fadd5a3e8073ad08662cdf86bd1c9ab624667f4c.zip
Ninja-fadd5a3e8073ad08662cdf86bd1c9ab624667f4c.tar.gz
Ninja-fadd5a3e8073ad08662cdf86bd1c9ab624667f4c.tar.bz2
Don't write ninja log header to log on every build on Windows.
-rw-r--r--src/build_log.cc4
-rw-r--r--src/build_log_test.cc31
2 files changed, 35 insertions, 0 deletions
diff --git a/src/build_log.cc b/src/build_log.cc
index d30625a..b743f70 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -66,6 +66,10 @@ bool BuildLog::OpenForWrite(const string& path, string* err) {
setvbuf(log_file_, NULL, _IOLBF, BUFSIZ);
SetCloseOnExec(fileno(log_file_));
+ // Opening a file in append mode doesn't set the file pointer to the file's
+ // end on Windows. Do that explicitly.
+ fseek(log_file_, 0, SEEK_END);
+
if (ftell(log_file_) == 0) {
if (fprintf(log_file_, kFileSignature, kCurrentVersion) < 0) {
*err = strerror(errno);
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index 9b729c7..08c3083 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -14,6 +14,7 @@
#include "build_log.h"
+#include "util.h"
#include "test.h"
#ifdef _WIN32
@@ -65,6 +66,36 @@ TEST_F(BuildLogTest, WriteRead) {
ASSERT_EQ("out", e1->output);
}
+TEST_F(BuildLogTest, FirstWriteAddsSignature) {
+ const char kExpectedVersion[] = "# ninja log vX\n";
+ const size_t kVersionPos = strlen(kExpectedVersion) - 2; // Points at 'X'.
+
+ BuildLog log;
+ string contents, err;
+
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ log.Close();
+
+ ASSERT_EQ(0, ReadFile(kTestFilename, &contents, &err));
+ ASSERT_EQ("", err);
+ if (contents.size() >= kVersionPos)
+ contents[kVersionPos] = 'X';
+ EXPECT_EQ(kExpectedVersion, contents);
+
+ // Opening the file anew shouldn't add a second version string.
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ log.Close();
+
+ contents.clear();
+ ASSERT_EQ(0, ReadFile(kTestFilename, &contents, &err));
+ ASSERT_EQ("", err);
+ if (contents.size() >= kVersionPos)
+ contents[kVersionPos] = 'X';
+ EXPECT_EQ(kExpectedVersion, contents);
+}
+
TEST_F(BuildLogTest, DoubleEntry) {
FILE* f = fopen(kTestFilename, "wb");
fprintf(f, "# ninja log v3\n");