Skip to content

Commit

Permalink
Gracefully handle outdated .ninja_log during '-t recompact'
Browse files Browse the repository at this point in the history
When we explicitly unlink the file we should return LOAD_NOT_FOUND instead of LOAD_SUCCESS
  • Loading branch information
von Heydebrand Julian committed Mar 21, 2024
1 parent 9279832 commit 878aa46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions misc/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ def test_pr_1685(self):
self.assertEqual(run('', flags='-t recompact'), '')
self.assertEqual(run('', flags='-t restat'), '')

def test_issue_2048(self):
with tempfile.TemporaryDirectory() as d:
with open(os.path.join(d, 'build.ninja'), 'w'):
pass

with open(os.path.join(d, '.ninja_log'), 'w') as f:
f.write('# ninja log v4\n')

try:
output = subprocess.check_output([NINJA_PATH, '-t', 'recompact'],
cwd=d,
env=default_env,
stderr=subprocess.STDOUT,
text=True
)

self.assertEqual(
output.strip(),
"ninja: warning: build log version is too old; starting over"
)
except subprocess.CalledProcessError as err:
self.fail("non-zero exit code with: " + err.output)

def test_status(self):
self.assertEqual(run(''), 'ninja: no work to do.\n')
self.assertEqual(run('', pipe=True), 'ninja: no work to do.\n')
Expand Down
4 changes: 2 additions & 2 deletions src/build_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ LoadStatus BuildLog::Load(const string& path, string* err) {
if (invalid_log_version) {
fclose(file);
unlink(path.c_str());
// Don't report this as a failure. An empty build log will cause
// Don't report this as a failure. A missing build log will cause
// us to rebuild the outputs anyway.
return LOAD_SUCCESS;
return LOAD_NOT_FOUND;
}
}

Expand Down

0 comments on commit 878aa46

Please sign in to comment.