From d964da79e76b2e75d6fdaa06f48098e54cba8024 Mon Sep 17 00:00:00 2001 From: Niklas Claesson Date: Sat, 30 Jun 2018 21:52:32 +0200 Subject: [PATCH] tests: Merge backend guessing into one function --- run_project_tests.py | 22 ++-------------------- run_tests.py | 40 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index bc36a1d08..647418549 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -41,6 +41,7 @@ import re from run_tests import get_fake_options, run_configure, get_meson_script from run_tests import get_backend_commands, get_backend_args_for_dir, Backend from run_tests import ensure_backend_detects_changes +from run_tests import guess_backend class BuildStep(Enum): @@ -101,26 +102,7 @@ signal.signal(signal.SIGTERM, stop_handler) def setup_commands(optbackend): global do_debug, backend, backend_flags global compile_commands, clean_commands, test_commands, install_commands, uninstall_commands - backend = optbackend - msbuild_exe = shutil.which('msbuild') - # Auto-detect backend if unspecified - if backend is None: - if msbuild_exe is not None: - backend = 'vs' # Meson will auto-detect VS version to use - else: - backend = 'ninja' - # Set backend arguments for Meson - if backend.startswith('vs'): - backend_flags = ['--backend=' + backend] - backend = Backend.vs - elif backend == 'xcode': - backend_flags = ['--backend=xcode'] - backend = Backend.xcode - elif backend == 'ninja': - backend_flags = ['--backend=ninja'] - backend = Backend.ninja - else: - raise RuntimeError('Unknown backend: {!r}'.format(backend)) + backend, backend_flags = guess_backend(optbackend, shutil.which('msbuild')) compile_commands, clean_commands, test_commands, install_commands, \ uninstall_commands = get_backend_commands(backend, do_debug) diff --git a/run_tests.py b/run_tests.py index 7bb601af0..1e03fa75c 100755 --- a/run_tests.py +++ b/run_tests.py @@ -34,6 +34,28 @@ from mesonbuild import mlog from mesonbuild.environment import Environment, detect_ninja from mesonbuild.coredata import backendlist +def guess_backend(backend, msbuild_exe): + # Auto-detect backend if unspecified + backend_flags = [] + if backend is None: + if msbuild_exe is not None: + backend = 'vs' # Meson will auto-detect VS version to use + else: + backend = 'ninja' + # Set backend arguments for Meson + if backend.startswith('vs'): + backend_flags = ['--backend=' + backend] + backend = Backend.vs + elif backend == 'xcode': + backend_flags = ['--backend=xcode'] + backend = Backend.xcode + elif backend == 'ninja': + backend_flags = ['--backend=ninja'] + backend = Backend.ninja + else: + raise RuntimeError('Unknown backend: {!r}'.format(backend)) + return (backend, backend_flags) + # Fake classes and objects for mocking class FakeBuild: @@ -236,24 +258,8 @@ def main(): import coverage coverage.process_startup() returncode = 0 - backend = options.backend cross = options.cross - msbuild_exe = shutil.which('msbuild') - # Auto-detect backend if unspecified - if backend is None: - if msbuild_exe is not None: - backend = 'vs' # Meson will auto-detect VS version to use - else: - backend = 'ninja' - # Set backend arguments for Meson - if backend.startswith('vs'): - backend = Backend.vs - elif backend == 'xcode': - backend = Backend.xcode - elif backend == 'ninja': - backend = Backend.ninja - else: - raise RuntimeError('Unknown backend: {!r}'.format(backend)) + backend, _ = guess_backend(options.backend, shutil.which('msbuild')) # Running on a developer machine? Be nice! if not mesonlib.is_windows() and not mesonlib.is_haiku() and 'TRAVIS' not in os.environ: os.nice(20)