From 4646958917c0a0924c989698c178f849c5c94635 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 6 Apr 2017 04:17:47 +0530 Subject: run_tests: Improve the backend detection --- run_tests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index 02aa701..b444b9a 100755 --- a/run_tests.py +++ b/run_tests.py @@ -20,15 +20,21 @@ import shutil import subprocess import platform from mesonbuild import mesonlib +from enum import Enum -def using_vs_backend(): - for arg in sys.argv[1:]: - if arg.startswith('--backend=vs'): - return True - return False +Backend = Enum('Backend', 'ninja vs xcode') if __name__ == '__main__': returncode = 0 + # Iterate over list in reverse order to find the last --backend arg + backend = Backend.ninja + for arg in reversed(sys.argv[1:]): + if arg.startswith('--backend'): + if arg.startswith('--backend=vs'): + backend = Backend.vs + elif arg == '--backend=xcode': + backend = Backend.xcode + break # Running on a developer machine? Be nice! if not mesonlib.is_windows() and 'TRAVIS' not in os.environ: os.nice(20) @@ -40,7 +46,7 @@ if __name__ == '__main__': units += ['WindowsTests'] # Unit tests always use the Ninja backend, so just skip them if we're # testing the VS backend - if not using_vs_backend(): + if backend is Backend.ninja: returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units) # Ubuntu packages do not have a binary without -6 suffix. if shutil.which('arm-linux-gnueabihf-gcc-6') and not platform.machine().startswith('arm'): -- cgit v1.1 From d755228afe40aff1a2550b161f34cab888d5b995 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 6 Apr 2017 06:56:55 +0530 Subject: tests: Factor out common code to run_tests And use generic build/clean/test/install commands in the unit tests, just like project tests. This sets the groundwork for running the unit tests with all backends. --- run_tests.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index b444b9a..f86c890 100755 --- a/run_tests.py +++ b/run_tests.py @@ -20,10 +20,64 @@ import shutil import subprocess import platform from mesonbuild import mesonlib +from mesonbuild.environment import detect_ninja from enum import Enum Backend = Enum('Backend', 'ninja vs xcode') +if mesonlib.is_windows(): + exe_suffix = '.exe' +else: + exe_suffix = '' + +def get_build_target_args(backend, target): + if target is None: + return [] + if backend.startswith('vs'): + return ['/target:' + target] + if backend == 'xcode': + return ['-target', target] + return [target] + +def get_backend_commands(backend, debug=False): + install_cmd = [] + uninstall_cmd = [] + if backend.startswith('vs'): + cmd = ['msbuild'] + clean_cmd = [] + test_cmd = cmd + ['RUN_TESTS.vcxproj'] + elif backend == 'xcode': + cmd = ['xcodebuild'] + clean_cmd = cmd + ['-alltargets', 'clean'] + test_cmd = cmd + ['-target', 'RUN_TESTS'] + else: + # We need at least 1.6 because of -w dupbuild=err + cmd = [detect_ninja('1.6'), '-w', 'dupbuild=err'] + if cmd[0] is None: + raise RuntimeError('Could not find Ninja v1.6 or newer') + if debug: + cmd += ['-v'] + clean_cmd = cmd + ['clean'] + test_cmd = cmd + ['test', 'benchmark'] + install_cmd = cmd + ['install'] + uninstall_cmd = cmd + ['uninstall'] + return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd + +def get_fake_options(prefix): + import argparse + opts = argparse.Namespace() + opts.cross_file = None + opts.wrap_mode = None + opts.prefix = prefix + return opts + +class FakeEnvironment(object): + def __init__(self): + self.cross_info = None + + def is_cross_build(self): + return False + if __name__ == '__main__': returncode = 0 # Iterate over list in reverse order to find the last --backend arg -- cgit v1.1 From 7e4a67c7906ef736870650031f332a17be6673e6 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 6 Apr 2017 08:00:59 +0530 Subject: run_project_tests: Clean on backends that can't install Also sets more groundwork for running unit tests with backends other that Ninja. Transferring global state to executors is totally broken in Python 3.4 so just serialize all the commands. --- run_tests.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index f86c890..ebccaa6 100755 --- a/run_tests.py +++ b/run_tests.py @@ -22,6 +22,7 @@ import platform from mesonbuild import mesonlib from mesonbuild.environment import detect_ninja from enum import Enum +from glob import glob Backend = Enum('Backend', 'ninja vs xcode') @@ -30,6 +31,15 @@ if mesonlib.is_windows(): else: exe_suffix = '' +def get_backend_args_for_dir(backend, builddir): + ''' + Visual Studio backend needs to be given the solution to build + ''' + if backend.startswith('vs'): + sln_name = glob(os.path.join(builddir, '*.sln'))[0] + return [os.path.split(sln_name)[-1]] + return [] + def get_build_target_args(backend, target): if target is None: return [] @@ -44,7 +54,7 @@ def get_backend_commands(backend, debug=False): uninstall_cmd = [] if backend.startswith('vs'): cmd = ['msbuild'] - clean_cmd = [] + clean_cmd = cmd + ['/target:Clean'] test_cmd = cmd + ['RUN_TESTS.vcxproj'] elif backend == 'xcode': cmd = ['xcodebuild'] -- cgit v1.1 From a331bf1162030c9aedc3b9ad33350fe28b7c35db Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 6 Apr 2017 08:16:08 +0530 Subject: unit tests: Run on all backends, not just Ninja --- run_tests.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index ebccaa6..7ea633e 100755 --- a/run_tests.py +++ b/run_tests.py @@ -40,14 +40,17 @@ def get_backend_args_for_dir(backend, builddir): return [os.path.split(sln_name)[-1]] return [] -def get_build_target_args(backend, target): +def get_builddir_target_args(backend, builddir, target): + dir_args = get_backend_args_for_dir(backend, builddir) if target is None: - return [] + return dir_args if backend.startswith('vs'): - return ['/target:' + target] - if backend == 'xcode': - return ['-target', target] - return [target] + target_args = ['/target:' + target] + elif backend == 'xcode': + target_args = ['-target', target] + else: + target_args = [target] + return target_args + dir_args def get_backend_commands(backend, debug=False): install_cmd = [] @@ -108,10 +111,10 @@ if __name__ == '__main__': units += ['LinuxlikeTests'] elif mesonlib.is_windows(): units += ['WindowsTests'] - # Unit tests always use the Ninja backend, so just skip them if we're - # testing the VS backend - if backend is Backend.ninja: - returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units) + # Can't pass arguments to unit tests, so set the backend to use in the environment + env = os.environ.copy() + env['MESON_UNIT_TEST_BACKEND'] = backend.name + returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units, env=env) # Ubuntu packages do not have a binary without -6 suffix. if shutil.which('arm-linux-gnueabihf-gcc-6') and not platform.machine().startswith('arm'): print('Running cross compilation tests.\n') -- cgit v1.1 From f80d471345e0ece943819ae79e4d85e645e2d1a7 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 8 Apr 2017 09:17:19 +0530 Subject: 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_tests.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index 7ea633e..846fc66 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): -- cgit v1.1 From 4f0d42967e9f672ba4f2bbb5b9eea063490b545c Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 8 Apr 2017 10:54:40 +0530 Subject: tests: Move appveyor platform workaround to run_tests.py This is also needed for the unit tests --- run_tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index 846fc66..a30fd5d 100755 --- a/run_tests.py +++ b/run_tests.py @@ -127,6 +127,21 @@ if __name__ == '__main__': # Running on a developer machine? Be nice! if not mesonlib.is_windows() and 'TRAVIS' not in os.environ: os.nice(20) + # Appveyor sets the `platform` environment variable which completely messes + # up building with the vs2010 and vs2015 backends. + # + # Specifically, MSBuild reads the `platform` environment variable to set + # the configured value for the platform (Win32/x64/arm), which breaks x86 + # builds. + # + # Appveyor setting this also breaks our 'native build arch' detection for + # Windows in environment.py:detect_windows_arch() by overwriting the value + # of `platform` set by vcvarsall.bat. + # + # While building for x86, `platform` should be unset. + if 'APPVEYOR' in os.environ and os.environ['arch'] == 'x86': + os.environ.pop('platform') + # Run tests print('Running unittests.\n') units = ['InternalTests', 'AllPlatformTests'] if mesonlib.is_linux(): -- cgit v1.1 From 5791cb7c4b6e56c18e14ae50e3dbc746c293e36e Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 9 Apr 2017 23:38:58 +0530 Subject: unit tests: exe_suffix is '.exe' on Cygwin --- run_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'run_tests.py') diff --git a/run_tests.py b/run_tests.py index a30fd5d..d0a67e8 100755 --- a/run_tests.py +++ b/run_tests.py @@ -26,7 +26,7 @@ from glob import glob Backend = Enum('Backend', 'ninja vs xcode') -if mesonlib.is_windows(): +if mesonlib.is_windows() or mesonlib.is_cygwin(): exe_suffix = '.exe' else: exe_suffix = '' -- cgit v1.1