tests: Merge backend guessing into one function

pull/3424/head
Niklas Claesson 7 years ago
parent fb1f0b9694
commit d964da79e7
  1. 22
      run_project_tests.py
  2. 40
      run_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_fake_options, run_configure, get_meson_script
from run_tests import get_backend_commands, get_backend_args_for_dir, Backend 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 ensure_backend_detects_changes
from run_tests import guess_backend
class BuildStep(Enum): class BuildStep(Enum):
@ -101,26 +102,7 @@ signal.signal(signal.SIGTERM, stop_handler)
def setup_commands(optbackend): def setup_commands(optbackend):
global do_debug, backend, backend_flags global do_debug, backend, backend_flags
global compile_commands, clean_commands, test_commands, install_commands, uninstall_commands global compile_commands, clean_commands, test_commands, install_commands, uninstall_commands
backend = optbackend backend, backend_flags = guess_backend(optbackend, shutil.which('msbuild'))
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))
compile_commands, clean_commands, test_commands, install_commands, \ compile_commands, clean_commands, test_commands, install_commands, \
uninstall_commands = get_backend_commands(backend, do_debug) uninstall_commands = get_backend_commands(backend, do_debug)

@ -34,6 +34,28 @@ from mesonbuild import mlog
from mesonbuild.environment import Environment, detect_ninja from mesonbuild.environment import Environment, detect_ninja
from mesonbuild.coredata import backendlist 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 # Fake classes and objects for mocking
class FakeBuild: class FakeBuild:
@ -236,24 +258,8 @@ def main():
import coverage import coverage
coverage.process_startup() coverage.process_startup()
returncode = 0 returncode = 0
backend = options.backend
cross = options.cross cross = options.cross
msbuild_exe = shutil.which('msbuild') backend, _ = guess_backend(options.backend, 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))
# Running on a developer machine? Be nice! # Running on a developer machine? Be nice!
if not mesonlib.is_windows() and not mesonlib.is_haiku() and 'TRAVIS' not in os.environ: if not mesonlib.is_windows() and not mesonlib.is_haiku() and 'TRAVIS' not in os.environ:
os.nice(20) os.nice(20)

Loading…
Cancel
Save