def get_backend_commands(backend, debug=False): install_cmd = [] uninstall_cmd = [] if backend is Backend.vs: cmd = ['msbuild'] clean_cmd = cmd + ['/target:Clean'] test_cmd = cmd + ['RUN_TESTS.vcxproj'] elif backend is Backend.xcode: cmd = ['xcodebuild'] clean_cmd = cmd + ['-alltargets', 'clean'] test_cmd = cmd + ['-target', 'RUN_TESTS'] 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: 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'] else: raise AssertionError('Unknown backend: {!r}'.format(backend)) return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd
def check_dist(packagename, meson_command): print('Testing distribution package %s.' % packagename) unpackdir = tempfile.mkdtemp() builddir = tempfile.mkdtemp() installdir = tempfile.mkdtemp() ninja_bin = detect_ninja() try: tf = tarfile.open(packagename) tf.extractall(unpackdir) srcdir = glob(os.path.join(unpackdir, '*'))[0] if subprocess.call(meson_command + ['--backend=ninja', srcdir, builddir]) != 0: print('Running Meson on distribution package failed') return 1 if subprocess.call([ninja_bin], cwd=builddir) != 0: print('Compiling the distribution package failed.') return 1 if subprocess.call([ninja_bin, 'test'], cwd=builddir) != 0: print('Running unit tests on the distribution package failed.') return 1 myenv = os.environ.copy() myenv['DESTDIR'] = installdir if subprocess.call([ninja_bin, 'install'], cwd=builddir, env=myenv) != 0: print('Installing the distribution package failed.') return 1 finally: shutil.rmtree(unpackdir) shutil.rmtree(builddir) shutil.rmtree(installdir) print('Distribution package %s tested.' % packagename) return 0
def run(options): if len(glob('*')) == 0: autodetect_options(options, sample=True) if not options.language: print('Defaulting to generating a C language project.') options.language = 'c' create_sample(options) else: autodetect_options(options) if os.path.isfile('meson.build') and not options.force: print('meson.build already exists. Use --force to overwrite.') sys.exit(1) create_meson_build(options) if options.build: if os.path.isdir(options.builddir) and options.force: print('Build directory already exists, deleting it.') shutil.rmtree(options.builddir) print('Building...') cmd = mesonlib.meson_command + [options.builddir] err = subprocess.call(cmd) if err: sys.exit(1) cmd = [detect_ninja(), '-C', options.builddir] err = subprocess.call(cmd) if err: sys.exit(1) return 0
def get_backend_commands(backend, debug=False): install_cmd = [] uninstall_cmd = [] if backend is Backend.vs: cmd = ['msbuild'] clean_cmd = cmd + ['/target:Clean'] test_cmd = cmd + ['RUN_TESTS.vcxproj'] elif backend is Backend.xcode: cmd = ['xcodebuild'] # In Xcode9 new build system's clean command fails when using a custom build directory. # Maybe use it when CI uses Xcode10 we can remove '-UseNewBuildSystem=FALSE' clean_cmd = cmd + ['-alltargets', 'clean', '-UseNewBuildSystem=FALSE'] test_cmd = cmd + ['-target', 'RUN_TESTS'] elif backend is Backend.ninja: # We need at least 1.6 because of -w dupbuild=err cmd = [detect_ninja('1.6'), '-w', 'dupbuild=err', '-d', 'explain'] 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'] else: raise AssertionError('Unknown backend: {!r}'.format(backend)) return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd
def setup_commands(backend): global backend_flags, compile_commands, test_commands, install_commands msbuild_exe = shutil.which('msbuild') if backend == 'vs2010' or (backend is None and msbuild_exe is not None): backend_flags = ['--backend=vs2010'] compile_commands = ['msbuild'] test_commands = ['msbuild', 'RUN_TESTS.vcxproj'] install_commands = [] elif backend == 'vs2015': backend_flags = ['--backend=vs2015'] compile_commands = ['msbuild'] test_commands = ['msbuild', 'RUN_TESTS.vcxproj'] install_commands = [] elif backend == 'xcode' or (backend is None and mesonlib.is_osx()): backend_flags = ['--backend=xcode'] compile_commands = ['xcodebuild'] test_commands = ['xcodebuild', '-target', 'RUN_TESTS'] install_commands = [] else: backend_flags = [] ninja_command = environment.detect_ninja() if ninja_command is None: raise RuntimeError('Could not find Ninja executable.') if print_debug: compile_commands = [ninja_command, '-v'] else: compile_commands = [ninja_command] test_commands = [ninja_command, 'test', 'benchmark'] install_commands = [ninja_command, 'install']
def run_special(self): 'Tests run by the user, usually something like "under gdb 1000 times".' if self.is_run: raise RuntimeError('Can not use run_special after a full run.') if os.path.isfile('build.ninja'): subprocess.check_call([environment.detect_ninja(), 'all']) tests = self.get_tests() if not tests: return 0 self.run_tests(tests) return self.fail_count
def rebuild_all(wd): if not os.path.isfile(os.path.join(wd, 'build.ninja')): print("Only ninja backend is supported to rebuild tests before running them.") return True ninja = environment.detect_ninja() if not ninja: print("Can't find ninja, can't rebuild test.") return False p = subprocess.Popen([ninja, '-C', wd]) p.communicate() if p.returncode != 0: print("Could not rebuild") return False return True
def run(args): parser = argparse.ArgumentParser(prog='meson') parser.add_argument("srcfiles", metavar="sourcefile", nargs="*", help="source files. default: all recognized files in current directory") parser.add_argument("-n", "--name", help="project name. default: name of current directory") parser.add_argument("-e", "--executable", help="executable name. default: project name") parser.add_argument("-d", "--deps", help="dependencies, comma-separated") parser.add_argument("-l", "--language", choices=['c', 'cpp'], help="project language. default: autodetected based on source files") parser.add_argument("-b", "--build", help="build after generation", action='store_true') parser.add_argument("--builddir", help="directory for build", default='build') parser.add_argument("-f", "--force", action="store_true", help="force overwrite of existing files and directories.") parser.add_argument('--type', default='executable', choices=['executable', 'library']) parser.add_argument('--version', default='0.1') options = parser.parse_args(args) if len(glob('*')) == 0: autodetect_options(options, sample=True) if not options.language: print('Defaulting to generating a C language project.') options.language = 'c' create_sample(options) else: autodetect_options(options) if os.path.isfile('meson.build') and not options.force: print('meson.build already exists. Use --force to overwrite.') sys.exit(1) create_meson_build(options) if options.build: if os.path.isdir(options.builddir) and options.force: print('Build directory already exists, deleting it.') shutil.rmtree(options.builddir) print('Building...') cmd = mesonlib.meson_command + [options.builddir] err = subprocess.call(cmd) if err: sys.exit(1) cmd = [detect_ninja(), '-C', options.builddir] err = subprocess.call(cmd) if err: sys.exit(1) return 0
def get_backend_commands(backend, debug=False): install_cmd = [] uninstall_cmd = [] if backend is Backend.vs: cmd = ['msbuild'] clean_cmd = cmd + ['/target:Clean'] test_cmd = cmd + ['RUN_TESTS.vcxproj'] elif backend is Backend.xcode: cmd = ['xcodebuild'] # In Xcode9 new build system's clean command fails when using a custom build directory. # Maybe use it when CI uses Xcode10 we can remove '-UseNewBuildSystem=FALSE' clean_cmd = cmd + ['-alltargets', 'clean', '-UseNewBuildSystem=FALSE'] test_cmd = cmd + ['-target', 'RUN_TESTS'] elif backend is Backend.ninja: global NINJA_1_9_OR_NEWER # Look for 1.9 to see if https://github.com/ninja-build/ninja/issues/1219 # is fixed, else require 1.6 for -w dupbuild=err for v in ('1.9', '1.6'): ninja_cmd = detect_ninja(v) if ninja_cmd is not None: if v == '1.9': NINJA_1_9_OR_NEWER = True else: print('Found ninja <1.9, tests will run slower') if 'CI' in os.environ: raise RuntimeError('Require ninja >= 1.9 when running on Meson CI') break cmd = [ninja_cmd, '-w', 'dupbuild=err', '-d', 'explain'] 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'] else: raise AssertionError('Unknown backend: {!r}'.format(backend)) return cmd, clean_cmd, test_cmd, install_cmd, uninstall_cmd
def check_dist(packagename, meson_command, extra_meson_args, bld_root, privdir): print('Testing distribution package %s' % packagename) unpackdir = os.path.join(privdir, 'dist-unpack') builddir = os.path.join(privdir, 'dist-build') installdir = os.path.join(privdir, 'dist-install') for p in (unpackdir, builddir, installdir): if os.path.exists(p): shutil.rmtree(p) os.mkdir(p) ninja_bin = detect_ninja() try: shutil.unpack_archive(packagename, unpackdir) unpacked_files = glob(os.path.join(unpackdir, '*')) assert(len(unpacked_files) == 1) unpacked_src_dir = unpacked_files[0] with open(os.path.join(bld_root, 'meson-info', 'intro-buildoptions.json')) as boptions: meson_command += ['-D{name}={value}'.format(**o) for o in json.load(boptions) if o['name'] not in ['backend', 'install_umask']] meson_command += extra_meson_args if subprocess.call(meson_command + ['--backend=ninja', unpacked_src_dir, builddir]) != 0: print('Running Meson on distribution package failed') return 1 if subprocess.call([ninja_bin], cwd=builddir) != 0: print('Compiling the distribution package failed') return 1 if subprocess.call([ninja_bin, 'test'], cwd=builddir) != 0: print('Running unit tests on the distribution package failed') return 1 myenv = os.environ.copy() myenv['DESTDIR'] = installdir if subprocess.call([ninja_bin, 'install'], cwd=builddir, env=myenv) != 0: print('Installing the distribution package failed') return 1 finally: shutil.rmtree(unpackdir) shutil.rmtree(builddir) shutil.rmtree(installdir) print('Distribution package %s tested' % packagename) return 0
def rebuild_all(self): if not os.path.isfile(os.path.join(self.options.wd, 'build.ninja')): print( "Only ninja backend is supported to rebuilt tests before running them." ) self.cant_rebuild = True return True ninja = environment.detect_ninja() if not ninja: print("Can't find ninja, can't rebuild test.") self.cant_rebuild = True return False p = subprocess.Popen([ninja, '-C', self.options.wd]) (stdo, stde) = p.communicate() if p.returncode != 0: print("Could not rebuild") return False return True
def setUp(self): super().setUp() src_root = os.path.dirname(__file__) self.builddir = tempfile.mkdtemp() self.meson_command = [ sys.executable, os.path.join(src_root, 'meson.py') ] 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.ninja_command = [detect_ninja(), '-C', self.builddir] self.common_test_dir = os.path.join(src_root, 'test cases/common') self.vala_test_dir = os.path.join(src_root, 'test cases/vala') self.framework_test_dir = os.path.join(src_root, 'test cases/frameworks') self.output = b'' self.orig_env = os.environ.copy()
def check_dist(packagename, meson_command, privdir): print('Testing distribution package %s' % packagename) unpackdir = os.path.join(privdir, 'dist-unpack') builddir = os.path.join(privdir, 'dist-build') installdir = os.path.join(privdir, 'dist-install') for p in (unpackdir, builddir, installdir): if os.path.exists(p): shutil.rmtree(p) os.mkdir(p) ninja_bin = detect_ninja() try: tf = tarfile.open(packagename) tf.extractall(unpackdir) srcdir = glob(os.path.join(unpackdir, '*'))[0] if subprocess.call(meson_command + ['--backend=ninja', srcdir, builddir]) != 0: print('Running Meson on distribution package failed') return 1 if subprocess.call([ninja_bin], cwd=builddir) != 0: print('Compiling the distribution package failed') return 1 if subprocess.call([ninja_bin, 'test'], cwd=builddir) != 0: print('Running unit tests on the distribution package failed') return 1 myenv = os.environ.copy() myenv['DESTDIR'] = installdir if subprocess.call([ninja_bin, 'install'], cwd=builddir, env=myenv) != 0: print('Installing the distribution package failed') return 1 finally: shutil.rmtree(unpackdir) shutil.rmtree(builddir) shutil.rmtree(installdir) print('Distribution package %s tested' % packagename) return 0
def run(options) -> int: ''' Here we generate the new Meson sample project. ''' if not Path(options.wd).exists(): sys.exit( 'Project source root directory not found. Run this command in source directory root.' ) os.chdir(options.wd) if not glob('*'): autodetect_options(options, sample=True) if not options.language: print('Defaulting to generating a C language project.') options.language = 'c' create_sample(options) else: autodetect_options(options) if Path('meson.build').is_file() and not options.force: raise SystemExit( 'meson.build already exists. Use --force to overwrite.') create_meson_build(options) if options.build: if Path(options.builddir).is_dir() and options.force: print('Build directory already exists, deleting it.') shutil.rmtree(options.builddir) print('Building...') cmd = mesonlib.meson_command + [options.builddir] ret = subprocess.run(cmd) if ret.returncode: raise SystemExit cmd = detect_ninja() + ['-C', options.builddir] ret = subprocess.run(cmd) if ret.returncode: raise SystemExit return 0
from mesonbuild.environment import Environment, detect_ninja from mesonbuild.coredata import backendlist NINJA_1_9_OR_NEWER = False NINJA_CMD = None # If we're on CI, just assume we have ninja in PATH and it's new enough because # we provide that. This avoids having to detect ninja for every subprocess unit # test that we run. if 'CI' in os.environ: NINJA_1_9_OR_NEWER = True NINJA_CMD = 'ninja' else: # Look for 1.9 to see if https://github.com/ninja-build/ninja/issues/1219 # is fixed, else require 1.6 for -w dupbuild=err for v in ('1.9', '1.6'): NINJA_CMD = detect_ninja(v) if NINJA_CMD is not None: if mesonlib.version_compare(v, '>=1.9'): NINJA_1_9_OR_NEWER = True else: mlog.warning('Found ninja <1.9, tests will run slower', once=True) break if NINJA_CMD is None: raise RuntimeError('Could not find Ninja v1.6 or newer') def guess_backend(backend, msbuild_exe: str): # Auto-detect backend if unspecified backend_flags = [] if backend is None:
1) setup of the cross build is platform specific 2) it can be slow (e.g. when invoking test apps via wine) Eventually migrate to something fancier.''' import os, subprocess, shutil, sys import mesonbuild.environment as environment from run_tests import gather_tests test_build_dir = 'work area' install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir') meson_command = './meson.py' extra_flags = ['--cross-file', sys.argv[1]] ninja_command = environment.detect_ninja() if ninja_command is None: raise RuntimeError('Could not find Ninja executable.') compile_commands = [ninja_command] test_commands = [ninja_command, 'test'] install_commands = [ninja_command, 'install'] def run_test(testdir, should_succeed=True): shutil.rmtree(test_build_dir) shutil.rmtree(install_dir) os.mkdir(test_build_dir) os.mkdir(install_dir) print('Running test: ' + testdir) gen_command = [sys.executable, meson_command, '--prefix', '/usr', '--libdir', 'lib', testdir, test_build_dir] + extra_flags p = subprocess.Popen(gen_command) p.wait()
from mesonbuild import mlog from mesonbuild.environment import Environment, detect_ninja from mesonbuild.coredata import backendlist NINJA_1_9_OR_NEWER = False NINJA_CMD = None # If we're on CI, just assume we have ninja in PATH and it's new enough because # we provide that. This avoids having to detect ninja for every subprocess unit # test that we run. if 'CI' in os.environ: NINJA_1_9_OR_NEWER = True NINJA_CMD = 'ninja' else: # Look for 1.9 to see if https://github.com/ninja-build/ninja/issues/1219 # is fixed NINJA_CMD = detect_ninja('1.9') if NINJA_CMD is not None: NINJA_1_9_OR_NEWER = True else: mlog.warning('Found ninja <1.9, tests will run slower', once=True) NINJA_CMD = detect_ninja() if NINJA_CMD is None: raise RuntimeError('Could not find Ninja v1.7 or newer') def guess_backend(backend, msbuild_exe: str): # Auto-detect backend if unspecified backend_flags = [] if backend is None: if msbuild_exe is not None and (mesonlib.is_windows() and not _using_intelcl()): backend = 'vs' # Meson will auto-detect VS version to use else:
2) it can be slow (e.g. when invoking test apps via wine) Eventually migrate to something fancier.''' import os, subprocess, shutil, sys import mesonbuild.environment as environment from run_tests import gather_tests test_build_dir = 'work area' install_dir = os.path.join( os.path.split(os.path.abspath(__file__))[0], 'install dir') meson_command = './meson.py' extra_flags = ['--cross-file', sys.argv[1]] ninja_command = environment.detect_ninja() if ninja_command is None: raise RuntimeError('Could not find Ninja executable.') compile_commands = [ninja_command] test_commands = [ninja_command, 'test'] install_commands = [ninja_command, 'install'] def run_test(testdir, should_succeed=True): shutil.rmtree(test_build_dir) shutil.rmtree(install_dir) os.mkdir(test_build_dir) os.mkdir(install_dir) print('Running test: ' + testdir) gen_command = [ sys.executable, meson_command, '--prefix', '/usr', '--libdir', 'lib',
def run(args): parser = argparse.ArgumentParser(prog='meson') parser.add_argument( "srcfiles", metavar="sourcefile", nargs="*", help="source files. default: all recognized files in current directory" ) parser.add_argument( "-n", "--name", help="project name. default: name of current directory") parser.add_argument("-e", "--executable", help="executable name. default: project name") parser.add_argument("-d", "--deps", help="dependencies, comma-separated") parser.add_argument( "-l", "--language", choices=['c', 'cpp'], help="project language. default: autodetected based on source files") parser.add_argument("-b", "--build", help="build after generation", action='store_true') parser.add_argument("--builddir", help="directory for build", default='build') parser.add_argument( "-f", "--force", action="store_true", help="force overwrite of existing files and directories.") parser.add_argument('--type', default='executable', choices=['executable', 'library']) parser.add_argument('--version', default='0.1') options = parser.parse_args(args) if len(glob('*')) == 0: autodetect_options(options, sample=True) if not options.language: print('Defaulting to generating a C language project.') options.language = 'c' create_sample(options) else: autodetect_options(options) if os.path.isfile('meson.build') and not options.force: print('meson.build already exists. Use --force to overwrite.') sys.exit(1) create_meson_build(options) if options.build: if os.path.isdir(options.builddir) and options.force: print('Build directory already exists, deleting it.') shutil.rmtree(options.builddir) print('Building...') err = os.system('{} "{}"'.format(' '.join(mesonlib.meson_command), options.builddir)) if err: sys.exit(1) err = os.system('{} -C "{}"'.format(detect_ninja(), options.builddir)) if err: sys.exit(1) return 0