From ed6b33ebed688b2acec47c03304512f3f110502d Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 19 May 2022 19:17:01 -0400 Subject: [PATCH] mtest: fix rebuilding all before running tests If an explicit list of targets is passed on the CLI, then that is passed to rebuild_deps. If not, we pass every loaded test to rebuild_deps instead. This means we cannot distinguish between "trying to run all tests" and "trying to run specific tests". We then load all the deps for all tests, and try to build them all as explicit arguments to the underlying ninja. This is usually papered over by people running `ninja test`, which depends on "all" anyway as a prerequisite for invoking the underlying `meson test --no-rebuild --print-errorlogs`, however, instead running `meson setup builddir && meson test -C builddir` with under-specified test deps would actually build a handful of deps and not anything else, then fail. Instead, pass no tests to rebuild_deps, so that we iterate over nothing and add no explicit targets. Hence, meson rebuilds the default "all" rule. --- mesonbuild/mtest.py | 3 ++- test cases/unit/106 underspecified mtest/main.c | 1 + test cases/unit/106 underspecified mtest/meson.build | 8 ++++++++ test cases/unit/106 underspecified mtest/runner.py | 5 +++++ unittests/platformagnostictests.py | 10 ++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test cases/unit/106 underspecified mtest/main.c create mode 100644 test cases/unit/106 underspecified mtest/meson.build create mode 100755 test cases/unit/106 underspecified mtest/runner.py diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index a4ea5aa4d875..4cbaedba88eb 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -1666,9 +1666,10 @@ def doit(self) -> int: raise RuntimeError('Test harness object can only be used once.') self.is_run = True tests = self.get_tests() + rebuild_only_tests = tests if self.options.args else [] if not tests: return 0 - if not self.options.no_rebuild and not rebuild_deps(self.options.wd, tests): + if not self.options.no_rebuild and not rebuild_deps(self.options.wd, rebuild_only_tests): # We return 125 here in case the build failed. # The reason is that exit code 125 tells `git bisect run` that the current # commit should be skipped. Thus users can directly use `meson test` to diff --git a/test cases/unit/106 underspecified mtest/main.c b/test cases/unit/106 underspecified mtest/main.c new file mode 100644 index 000000000000..8842fc1226ef --- /dev/null +++ b/test cases/unit/106 underspecified mtest/main.c @@ -0,0 +1 @@ +int main(void) { return 0 ; } diff --git a/test cases/unit/106 underspecified mtest/meson.build b/test cases/unit/106 underspecified mtest/meson.build new file mode 100644 index 000000000000..c0a88d6770c8 --- /dev/null +++ b/test cases/unit/106 underspecified mtest/meson.build @@ -0,0 +1,8 @@ +project('underspecified deps', 'c') + +runner = find_program('runner.py') +exe1 = executable('main1', 'main.c') +exe2 = executable('main2', 'main.c') + +test('runner-with-exedep', runner, args: exe1) +test('runner-without-dep', runner, args: exe2.full_path()) diff --git a/test cases/unit/106 underspecified mtest/runner.py b/test cases/unit/106 underspecified mtest/runner.py new file mode 100755 index 000000000000..9fb9ac40b94e --- /dev/null +++ b/test cases/unit/106 underspecified mtest/runner.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +import sys, subprocess + +subprocess.run(sys.argv[1:], check=True) diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index f45e6b4ddbbf..bb6a14f6cb46 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import subprocess import tempfile from unittest import skipIf @@ -83,3 +84,12 @@ def test_debug_function_outputs_to_meson_log(self): mesonlog = os.path.join(self.builddir, 'meson-logs/meson-log.txt') with open(mesonlog, mode='r', encoding='utf-8') as file: self.assertIn(log_msg, file.read()) + + def test_mtest_rebuild_deps(self): + testdir = os.path.join(self.unit_test_dir, '106 underspecified mtest') + self.init(testdir) + + self._run(self.mtest_command) + self.clean() + + self._run(self.mtest_command + ['runner-with-exedep'])