From 8a32168107523379be6bd707d9f225a7789ccc10 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 19 May 2022 19:17:01 -0400 Subject: [PATCH] mtest: fix rebuilding correct target list before running tests When manually specifying a target on the CLI, which does not have any test deps, we calculate that there are no deps to rebuild, we run ninja without any targets, and this invokes the default "all" rule and maybe builds a few thousand targets that this specific test does not need. In such a case we simply should not run ninja at all, since we don't want to rebuild anything. --- mesonbuild/mtest.py | 5 +++++ unittests/platformagnostictests.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 4cbaedba88eb..32c70b2835f9 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -1972,6 +1972,11 @@ def convert_path_to_target(path: str) -> str: depends.update(d) targets.update(intro_targets[d]) + if tests and not targets: + # We want to build minimal deps, but if the subset of targets have no + # deps then ninja falls back to 'all'. + return True + ret = subprocess.run(ninja + ['-C', wd] + sorted(targets)).returncode if ret != 0: print(f'Could not rebuild {wd}') diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index bb6a14f6cb46..dd360663e49d 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -92,4 +92,8 @@ def test_mtest_rebuild_deps(self): self._run(self.mtest_command) self.clean() + with self.assertRaises(subprocess.CalledProcessError): + self._run(self.mtest_command + ['runner-without-dep']) + self.clean() + self._run(self.mtest_command + ['runner-with-exedep'])