From f80d471345e0ece943819ae79e4d85e645e2d1a7 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 8 Apr 2017 09:17:19 +0530 Subject: [PATCH] unit tests: Fix running specific targets with MSBuild /t:targetname syntax doesn't work, but running the vcxproj does work Also use the Backend enum everywhere. --- run_project_tests.py | 23 +++++++++++++---------- run_tests.py | 40 +++++++++++++++++++++++++++++++--------- run_unittests.py | 6 +++--- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index 51ab5605c..1a16880db 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -34,7 +34,7 @@ import multiprocessing import concurrent.futures as conc import re -from run_tests import get_backend_commands, get_backend_args_for_dir +from run_tests import get_backend_commands, get_backend_args_for_dir, Backend class BuildStep(Enum): @@ -174,10 +174,13 @@ def setup_commands(optbackend): # 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, \ @@ -419,15 +422,15 @@ def detect_tests_to_run(): all_tests.append(('platform-windows', gather_tests('test cases/windows'), False if mesonlib.is_windows() or mesonlib.is_cygwin() else True)) all_tests.append(('platform-linux', gather_tests('test cases/linuxlike'), False if not (mesonlib.is_osx() or mesonlib.is_windows()) else True)) all_tests.append(('framework', gather_tests('test cases/frameworks'), False if not mesonlib.is_osx() and not mesonlib.is_windows() and not mesonlib.is_cygwin() else True)) - all_tests.append(('java', gather_tests('test cases/java'), False if backend == 'ninja' and not mesonlib.is_osx() and have_java() else True)) - all_tests.append(('C#', gather_tests('test cases/csharp'), False if backend == 'ninja' and shutil.which('mcs') else True)) - all_tests.append(('vala', gather_tests('test cases/vala'), False if backend == 'ninja' and shutil.which('valac') else True)) - all_tests.append(('rust', gather_tests('test cases/rust'), False if backend == 'ninja' and shutil.which('rustc') else True)) - all_tests.append(('d', gather_tests('test cases/d'), False if backend == 'ninja' and have_d_compiler() else True)) - all_tests.append(('objective c', gather_tests('test cases/objc'), False if backend in ('ninja', 'xcode') and not mesonlib.is_windows() else True)) - all_tests.append(('fortran', gather_tests('test cases/fortran'), False if backend == 'ninja' and shutil.which('gfortran') else True)) - all_tests.append(('swift', gather_tests('test cases/swift'), False if backend in ('ninja', 'xcode') and shutil.which('swiftc') else True)) - all_tests.append(('python3', gather_tests('test cases/python3'), False if backend == 'ninja' and shutil.which('python3') else True)) + all_tests.append(('java', gather_tests('test cases/java'), False if backend is Backend.ninja and not mesonlib.is_osx() and have_java() else True)) + all_tests.append(('C#', gather_tests('test cases/csharp'), False if backend is Backend.ninja and shutil.which('mcs') else True)) + all_tests.append(('vala', gather_tests('test cases/vala'), False if backend is Backend.ninja and shutil.which('valac') else True)) + all_tests.append(('rust', gather_tests('test cases/rust'), False if backend is Backend.ninja and shutil.which('rustc') else True)) + all_tests.append(('d', gather_tests('test cases/d'), False if backend is Backend.ninja and have_d_compiler() else True)) + all_tests.append(('objective c', gather_tests('test cases/objc'), False if backend in (Backend.ninja, Backend.xcode) and not mesonlib.is_windows() else True)) + all_tests.append(('fortran', gather_tests('test cases/fortran'), False if backend is Backend.ninja and shutil.which('gfortran') else True)) + all_tests.append(('swift', gather_tests('test cases/swift'), False if backend in (Backend.ninja, Backend.xcode) and shutil.which('swiftc') else True)) + all_tests.append(('python3', gather_tests('test cases/python3'), False if backend is Backend.ninja and shutil.which('python3') else True)) return all_tests def run_tests(all_tests, log_name_base, extra_args): diff --git a/run_tests.py b/run_tests.py index 7ea633e33..846fc66ee 100755 --- a/run_tests.py +++ b/run_tests.py @@ -35,35 +35,55 @@ def get_backend_args_for_dir(backend, builddir): ''' Visual Studio backend needs to be given the solution to build ''' - if backend.startswith('vs'): + if backend is Backend.vs: sln_name = glob(os.path.join(builddir, '*.sln'))[0] return [os.path.split(sln_name)[-1]] return [] +def find_vcxproj_with_target(builddir, target): + import re, fnmatch + t, ext = os.path.splitext(target) + if ext: + p = '{}\s*\{}'.format(t, ext) + else: + p = '{}'.format(t) + for root, dirs, files in os.walk(builddir): + for f in fnmatch.filter(files, '*.vcxproj'): + f = os.path.join(builddir, f) + with open(f, 'r', encoding='utf-8') as o: + if re.search(p, o.read(), flags=re.MULTILINE): + return f + raise RuntimeError('No vcxproj matching {!r} in {!r}'.format(p, builddir)) + def get_builddir_target_args(backend, builddir, target): - dir_args = get_backend_args_for_dir(backend, builddir) + dir_args = [] + if not target: + dir_args = get_backend_args_for_dir(backend, builddir) if target is None: return dir_args - if backend.startswith('vs'): - target_args = ['/target:' + target] - elif backend == 'xcode': + if backend is Backend.vs: + vcxproj = find_vcxproj_with_target(builddir, target) + target_args = [vcxproj] + elif backend is Backend.xcode: target_args = ['-target', target] - else: + elif backend is Backend.ninja: target_args = [target] + else: + raise AssertionError('Unknown backend: {!r}'.format(backend)) return target_args + dir_args def get_backend_commands(backend, debug=False): install_cmd = [] uninstall_cmd = [] - if backend.startswith('vs'): + if backend is Backend.vs: cmd = ['msbuild'] clean_cmd = cmd + ['/target:Clean'] test_cmd = cmd + ['RUN_TESTS.vcxproj'] - elif backend == 'xcode': + elif backend is Backend.xcode: cmd = ['xcodebuild'] clean_cmd = cmd + ['-alltargets', 'clean'] test_cmd = cmd + ['-target', 'RUN_TESTS'] - else: + elif backend is Backend.ninja: # We need at least 1.6 because of -w dupbuild=err cmd = [detect_ninja('1.6'), '-w', 'dupbuild=err'] if cmd[0] is None: @@ -74,6 +94,8 @@ def get_backend_commands(backend, debug=False): test_cmd = cmd + ['test', 'benchmark'] install_cmd = cmd + ['install'] uninstall_cmd = cmd + ['uninstall'] + else: + raise AssertionError('Unknown backend: {!r}'.format(backend)) return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd def get_fake_options(prefix): diff --git a/run_unittests.py b/run_unittests.py index f7ac14098..0c7d6c09f 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -29,7 +29,7 @@ from mesonbuild.environment import Environment from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram from run_tests import exe_suffix, get_fake_options, FakeEnvironment -from run_tests import get_builddir_target_args, get_backend_commands +from run_tests import get_builddir_target_args, get_backend_commands, Backend def get_soname(fname): @@ -332,9 +332,9 @@ class BasePlatformTests(unittest.TestCase): self.installdir = os.path.join(self.builddir, 'install') # Get the backend # FIXME: Extract this from argv? - self.backend = os.environ.get('MESON_UNIT_TEST_BACKEND', 'ninja') + self.backend = getattr(Backend, os.environ.get('MESON_UNIT_TEST_BACKEND', 'ninja')) self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py'), - '--backend=' + self.backend] + '--backend=' + self.backend.name] self.mconf_command = [sys.executable, os.path.join(src_root, 'mesonconf.py')] self.mintro_command = [sys.executable, os.path.join(src_root, 'mesonintrospect.py')] self.mtest_command = [sys.executable, os.path.join(src_root, 'mesontest.py'), '-C', self.builddir]