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 13, 2024
1 parent ab510c7 commit 878653f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions misc/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ def test_pr_1685(self):
self.assertEqual(run('', flags='-t recompact'), '')
self.assertEqual(run('', flags='-t restat'), '')

def test_pr_2390(self):
with tempfile.TemporaryDirectory() as d:
os.chdir(d)

with open('build.ninja', 'w') as f:
pass

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

try:
output = subprocess.check_output([NINJA_PATH, '-t', 'recompact'],
shell=True,
env=default_env,
stderr=subprocess.STDOUT
)
self.assertEqual(
output.decode('utf-8').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
2 changes: 1 addition & 1 deletion src/build_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ LoadStatus BuildLog::Load(const string& path, string* err) {
unlink(path.c_str());
// Don't report this as a failure. An empty build log will cause
// us to rebuild the outputs anyway.
return LOAD_SUCCESS;
return LOAD_NOT_FOUND;
}
}

Expand Down

0 comments on commit 878653f

Please sign in to comment.