def detect_tests_to_run(): # Name, subdirectory, skip condition. all_tests = [ ('common', 'common', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-tests', 'failing tests', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', backend is not Backend.ninja or not shutil.which('mcs')), ('vala', 'vala', backend is not Backend.ninja or not shutil.which('valac')), ('rust', 'rust', backend is not Backend.ninja or not shutil.which('rustc')), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objc_compiler()), ('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), ('python3', 'python3', backend is not Backend.ninja), ] gathered_tests = [(name, gather_tests('test cases/' + subdir), skip) for name, subdir, skip in all_tests] if mesonlib.is_windows(): # TODO: Set BOOST_ROOT in .appveyor.yml gathered_tests += [('framework', ['test cases/frameworks/1 boost'], 'BOOST_ROOT' not in os.environ)] elif mesonlib.is_osx() or mesonlib.is_cygwin(): gathered_tests += [('framework', gather_tests('test cases/frameworks'), True)] else: gathered_tests += [('framework', gather_tests('test cases/frameworks'), False)] return gathered_tests
def detect_tests_to_run(): # Name, subdirectory, skip condition. all_tests = [ ('common', 'common', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-test', 'failing test', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', skip_csharp(backend)), ('vala', 'vala', backend is not Backend.ninja or not shutil.which('valac')), ('rust', 'rust', backend is not Backend.ninja or not shutil.which('rustc')), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objc_compiler()), ('objective c++', 'objcpp', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objcpp_compiler()), ('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), ('python3', 'python3', backend is not Backend.ninja), ('fpga', 'fpga', shutil.which('yosys') is None), ('frameworks', 'frameworks', False), ('nasm', 'nasm', False), ] gathered_tests = [(name, gather_tests(Path('test cases', subdir)), skip) for name, subdir, skip in all_tests] return gathered_tests
def detect_tests_to_run(): # Name, subdirectory, skip condition. all_tests = [ ('common', 'common', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-tests', 'failing tests', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', skip_csharp(backend)), ('vala', 'vala', backend is not Backend.ninja or not shutil.which('valac')), ('rust', 'rust', backend is not Backend.ninja or not shutil.which('rustc')), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objc_compiler()), ('objective c++', 'objcpp', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objcpp_compiler()), ('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), ('python3', 'python3', backend is not Backend.ninja), ('fpga', 'fpga', shutil.which('yosys') is None), ('frameworks', 'frameworks', False), ] gathered_tests = [(name, gather_tests('test cases/' + subdir), skip) for name, subdir, skip in all_tests] return gathered_tests
def detect_tests_to_run(): # Name, subdirectory, skip condition. all_tests = [ ('common', 'common', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-tests', 'failing tests', False), ('prebuilt', 'prebuilt', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', backend is not Backend.ninja or not shutil.which('mcs')), ('vala', 'vala', backend is not Backend.ninja or not shutil.which('valac')), ('rust', 'rust', backend is not Backend.ninja or not shutil.which('rustc')), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or mesonlib.is_windows() or not have_objc_compiler()), ('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), ('python3', 'python3', backend is not Backend.ninja), ] gathered_tests = [(name, gather_tests('test cases/' + subdir), skip) for name, subdir, skip in all_tests] if mesonlib.is_windows(): # TODO: Set BOOST_ROOT in .appveyor.yml gathered_tests += [('framework', ['test cases/frameworks/1 boost'], 'BOOST_ROOT' not in os.environ)] elif mesonlib.is_osx() or mesonlib.is_cygwin(): gathered_tests += [('framework', gather_tests('test cases/frameworks'), True)] else: gathered_tests += [('framework', gather_tests('test cases/frameworks'), False)] return gathered_tests
def detect_tests_to_run(only: List[str]) -> List[Tuple[str, List[Path], bool]]: """ Parameters ---------- only: list of str, optional specify names of tests to run Returns ------- gathered_tests: list of tuple of str, list of pathlib.Path, bool tests to run """ # Name, subdirectory, skip condition. all_tests = [ ('cmake', 'cmake', not shutil.which('cmake') or (os.environ.get('compiler') == 'msvc2015' and under_ci)), ('common', 'common', False), ('warning-meson', 'warning', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-test', 'failing test', False), ('kconfig', 'kconfig', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', skip_csharp(backend)), ('vala', 'vala', backend is not Backend.ninja or not shutil.which('valac')), ('rust', 'rust', should_skip_rust()), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or not have_objc_compiler()), ('objective c++', 'objcpp', backend not in (Backend.ninja, Backend.xcode) or not have_objcpp_compiler()), ('fortran', 'fortran', backend is not Backend.ninja or not shutil.which('gfortran')), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), ('cuda', 'cuda', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('nvcc')), ('python3', 'python3', backend is not Backend.ninja), ('python', 'python', backend is not Backend.ninja), ('fpga', 'fpga', shutil.which('yosys') is None), ('frameworks', 'frameworks', False), ('nasm', 'nasm', False), ] if only: names = [t[0] for t in all_tests] ind = [names.index(o) for o in only] all_tests = [all_tests[i] for i in ind] gathered_tests = [(name, gather_tests(Path('test cases', subdir)), skip) for name, subdir, skip in all_tests] return gathered_tests
def detect_tests_to_run(only: T.List[str]) -> T.List[T.Tuple[str, T.List[TestDef], bool]]: """ Parameters ---------- only: list of str, optional specify names of tests to run Returns ------- gathered_tests: list of tuple of str, list of TestDef, bool tests to run """ skip_fortran = not(shutil.which('gfortran') or shutil.which('flang') or shutil.which('pgfortran') or shutil.which('ifort')) # Name, subdirectory, skip condition. all_tests = [ ('cmake', 'cmake', not shutil.which('cmake') or (os.environ.get('compiler') == 'msvc2015' and under_ci)), ('common', 'common', False), ('warning-meson', 'warning', False), ('failing-meson', 'failing', False), ('failing-build', 'failing build', False), ('failing-test', 'failing test', False), ('kconfig', 'kconfig', False), ('platform-osx', 'osx', not mesonlib.is_osx()), ('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), ('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), ('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), ('C#', 'csharp', skip_csharp(backend)), ('vala', 'vala', backend is not Backend.ninja or not shutil.which(os.environ.get('VALAC', 'valac'))), ('rust', 'rust', should_skip_rust(backend)), ('d', 'd', backend is not Backend.ninja or not have_d_compiler()), ('objective c', 'objc', backend not in (Backend.ninja, Backend.xcode) or not have_objc_compiler()), ('objective c++', 'objcpp', backend not in (Backend.ninja, Backend.xcode) or not have_objcpp_compiler()), ('fortran', 'fortran', skip_fortran or backend != Backend.ninja), ('swift', 'swift', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('swiftc')), # CUDA tests on Windows: use Ninja backend: python run_project_tests.py --only cuda --backend ninja ('cuda', 'cuda', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('nvcc')), ('python3', 'python3', backend is not Backend.ninja), ('python', 'python', backend is not Backend.ninja), ('fpga', 'fpga', shutil.which('yosys') is None), ('frameworks', 'frameworks', False), ('nasm', 'nasm', False), ('wasm', 'wasm', shutil.which('emcc') is None or backend is not Backend.ninja), ] names = [t[0] for t in all_tests] assert names == ALL_TESTS, 'argparse("--only", choices=ALL_TESTS) need to be updated to match all_tests names' if only: ind = [names.index(o) for o in only] all_tests = [all_tests[i] for i in ind] gathered_tests = [(name, gather_tests(Path('test cases', subdir)), skip) for name, subdir, skip in all_tests] return gathered_tests
def test_meson_installed(self): # Install meson prefix = self.tmpdir / 'prefix' pylibdir = prefix / get_pypath() bindir = prefix / get_pybindir() pylibdir.mkdir(parents=True) os.environ['PYTHONPATH'] = str(pylibdir) os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] self._run(python_command + ['setup.py', 'install', '--prefix', str(prefix)]) self.assertTrue(pylibdir.is_dir()) self.assertTrue(bindir.is_dir()) # Run `meson` os.chdir('/') if is_windows(): resolved_meson_command = python_command + [str(bindir / 'meson.py')] else: resolved_meson_command = python_command + [str(bindir / 'meson')] # The python configuration on appveyor does not register .py as # a valid extension, so we cannot run `meson` on Windows. builddir = str(self.tmpdir / 'build1') meson_setup = ['meson', 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `/path/to/meson` builddir = str(self.tmpdir / 'build2') if is_windows(): # Cannot run .py directly because of the appveyor configuration, # and the script is named meson.py, not meson meson_setup = python_command + [str(bindir / 'meson.py'), 'setup'] else: meson_setup = [str(bindir / 'meson'), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `python3 -m mesonbuild.mesonmain` resolved_meson_command = python_command + ['-m', 'mesonbuild.mesonmain'] builddir = str(self.tmpdir / 'build3') meson_setup = ['-m', 'mesonbuild.mesonmain', 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) if is_windows(): # Next part requires a shell return # `meson` is a wrapper to `meson.real` resolved_meson_command = python_command + [str(bindir / 'meson.real')] builddir = str(self.tmpdir / 'build4') (bindir / 'meson').rename(bindir / 'meson.real') wrapper = (bindir / 'meson') with open(str(wrapper), 'w') as f: f.write('#!/bin/sh\n\nmeson.real "$@"') wrapper.chmod(0o755) meson_setup = [str(wrapper), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
def detect_tests_to_run(): all_tests = [] all_tests.append(('common', gather_tests('test cases/common'), False)) all_tests.append( ('failing-meson', gather_tests('test cases/failing'), False)) all_tests.append( ('failing-build', gather_tests('test cases/failing build'), False)) all_tests.append( ('failing-tests', gather_tests('test cases/failing tests'), False)) all_tests.append(('prebuilt', gather_tests('test cases/prebuilt'), False)) all_tests.append(('platform-osx', gather_tests('test cases/osx'), False if mesonlib.is_osx() else True)) 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 using_backend('ninja') and not mesonlib.is_osx() and have_java() else True)) all_tests.append( ('C#', gather_tests('test cases/csharp'), False if using_backend('ninja') and shutil.which('mcs') else True)) all_tests.append( ('vala', gather_tests('test cases/vala'), False if using_backend('ninja') and shutil.which('valac') else True)) all_tests.append( ('rust', gather_tests('test cases/rust'), False if using_backend('ninja') and shutil.which('rustc') else True)) all_tests.append( ('d', gather_tests('test cases/d'), False if using_backend('ninja') and have_d_compiler() else True)) all_tests.append( ('objective c', gather_tests('test cases/objc'), False if using_backend( ('ninja', 'xcode')) and not mesonlib.is_windows() else True)) all_tests.append( ('fortran', gather_tests('test cases/fortran'), False if using_backend('ninja') and shutil.which('gfortran') else True)) all_tests.append( ('swift', gather_tests('test cases/swift'), False if using_backend( ('ninja', 'xcode')) and shutil.which('swiftc') else True)) all_tests.append( ('python3', gather_tests('test cases/python3'), False if using_backend('ninja') and shutil.which('python3') else True)) return all_tests
def platform_fix_exe_name(fname): if not fname.endswith('?exe'): return fname fname = fname[:-4] if mesonlib.is_windows(): return fname + '.exe' return fname
def skippable(suite, test): if not under_ci: return True if not suite.endswith('frameworks'): return True # gtk-doc test may be skipped, pending upstream fixes for spaces in # filenames landing in the distro used for CI if test.endswith('10 gtk-doc'): return True # NetCDF is not in the CI image if test.endswith('netcdf'): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Qt is provided on macOS by Homebrew if test.endswith('4 qt') and mesonlib.is_osx(): return False # Other framework tests are allowed to be skipped on other platforms return True
def test_meson_zipapp(self): if is_windows(): raise unittest.SkipTest('NOT IMPLEMENTED') source = Path(__file__).resolve().parent.as_posix() target = self.tmpdir / 'meson.pyz' zipapp.create_archive(source=source, target=target, interpreter=python_command[0], main=None) self._run([target.as_posix(), '--help'])
def skippable(suite, test): if not under_ci: return True if not suite.endswith('frameworks'): return True # gtk-doc test is always skipped pending upstream fixes for spaces in # filenames landing in distros if test.endswith('10 gtk-doc'): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Other framework tests are allowed to be skipped on other platforms return True
def skippable(suite, test): if not under_ci: return True if not suite.endswith('frameworks'): return True # gtk-doc test may be skipped, pending upstream fixes for spaces in # filenames landing in the distro used for CI if test.endswith('10 gtk-doc'): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Other framework tests are allowed to be skipped on other platforms return True
def _cross_file_generator( self, *, needs_exe_wrapper: bool = False, exe_wrapper: T.Optional[T.List[str]] = None) -> str: if is_windows(): raise SkipTest( 'Cannot run this test on non-mingw/non-cygwin windows') return textwrap.dedent(f"""\ [binaries] c = '{shutil.which('gcc' if is_sunos() else 'cc')}' ar = '{shutil.which('ar')}' strip = '{shutil.which('strip')}' exe_wrapper = {str(exe_wrapper) if exe_wrapper is not None else '[]'} [properties] needs_exe_wrapper = {needs_exe_wrapper} [host_machine] system = 'linux' cpu_family = 'x86' cpu = 'i686' endian = 'little' """)
def test_meson_installed(self): # Install meson prefix = self.tmpdir / 'prefix' pylibdir = prefix / get_pypath() bindir = prefix / get_pybindir() pylibdir.mkdir(parents=True) os.environ['PYTHONPATH'] = str(pylibdir) os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] self._run(python_command + ['setup.py', 'install', '--prefix', str(prefix)]) # Check that all the files were installed correctly self.assertTrue(bindir.is_dir()) self.assertTrue(pylibdir.is_dir()) from setup import packages # Extract list of expected python module files expect = set() for pkg in packages: expect.update([p.as_posix() for p in Path(pkg.replace('.', '/')).glob('*.py')]) # Check what was installed, only count files that are inside 'mesonbuild' have = set() for p in Path(pylibdir).glob('**/*.py'): s = p.as_posix() if 'mesonbuild' not in s: continue have.add(s[s.rfind('mesonbuild'):]) self.assertEqual(have, expect) # Run `meson` os.chdir('/') resolved_meson_command = [str(bindir / 'meson')] builddir = str(self.tmpdir / 'build1') meson_setup = ['meson', 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `/path/to/meson` builddir = str(self.tmpdir / 'build2') meson_setup = [str(bindir / 'meson'), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `python3 -m mesonbuild.mesonmain` resolved_meson_command = python_command + ['-m', 'mesonbuild.mesonmain'] builddir = str(self.tmpdir / 'build3') meson_setup = ['-m', 'mesonbuild.mesonmain', 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) if is_windows(): # Next part requires a shell return # `meson` is a wrapper to `meson.real` resolved_meson_command = [str(bindir / 'meson.real')] builddir = str(self.tmpdir / 'build4') (bindir / 'meson').rename(bindir / 'meson.real') wrapper = (bindir / 'meson') wrapper.open('w').write('#!/bin/sh\n\nmeson.real "$@"') wrapper.chmod(0o755) meson_setup = [str(wrapper), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
def test_meson_zipapp(self): if is_windows(): raise unittest.SkipTest('NOT IMPLEMENTED') source = Path(__file__).resolve().parent target = self.tmpdir / 'meson.pyz' script = source / 'packaging' / 'create_zipapp.py' self._run([script.as_posix(), source, '--outfile', target, '--interpreter', python_command[0]]) self._run([target.as_posix(), '--help'])
def should_skip_rust(backend: Backend) -> bool: if not shutil.which('rustc'): return True if backend is not Backend.ninja: return True if mesonlib.is_windows() and has_broken_rustc(): return True return False
def skippable(suite, test): # Everything is optional when not running on CI, or on Ubuntu 16.04 CI if not under_ci or under_xenial_ci: return True if not suite.endswith('frameworks'): return True # this test assumptions aren't valid for Windows paths if test.endswith('38 libdir must be inside prefix'): return True # gtk-doc test may be skipped, pending upstream fixes for spaces in # filenames landing in the distro used for CI if test.endswith('10 gtk-doc'): return True # NetCDF is not in the CI Docker image if test.endswith('netcdf'): return True # MSVC doesn't link with GFortran if test.endswith('14 fortran links c'): return True # Blocks are not supported on all compilers if test.endswith('29 blocks'): return True # Scientific libraries are skippable on certain systems # See the discussion here: https://github.com/mesonbuild/meson/pull/6562 if any([x in test for x in ['17 mpi', '25 hdf5', '30 scalapack'] ]) and skip_scientific: return True # These create OS specific tests, and need to be skippable if any([x in test for x in ['16 sdl', '17 mpi']]): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Qt is provided on macOS by Homebrew if test.endswith('4 qt') and mesonlib.is_osx(): return False # Other framework tests are allowed to be skipped on other platforms return True
def test_meson_installed(self): # Install meson prefix = self.tmpdir / 'prefix' pylibdir = prefix / get_pypath() bindir = prefix / get_pybindir() pylibdir.mkdir(parents=True) # XXX: join with empty name so it always ends with os.sep otherwise # distutils complains that prefix isn't contained in PYTHONPATH os.environ['PYTHONPATH'] = os.path.join(str(pylibdir), '') os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] self._run(python_command + ['setup.py', 'install', '--prefix', str(prefix)]) # Fix importlib-metadata by appending all dirs in pylibdir PYTHONPATHS = [pylibdir] + [x for x in pylibdir.iterdir()] PYTHONPATHS = [os.path.join(str(x), '') for x in PYTHONPATHS] os.environ['PYTHONPATH'] = os.pathsep.join(PYTHONPATHS) # Check that all the files were installed correctly self.assertTrue(bindir.is_dir()) self.assertTrue(pylibdir.is_dir()) # Run `meson` os.chdir('/') resolved_meson_command = [str(bindir / 'meson')] builddir = str(self.tmpdir / 'build1') meson_setup = ['meson', 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `/path/to/meson` builddir = str(self.tmpdir / 'build2') meson_setup = [str(bindir / 'meson'), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Run `python3 -m mesonbuild.mesonmain` resolved_meson_command = python_command + [ '-m', 'mesonbuild.mesonmain' ] builddir = str(self.tmpdir / 'build3') meson_setup = ['-m', 'mesonbuild.mesonmain', 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) if is_windows(): # Next part requires a shell return # `meson` is a wrapper to `meson.real` resolved_meson_command = [str(bindir / 'meson.real')] builddir = str(self.tmpdir / 'build4') (bindir / 'meson').rename(bindir / 'meson.real') wrapper = (bindir / 'meson') wrapper.write_text('#!/bin/sh\n\nmeson.real "$@"', encoding='utf-8') wrapper.chmod(0o755) meson_setup = [str(wrapper), 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
def platform_fix_name(fname): if '?lib' in fname: if mesonlib.is_cygwin(): fname = re.sub(r'\?lib(.*)\.dll$', r'cyg\1.dll', fname) else: fname = re.sub(r'\?lib', 'lib', fname) if fname.endswith('?exe'): fname = fname[:-4] if mesonlib.is_windows() or mesonlib.is_cygwin(): return fname + '.exe' return fname
def platform_fix_filename(fname): if mesonlib.is_osx(): if fname.endswith('.so'): return fname[:-2] + 'dylib' return fname.replace('.so.', '.dylib.') elif mesonlib.is_windows(): if fname.endswith('.so'): (p, f) = os.path.split(fname) f = f[3:-2] + 'dll' return os.path.join(p, f) if fname.endswith('.a'): return fname[:-1] + 'lib' return fname
def main(): # Warn if the locale is not UTF-8. This can cause various unfixable issues # such as os.stat not being able to decode filenames with unicode in them. # There is no way to reset both the preferred encoding and the filesystem # encoding, so we can just warn about it. e = locale.getpreferredencoding() if e.upper() != 'UTF-8' and not mesonlib.is_windows(): print('Warning: You are using {!r} which is not a a Unicode-compatible ' 'locale.'.format(e), file=sys.stderr) print('You might see errors if you use UTF-8 strings as ' 'filenames, as strings, or as file contents.', file=sys.stderr) print('Please switch to a UTF-8 locale for your platform.', file=sys.stderr) # Always resolve the command path so Ninja can find it for regen, tests, etc. launcher = os.path.realpath(sys.argv[0]) return mesonmain.run(sys.argv[1:], launcher)
def skippable(suite, test): # Everything is optional when not running on CI, or on Ubuntu 16.04 CI if not under_ci or under_xenial_ci: return True if not suite.endswith('frameworks'): return True # this test assumptions aren't valid for Windows paths if test.endswith('38 libdir must be inside prefix'): return True # gtk-doc test may be skipped, pending upstream fixes for spaces in # filenames landing in the distro used for CI if test.endswith('10 gtk-doc'): return True # NetCDF is not in the CI Docker image if test.endswith('netcdf'): return True # MSVC doesn't link with GFortran if test.endswith('14 fortran links c'): return True # Blocks are not supported on all compilers if test.endswith('29 blocks'): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Qt is provided on macOS by Homebrew if test.endswith('4 qt') and mesonlib.is_osx(): return False # Other framework tests are allowed to be skipped on other platforms return True
def test_cross_file_system_paths(self): if is_windows(): raise SkipTest( 'system crossfile paths not defined for Windows (yet)') testdir = os.path.join(self.common_test_dir, '1 trivial') cross_content = self._cross_file_generator() with tempfile.TemporaryDirectory() as d: dir_ = os.path.join(d, 'meson', 'cross') os.makedirs(dir_) with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: f.write(cross_content) name = os.path.basename(f.name) with mock.patch.dict(os.environ, {'XDG_DATA_HOME': d}): self.init(testdir, extra_args=['--cross-file=' + name], inprocess=True) self.wipe() with mock.patch.dict(os.environ, {'XDG_DATA_DIRS': d}): os.environ.pop('XDG_DATA_HOME', None) self.init(testdir, extra_args=['--cross-file=' + name], inprocess=True) self.wipe() with tempfile.TemporaryDirectory() as d: dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross') os.makedirs(dir_) with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f: f.write(cross_content) name = os.path.basename(f.name) # If XDG_DATA_HOME is set in the environment running the # tests this test will fail, os mock the environment, pop # it, then test with mock.patch.dict(os.environ): os.environ.pop('XDG_DATA_HOME', None) with mock.patch('mesonbuild.coredata.os.path.expanduser', lambda x: x.replace('~', d)): self.init(testdir, extra_args=['--cross-file=' + name], inprocess=True) self.wipe()
def detect_tests_to_run(): all_tests = [] all_tests.append(('common', gather_tests('test cases/common'), False)) all_tests.append(('failing', gather_tests('test cases/failing'), False)) all_tests.append(('prebuilt object', gather_tests('test cases/prebuilt object'), False)) all_tests.append(('platform-osx', gather_tests('test cases/osx'), False if mesonlib.is_osx() else True)) all_tests.append(('platform-windows', gather_tests('test cases/windows'), False if mesonlib.is_windows() 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() else True)) all_tests.append(('java', gather_tests('test cases/java'), False if not mesonlib.is_osx() and shutil.which('javac') else True)) all_tests.append(('C#', gather_tests('test cases/csharp'), False if shutil.which('mcs') else True)) all_tests.append(('vala', gather_tests('test cases/vala'), False if shutil.which('valac') else True)) all_tests.append(('rust', gather_tests('test cases/rust'), False if shutil.which('rustc') else True)) all_tests.append(('objective c', gather_tests('test cases/objc'), False if not mesonlib.is_windows() else True)) all_tests.append(('fortran', gather_tests('test cases/fortran'), False if shutil.which('gfortran') else True)) all_tests.append(('swift', gather_tests('test cases/swift'), False if shutil.which('swiftc') else True)) return all_tests
def generate_prebuilt(): static_suffix = 'a' if shutil.which('cl'): compiler = 'cl' static_suffix = 'lib' elif shutil.which('cc'): compiler = 'cc' elif shutil.which('gcc'): compiler = 'gcc' else: raise RuntimeError("Could not find C compiler.") if mesonlib.is_windows(): object_suffix = 'obj' else: object_suffix = 'o' objectfile = generate_pb_object(compiler, object_suffix) stlibfile = generate_pb_static(compiler, object_suffix, static_suffix) return (objectfile, stlibfile)
def generate_prebuilt(): static_suffix = 'a' if shutil.which('cl'): compiler = 'cl' static_suffix = 'lib' elif shutil.which('cc'): compiler = 'cc' elif shutil.which('gcc'): compiler = 'gcc' else: raise RuntimeError("Could not find C compiler.") if mesonlib.is_windows(): object_suffix = 'obj' else: object_suffix = 'o' objectfile = generate_pb_object(compiler, object_suffix) stlibfile = generate_pb_static(compiler, object_suffix, static_suffix) return objectfile, stlibfile
def generate_prebuilt_object(): source = 'test cases/prebuilt object/1 basic/source.c' objectbase = 'test cases/prebuilt object/1 basic/prebuilt.' if shutil.which('cl'): objectfile = objectbase + 'obj' cmd = ['cl', '/nologo', '/Fo'+objectfile, '/c', source] else: if mesonlib.is_windows(): objectfile = objectbase + 'obj' else: objectfile = objectbase + 'o' if shutil.which('cc'): cmd = 'cc' elif shutil.which('gcc'): cmd = 'gcc' else: raise RuntimeError("Could not find C compiler.") cmd = [cmd, '-c', source, '-o', objectfile] subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return objectfile
def guess_backend(backend, msbuild_exe): # Auto-detect backend if unspecified backend_flags = [] if backend is None: if msbuild_exe is not None and mesonlib.is_windows(): 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)
def cb(comp): if comp.id == 'lcc': if shutil.which('lfortran'): return 'lfortran', 'lcc' raise SkipTest('No alternate Fortran implementation.') elif comp.id == 'gcc': if shutil.which('ifort'): # There is an ICC for windows (windows build, linux host), # but we don't support that ATM so lets not worry about it. if is_windows(): return 'ifort', 'intel-cl' return 'ifort', 'intel' elif shutil.which('flang'): return 'flang', 'flang' elif shutil.which('pgfortran'): return 'pgfortran', 'pgi' # XXX: there are several other fortran compilers meson # supports, but I don't have any of them to test with raise SkipTest('No alternate Fortran implementation.') if not shutil.which('gfortran'): raise SkipTest('No alternate Fortran implementation.') return 'gfortran', 'gcc'
def guess_backend(backend_str: str, msbuild_exe: str) -> T.Tuple['Backend', T.List[str]]: # Auto-detect backend if unspecified backend_flags = [] if backend_str is None: if msbuild_exe is not None and (mesonlib.is_windows() and not _using_intelcl()): backend_str = 'vs' # Meson will auto-detect VS version to use else: backend_str = 'ninja' # Set backend arguments for Meson if backend_str.startswith('vs'): backend_flags = ['--backend=' + backend_str] backend = Backend.vs elif backend_str == 'xcode': backend_flags = ['--backend=xcode'] backend = Backend.xcode elif backend_str == 'ninja': backend_flags = ['--backend=ninja'] backend = Backend.ninja else: raise RuntimeError(f'Unknown backend: {backend_str!r}') return (backend, backend_flags)
def test_meson_uninstalled(self): # This is what the meson command must be for all these cases resolved_meson_command = python_command + [ str(self.src_root / 'meson.py') ] # Absolute path to meson.py os.chdir('/') builddir = str(self.tmpdir / 'build1') meson_py = str(self.src_root / 'meson.py') meson_setup = [meson_py, 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # ./meson.py os.chdir(str(self.src_root)) builddir = str(self.tmpdir / 'build2') meson_py = './meson.py' meson_setup = [meson_py, 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Symlink to meson.py if is_windows(): # Symlinks require admin perms return os.chdir(str(self.src_root)) builddir = str(self.tmpdir / 'build3') # Create a symlink to meson.py in bindir, and add it to PATH bindir = (self.tmpdir / 'bin') bindir.mkdir() (bindir / 'meson').symlink_to(self.src_root / 'meson.py') os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] # See if it works! meson_py = 'meson' meson_setup = [meson_py, 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
def skippable(suite, test): if not under_ci: return True if not suite.endswith('frameworks'): return True # gtk-doc test may be skipped, pending upstream fixes for spaces in # filenames landing in the distro used for CI if test.endswith('10 gtk-doc'): return True # NetCDF is not in the CI image if test.endswith('netcdf'): return True # MSVC doesn't link with GFortran if test.endswith('14 fortran links c'): return True # No frameworks test should be skipped on linux CI, as we expect all # prerequisites to be installed if mesonlib.is_linux(): return False # Boost test should only be skipped for windows CI build matrix entries # which don't define BOOST_ROOT if test.endswith('1 boost'): if mesonlib.is_windows(): return 'BOOST_ROOT' not in os.environ return False # Qt is provided on macOS by Homebrew if test.endswith('4 qt') and mesonlib.is_osx(): return False # Other framework tests are allowed to be skipped on other platforms return True
def platform_fix_name(fname, compiler): if '?lib' in fname: if mesonlib.is_cygwin(): fname = re.sub(r'\?lib(.*)\.dll$', r'cyg\1.dll', fname) else: fname = re.sub(r'\?lib', 'lib', fname) if fname.endswith('?exe'): fname = fname[:-4] if mesonlib.is_windows() or mesonlib.is_cygwin(): return fname + '.exe' if fname.startswith('?msvc:'): fname = fname[6:] if compiler != 'cl': return None if fname.startswith('?gcc:'): fname = fname[5:] if compiler == 'cl': return None return fname
def test_python_module(self): if is_windows(): # Bat adds extra crap to stdout, so the version check logic in the # python module breaks. This is fine on other OSes because they # don't need the extra indirection. raise SkipTest('bat indirection breaks internal sanity checks.') elif is_osx(): binary = 'python' else: binary = 'python2' # We not have python2, check for it for v in ['2', '2.7', '-2.7']: rc = subprocess.call(['pkg-config', '--cflags', f'python{v}'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) if rc == 0: break else: raise SkipTest( 'Not running Python 2 tests because dev packages not installed.' ) self._simple_test('python', binary, entry='python')
def test_meson_uninstalled(self): # This is what the meson command must be for all these cases resolved_meson_command = python_command + [str(self.src_root / 'meson.py')] # Absolute path to meson.py os.chdir('/') builddir = str(self.tmpdir / 'build1') meson_py = str(self.src_root / 'meson.py') meson_setup = [meson_py, 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # ./meson.py os.chdir(str(self.src_root)) builddir = str(self.tmpdir / 'build2') meson_py = './meson.py' meson_setup = [meson_py, 'setup'] meson_command = python_command + meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command) # Symlink to meson.py if is_windows(): # Symlinks require admin perms return os.chdir(str(self.src_root)) builddir = str(self.tmpdir / 'build3') # Create a symlink to meson.py in bindir, and add it to PATH bindir = (self.tmpdir / 'bin') bindir.mkdir() (bindir / 'meson').symlink_to(self.src_root / 'meson.py') os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH'] # See if it works! meson_py = 'meson' meson_setup = [meson_py, 'setup'] meson_command = meson_setup + self.meson_args stdo = self._run(meson_command + [self.testdir, builddir]) self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
def validate_install(srcdir, installdir): if mesonlib.is_windows(): # Don't really know how Windows installs should work # so skip. return '' info_file = os.path.join(srcdir, 'installed_files.txt') expected = {} found = {} if os.path.exists(info_file): for line in open(info_file): expected[platform_fix_filename(line.strip())] = True for root, _, files in os.walk(installdir): for fname in files: found_name = os.path.join(root, fname)[len(installdir)+1:] found[found_name] = True expected = set(expected) found = set(found) missing = expected - found for fname in missing: return 'Expected file %s missing.' % fname extra = found - expected for fname in extra: return 'Found extra file %s.' % fname return ''
def _using_intelcl() -> bool: """ detect if intending to using Intel-Cl compilers (Intel compilers on Windows) Sufficient evidence of intent is that user is working in the Intel compiler shell environment, otherwise this function returns False """ if not mesonlib.is_windows(): return False # handle where user tried to "blank" MKLROOT and left space(s) if not os.environ.get('MKLROOT', '').strip(): return False if (os.environ.get('CC') == 'icl' or os.environ.get('CXX') == 'icl' or os.environ.get('FC') == 'ifort'): return True # Intel-Cl users might not have the CC,CXX,FC envvars set, # but because they're in Intel shell, the exe's below are on PATH if shutil.which('icl') or shutil.which('ifort'): return True mlog.warning( 'It appears you might be intending to use Intel compiler on Windows ' 'since non-empty environment variable MKLROOT is set to {} ' 'However, Meson cannot find the Intel WIndows compiler executables (icl,ifort).' 'Please try using the Intel shell.'.format(os.environ.get('MKLROOT'))) return False
import time import shutil import subprocess import tempfile import platform from mesonbuild import mesonlib from mesonbuild import mesonmain from mesonbuild import mlog from mesonbuild.environment import detect_ninja from io import StringIO from enum import Enum from glob import glob Backend = Enum('Backend', 'ninja vs xcode') if mesonlib.is_windows() or mesonlib.is_cygwin(): exe_suffix = '.exe' else: exe_suffix = '' def get_backend_args_for_dir(backend, builddir): ''' Visual Studio backend needs to be given the solution to build ''' 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
def _run_tests(all_tests: T.List[T.Tuple[str, T.List[Path], bool]], log_name_base: str, failfast: bool, extra_args: T.List[str]) -> T.Tuple[int, int, int]: global stop, executor, futures, system_compiler xmlname = log_name_base + '.xml' junit_root = ET.Element('testsuites') conf_time = 0 build_time = 0 test_time = 0 passing_tests = 0 failing_tests = 0 skipped_tests = 0 commands = (compile_commands, clean_commands, install_commands, uninstall_commands) try: # This fails in some CI environments for unknown reasons. num_workers = multiprocessing.cpu_count() except Exception as e: print( 'Could not determine number of CPUs due to the following reason:' + str(e)) print('Defaulting to using only one process') num_workers = 1 # Due to Ninja deficiency, almost 50% of build time # is spent waiting. Do something useful instead. # # Remove this once the following issue has been resolved: # https://github.com/mesonbuild/meson/pull/2082 if not mesonlib.is_windows( ): # twice as fast on Windows by *not* multiplying by 2. num_workers *= 2 executor = ProcessPoolExecutor(max_workers=num_workers) for name, test_cases, skipped in all_tests: current_suite = ET.SubElement(junit_root, 'testsuite', { 'name': name, 'tests': str(len(test_cases)) }) print() if skipped: print(bold('Not running %s tests.' % name)) else: print(bold('Running %s tests.' % name)) print() futures = [] for t in test_cases: # Jenkins screws us over by automatically sorting test cases by name # and getting it wrong by not doing logical number sorting. (testnum, testbase) = t.name.split(' ', 1) testname = '%.3d %s' % (int(testnum), testbase) should_fail = False suite_args = [] if name.startswith('failing'): should_fail = name.split('failing-')[1] if name.startswith('warning'): suite_args = ['--fatal-meson-warnings'] should_fail = name.split('warning-')[1] result = executor.submit(run_test, skipped, t.as_posix(), extra_args + suite_args, system_compiler, backend, backend_flags, commands, should_fail) futures.append((testname, t, result)) for (testname, t, result) in futures: sys.stdout.flush() try: result = result.result() except CancelledError: continue if (result is None) or (('MESON_SKIP_TEST' in result.stdo) and (skippable(name, t.as_posix()))): print(yellow('Skipping:'), t.as_posix()) current_test = ET.SubElement(current_suite, 'testcase', { 'name': testname, 'classname': name }) ET.SubElement(current_test, 'skipped', {}) skipped_tests += 1 else: without_install = "" if len( install_commands) > 0 else " (without install)" if result.msg != '': print( red('Failed test{} during {}: {!r}'.format( without_install, result.step.name, t.as_posix()))) print('Reason:', result.msg) failing_tests += 1 if result.step == BuildStep.configure and result.mlog != no_meson_log_msg: # For configure failures, instead of printing stdout, # print the meson log if available since it's a superset # of stdout and often has very useful information. failing_logs.append(result.mlog) elif under_ci: # Always print the complete meson log when running in # a CI. This helps debugging issues that only occur in # a hard to reproduce environment failing_logs.append(result.mlog) failing_logs.append(result.stdo) else: failing_logs.append(result.stdo) for cmd_res in result.cicmds: failing_logs.append(cmd_res) failing_logs.append(result.stde) if failfast: print("Cancelling the rest of the tests") for (_, _, res) in futures: res.cancel() else: print('Succeeded test%s: %s' % (without_install, t.as_posix())) passing_tests += 1 conf_time += result.conftime build_time += result.buildtime test_time += result.testtime total_time = conf_time + build_time + test_time log_text_file(logfile, t, result.stdo, result.stde) current_test = ET.SubElement( current_suite, 'testcase', { 'name': testname, 'classname': name, 'time': '%.3f' % total_time }) if result.msg != '': ET.SubElement(current_test, 'failure', {'message': result.msg}) stdoel = ET.SubElement(current_test, 'system-out') stdoel.text = result.stdo stdeel = ET.SubElement(current_test, 'system-err') stdeel.text = result.stde if failfast and failing_tests > 0: break print("\nTotal configuration time: %.2fs" % conf_time) print("Total build time: %.2fs" % build_time) print("Total test time: %.2fs" % test_time) ET.ElementTree(element=junit_root).write(xmlname, xml_declaration=True, encoding='UTF-8') return passing_tests, failing_tests, skipped_tests
def main(): print_system_info() parser = argparse.ArgumentParser() parser.add_argument('--cov', action='store_true') parser.add_argument('--backend', default=None, dest='backend', choices=backendlist) parser.add_argument('--cross', default=False, dest='cross', action='store_true') parser.add_argument('--failfast', action='store_true') (options, _) = parser.parse_known_args() # Enable coverage early... enable_coverage = options.cov if enable_coverage: os.makedirs('.coverage', exist_ok=True) sys.argv.remove('--cov') import coverage coverage.process_startup() returncode = 0 cross = options.cross 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 'CI' 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(mlog.bold('Running unittests.').get_text(mlog.colorize_console)) print(flush=True) # 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 with tempfile.TemporaryDirectory() as temp_dir: # Enable coverage on all subsequent processes. if enable_coverage: Path(temp_dir, 'usercustomize.py').open('w').write( 'import coverage\n' 'coverage.process_startup()\n') env['COVERAGE_PROCESS_START'] = '.coveragerc' if 'PYTHONPATH' in env: env['PYTHONPATH'] = os.pathsep.join([temp_dir, env.get('PYTHONPATH')]) else: env['PYTHONPATH'] = temp_dir if not cross: cmd = mesonlib.python_command + ['run_meson_command_tests.py', '-v'] if options.failfast: cmd += ['--failfast'] returncode += subprocess.call(cmd, env=env) if options.failfast and returncode != 0: return returncode cmd = mesonlib.python_command + ['run_unittests.py', '-v'] if options.failfast: cmd += ['--failfast'] returncode += subprocess.call(cmd, env=env) if options.failfast and returncode != 0: return returncode cmd = mesonlib.python_command + ['run_project_tests.py'] + sys.argv[1:] returncode += subprocess.call(cmd, env=env) else: cross_test_args = mesonlib.python_command + ['run_cross_test.py'] print(mlog.bold('Running armhf cross tests.').get_text(mlog.colorize_console)) print(flush=True) cmd = cross_test_args + ['cross/ubuntu-armhf.txt'] if options.failfast: cmd += ['--failfast'] returncode += subprocess.call(cmd, env=env) if options.failfast and returncode != 0: return returncode print(mlog.bold('Running mingw-w64 64-bit cross tests.') .get_text(mlog.colorize_console)) print(flush=True) cmd = cross_test_args + ['cross/linux-mingw-w64-64bit.txt'] if options.failfast: cmd += ['--failfast'] returncode += subprocess.call(cmd, env=env) return returncode
opts = get_fake_options(prefix) env = Environment(sdir, bdir, opts) env.coredata.compiler_options.host['c_args'] = FakeCompilerOptions() env.machines.host.cpu_family = 'x86_64' # Used on macOS inside find_library return env Backend = Enum('Backend', 'ninja vs xcode') if 'MESON_EXE' in os.environ: import shlex meson_exe = shlex.split(os.environ['MESON_EXE']) else: meson_exe = None if mesonlib.is_windows() or mesonlib.is_cygwin(): exe_suffix = '.exe' else: exe_suffix = '' def get_meson_script(): ''' Guess the meson that corresponds to the `mesonbuild` that has been imported so we can run configure and other commands in-process, since mesonmain.run needs to know the meson_command to use. Also used by run_unittests.py to determine what meson to run when not running in-process (which is the default). ''' # Is there a meson.py next to the mesonbuild currently in use? mesonbuild_dir = Path(mesonbuild.__file__).resolve().parent.parent
def should_run_cross_mingw_tests(): return shutil.which('x86_64-w64-mingw32-gcc') and not (is_windows() or is_cygwin())