From 91b986fe22f327df3ed69234f4472d10e5bd883f Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Mon, 18 Jun 2012 15:47:38 -0700 Subject: drop support of log formats < 4 Log format 4 was introduced in January. There's been plenty of time to migrate. --- src/build_log.cc | 25 +++++++++++++++---------- src/build_log_test.cc | 19 ++++++------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 4baff42..86b660f 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -39,6 +39,7 @@ namespace { const char kFileSignature[] = "# ninja log v%d\n"; +const int kOldestSupportedVersion = 4; const int kCurrentVersion = 5; // 64bit MurmurHash2, by Austin Appleby @@ -229,19 +230,23 @@ bool BuildLog::Load(const string& path, string* err) { char* line_end = 0; while (reader.ReadLine(&line_start, &line_end)) { if (!log_version) { - log_version = 1; // Assume by default. - if (sscanf(line_start, kFileSignature, &log_version) > 0) - continue; + sscanf(line_start, kFileSignature, &log_version); + + if (log_version < kOldestSupportedVersion) { + *err = "unable to extract version from build log, perhaps due to " + "being too old; you must clobber your build output and rebuild"; + return false; + } } // If no newline was found in this chunk, read the next. if (!line_end) continue; - char field_separator = log_version >= 4 ? '\t' : ' '; + const char kFieldSeparator = '\t'; char* start = line_start; - char* end = (char*)memchr(start, field_separator, line_end - start); + char* end = (char*)memchr(start, kFieldSeparator, line_end - start); if (!end) continue; *end = 0; @@ -252,21 +257,21 @@ bool BuildLog::Load(const string& path, string* err) { start_time = atoi(start); start = end + 1; - end = (char*)memchr(start, field_separator, line_end - start); + end = (char*)memchr(start, kFieldSeparator, line_end - start); if (!end) continue; *end = 0; end_time = atoi(start); start = end + 1; - end = (char*)memchr(start, field_separator, line_end - start); + end = (char*)memchr(start, kFieldSeparator, line_end - start); if (!end) continue; *end = 0; restat_mtime = atol(start); start = end + 1; - end = (char*)memchr(start, field_separator, line_end - start); + end = (char*)memchr(start, kFieldSeparator, line_end - start); if (!end) continue; string output = string(start, end - start); @@ -293,10 +298,10 @@ bool BuildLog::Load(const string& path, string* err) { char c = *end; *end = '\0'; entry->command_hash = (uint64_t)strtoull(start, NULL, 10); *end = c; - } - else + } else { entry->command_hash = LogEntry::HashCommand(StringPiece(start, end - start)); + } } fclose(file); diff --git a/src/build_log_test.cc b/src/build_log_test.cc index afd3b81..9fb42c9 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -98,9 +98,9 @@ TEST_F(BuildLogTest, FirstWriteAddsSignature) { TEST_F(BuildLogTest, DoubleEntry) { FILE* f = fopen(kTestFilename, "wb"); - fprintf(f, "# ninja log v3\n"); - fprintf(f, "0 1 2 out command abc\n"); - fprintf(f, "3 4 5 out command def\n"); + fprintf(f, "# ninja log v4\n"); + fprintf(f, "0\t1\t2\tout\tcommand abc\n"); + fprintf(f, "3\t4\t5\tout\tcommand def\n"); fclose(f); string err; @@ -148,7 +148,7 @@ TEST_F(BuildLogTest, Truncate) { } } -TEST_F(BuildLogTest, UpgradeV3) { +TEST_F(BuildLogTest, ObsoleteOldVersion) { FILE* f = fopen(kTestFilename, "wb"); fprintf(f, "# ninja log v3\n"); fprintf(f, "123 456 0 out command\n"); @@ -156,15 +156,8 @@ TEST_F(BuildLogTest, UpgradeV3) { string err; BuildLog log; - EXPECT_TRUE(log.Load(kTestFilename, &err)); - ASSERT_EQ("", err); - - BuildLog::LogEntry* e = log.LookupByOutput("out"); - ASSERT_TRUE(e); - ASSERT_EQ(123, e->start_time); - ASSERT_EQ(456, e->end_time); - ASSERT_EQ(0, e->restat_mtime); - ASSERT_NO_FATAL_FAILURE(AssertHash("command", e->command_hash)); + EXPECT_FALSE(log.Load(kTestFilename, &err)); + ASSERT_NE(err.find("version"), string::npos); } TEST_F(BuildLogTest, SpacesInOutputV4) { -- cgit v0.12