aboutsummaryrefslogtreecommitdiff
path: root/run_tests.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-02-15 18:59:10 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-02-17 14:48:27 -0500
commit62a6c95c133045aaba9262c7bac6f1f55384d614 (patch)
tree1e7eb5aeaaf1da462fb73fd28786fdd8de88abdd /run_tests.py
parent9daaece7850cdd378163cd50bc524693f5294309 (diff)
downloadmeson-62a6c95c133045aaba9262c7bac6f1f55384d614.zip
meson-62a6c95c133045aaba9262c7bac6f1f55384d614.tar.gz
meson-62a6c95c133045aaba9262c7bac6f1f55384d614.tar.bz2
unittests: make ninja detection faster and more robust
Instead of blindly assuming when $CI is set that `ninja` is always correct and always new enough, check for it the same way we do when $CI is not set. Instead of special casing when $CI is set and skipping ninja detection in subprocess tests (by assuming it is always `ninja`), skip detection in subprocess tests all the time, by passing this information around across processes after the first time it is looked up. This means that local (non-CI) tests are faster too! Fixes running unittests in alpine linux using samu. Although ninja is a symlink to samu, the exact output string on no-op builds is different, which we already handle, but what we don't handle is the fact that samu prints a third case when you invoke it as `ninja`. If $CI is exported, then the unittests ignored $NINJA entirely. Fixes running unittests when $CI is set, `samu` exists and `ninja` does not exist. This is not currently the case anywhere, but may be in the future; why not fix it now?
Diffstat (limited to 'run_tests.py')
-rwxr-xr-xrun_tests.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/run_tests.py b/run_tests.py
index 20edf93..6867ce6 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -46,13 +46,13 @@ from mesonbuild.mesonlib import OptionKey, setup_vsenv
NINJA_1_9_OR_NEWER = False
NINJA_CMD = None
-# If we're on CI, just assume we have ninja in PATH and it's new enough because
-# we provide that. This avoids having to detect ninja for every subprocess unit
-# test that we run.
-if 'CI' in os.environ:
- NINJA_1_9_OR_NEWER = True
- NINJA_CMD = ['ninja']
-else:
+# If we're on CI, detecting ninja for every subprocess unit test that we run is slow
+# Optimize this by respecting $NINJA and skipping detection, then exporting it on
+# first run.
+try:
+ NINJA_1_9_OR_NEWER = bool(int(os.environ['NINJA_1_9_OR_NEWER']))
+ NINJA_CMD = [os.environ['NINJA']]
+except (KeyError, ValueError):
# Look for 1.9 to see if https://github.com/ninja-build/ninja/issues/1219
# is fixed
NINJA_CMD = detect_ninja('1.9')
@@ -61,7 +61,11 @@ else:
else:
mlog.warning('Found ninja <1.9, tests will run slower', once=True)
NINJA_CMD = detect_ninja()
-if NINJA_CMD is None:
+
+if NINJA_CMD is not None:
+ os.environ['NINJA_1_9_OR_NEWER'] = str(int(NINJA_1_9_OR_NEWER))
+ os.environ['NINJA'] = NINJA_CMD[0]
+else:
raise RuntimeError('Could not find Ninja v1.7 or newer')
def guess_backend(backend_str: str, msbuild_exe: str) -> T.Tuple['Backend', T.List[str]]: