diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index ba9b06559..8b2382907 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -1560,6 +1560,16 @@ class TestHarness: startdir = os.getcwd() try: os.chdir(self.options.wd) + + # Before loading build / test data, make sure that the build + # configuration does not need to be regenerated. This needs to + # happen before rebuild_deps(), because we need the correct list of + # tests and their dependencies to compute + if not self.options.no_rebuild: + ret = subprocess.run(self.ninja + ['build.ninja']).returncode + if ret != 0: + raise TestException(f'Could not configure {self.options.wd!r}') + self.build_data = build.load(os.getcwd()) if not self.options.setup: self.options.setup = self.build_data.test_setup_default_name diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 824d97b17..1b8ff85f2 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -793,6 +793,26 @@ class AllPlatformTests(BasePlatformTests): self.assertFailedTestCount(2, self.mtest_command + ['--no-suite', 'subprjfail:fail', '--no-suite', 'subprjmix:fail']) + def test_mtest_reconfigure(self): + if self.backend is not Backend.ninja: + raise SkipTest(f'mtest can\'t rebuild with {self.backend.name!r}') + + testdir = os.path.join(self.common_test_dir, '206 tap tests') + self.init(testdir) + self.utime(os.path.join(testdir, 'meson.build')) + o = self._run(self.mtest_command + ['--list']) + self.assertIn('Regenerating build files.', o) + self.assertIn('test_features / xfail', o) + o = self._run(self.mtest_command + ['--list']) + self.assertNotIn('Regenerating build files.', o) + # no real targets should have been built + tester = os.path.join(self.builddir, 'tester' + exe_suffix) + self.assertPathDoesNotExist(tester) + # check that we don't reconfigure if --no-rebuild is passed + self.utime(os.path.join(testdir, 'meson.build')) + o = self._run(self.mtest_command + ['--list', '--no-rebuild']) + self.assertNotIn('Regenerating build files.', o) + def test_build_by_default(self): testdir = os.path.join(self.common_test_dir, '129 build by default') self.init(testdir)