aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2022-08-22 16:18:56 -0700
committerEli Schwartz <eschwartz93@gmail.com>2022-09-04 19:05:14 -0400
commitf501e3b1875fd2c929a8a14771bda3ea4550feed (patch)
treec7cbedc41c97254c0507eba7195dcd163e263c7a /mesonbuild
parent2096e394fcde72184252948a0d77e3a31c3f9b91 (diff)
downloadmeson-f501e3b1875fd2c929a8a14771bda3ea4550feed.zip
meson-f501e3b1875fd2c929a8a14771bda3ea4550feed.tar.gz
meson-f501e3b1875fd2c929a8a14771bda3ea4550feed.tar.bz2
mtest: pull detection of ninja into TestHarness
A later commit will add a second invocation of ninja, no point in having the detection code twice. This changes the exit code in case ninja isn't found from 125 to 127, which seems more appropriate given the justification for returning 125 (to make git bisect run skip that commit). If we can't find ninja we'll not succeed in other commits either.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/mtest.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 23e506d..ba9b065 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -1509,6 +1509,7 @@ class TestHarness:
self.console_logger = ConsoleLogger()
self.loggers.append(self.console_logger)
self.need_console = False
+ self.ninja = None # type: T.List[str]
self.logfile_base = None # type: T.Optional[str]
if self.options.logbase and not self.options.gdb:
@@ -1523,6 +1524,7 @@ class TestHarness:
if namebase:
self.logfile_base += '-' + namebase.replace(' ', '_')
+ self.prepare_build()
self.load_metadata()
ss = set()
@@ -1535,6 +1537,25 @@ class TestHarness:
assert self.console_logger
return self.console_logger
+ def prepare_build(self) -> None:
+ if self.options.no_rebuild:
+ return
+
+ if not (Path(self.options.wd) / 'build.ninja').is_file():
+ print('Only ninja backend is supported to rebuild tests before running them.')
+ # Disable, no point in trying to build anything later
+ self.options.no_rebuild = True
+ return
+
+ self.ninja = environment.detect_ninja()
+ if not self.ninja:
+ print("Can't find ninja, can't rebuild test.")
+ # If ninja can't be found return exit code 127, indicating command
+ # not found for shell, which seems appropriate here. This works
+ # nicely for `git bisect run`, telling it to abort - no point in
+ # continuing if there's no ninja.
+ sys.exit(127)
+
def load_metadata(self) -> None:
startdir = os.getcwd()
try:
@@ -1692,7 +1713,7 @@ class TestHarness:
tests = self.get_tests()
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.ninja, self.options.wd, 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
@@ -1967,21 +1988,14 @@ def list_tests(th: TestHarness) -> bool:
print(th.get_pretty_suite(t))
return not tests
-def rebuild_deps(wd: str, tests: T.List[TestSerialisation]) -> bool:
+def rebuild_deps(ninja: T.List[str], wd: str, tests: T.List[TestSerialisation]) -> bool:
def convert_path_to_target(path: str) -> str:
path = os.path.relpath(path, wd)
if os.sep != '/':
path = path.replace(os.sep, '/')
return path
- if not (Path(wd) / 'build.ninja').is_file():
- print('Only ninja backend is supported to rebuild tests before running them.')
- return True
-
- ninja = environment.detect_ninja()
- if not ninja:
- print("Can't find ninja, can't rebuild test.")
- return False
+ assert len(ninja) > 0
depends = set() # type: T.Set[str]
targets = set() # type: T.Set[str]