Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 697350d

Browse files
committed
make it more explicit that a bad build log causes us to rebuild
(Committing this on top of b56fe80 since they're related, but I may end up reverting both.)
1 parent 413103c commit 697350d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/build_log.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,13 @@ bool BuildLog::Load(const string& path, string* err) {
235235
sscanf(line_start, kFileSignature, &log_version);
236236

237237
if (log_version < kOldestSupportedVersion) {
238-
*err = "unable to extract version from build log, perhaps due to "
239-
"being too old; you must clobber your build output and rebuild";
238+
*err = ("build log version invalid, perhaps due to being too old; "
239+
"starting over");
240240
fclose(file);
241-
return false;
241+
unlink(path.c_str());
242+
// Don't report this as a failure. An empty build log will cause
243+
// us to rebuild the outputs anyway.
244+
return true;
242245
}
243246
}
244247

src/build_log_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ TEST_F(BuildLogTest, ObsoleteOldVersion) {
154154

155155
string err;
156156
BuildLog log;
157-
EXPECT_FALSE(log.Load(kTestFilename, &err));
157+
EXPECT_TRUE(log.Load(kTestFilename, &err));
158158
ASSERT_NE(err.find("version"), string::npos);
159159
}
160160

src/ninja.cc

+5
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ int NinjaMain(int argc, char** argv) {
759759
Error("loading build log %s: %s", log_path.c_str(), err.c_str());
760760
return 1;
761761
}
762+
if (!err.empty()) {
763+
// Hack: Load() can return a warning via err by returning true.
764+
Warning("%s", err.c_str());
765+
err.clear();
766+
}
762767

763768
if (!build_log.OpenForWrite(log_path, &err)) {
764769
Error("opening build log: %s", err.c_str());

0 commit comments

Comments
 (0)