def run(options): b = build.load('.') # This import must be load delayed, otherwise it will get the default # value of None. from mesonbuild.mesonlib import meson_command src_root = b.environment.source_dir bld_root = b.environment.build_dir priv_dir = os.path.join(bld_root, 'meson-private') dist_sub = os.path.join(bld_root, 'meson-dist') dist_name = b.project_name + '-' + b.project_version archives = determine_archives_to_generate(options) _git = os.path.join(src_root, '.git') if os.path.isdir(_git) or os.path.isfile(_git): names = create_dist_git(dist_name, archives, src_root, bld_root, dist_sub, b.dist_scripts) elif os.path.isdir(os.path.join(src_root, '.hg')): names = create_dist_hg(dist_name, archives, src_root, bld_root, dist_sub, b.dist_scripts) else: print('Dist currently only works with Git or Mercurial repos') return 1 if names is None: return 1 # Check only one. rc = check_dist(names[0], meson_command, priv_dir) if rc == 0: for name in names: create_hash(name) return rc
def run(options: 'argparse.Namespace') -> int: bdir = Path(options.wd) validate_builddir(bdir) if options.targets and options.clean: raise MesonException( '`TARGET` and `--clean` can\'t be used simultaneously') cdata = coredata.load(options.wd) b = build.load(options.wd) setup_vsenv(b.need_vsenv) cmd = [] # type: T.List[str] env = None # type: T.Optional[T.Dict[str, str]] backend = cdata.get_option(mesonlib.OptionKey('backend')) assert isinstance(backend, str) if backend == 'ninja': cmd, env = get_parsed_args_ninja(options, bdir) elif backend.startswith('vs'): cmd, env = get_parsed_args_vs(options, bdir) elif backend == 'xcode': cmd, env = get_parsed_args_xcode(options, bdir) else: raise MesonException( f'Backend `{backend}` is not yet supported by `compile`. Use generated project files directly instead.' ) p, *_ = mesonlib.Popen_safe(cmd, stdout=sys.stdout.buffer, stderr=sys.stderr.buffer, env=env) return p.returncode
def run(options): options.wd = os.path.abspath(options.wd) buildfile = Path(options.wd) / 'meson-private' / 'build.dat' if not buildfile.is_file(): raise MesonException( f'Directory {options.wd!r} does not seem to be a Meson build directory.' ) b = build.load(options.wd) # This import must be load delayed, otherwise it will get the default # value of None. from mesonbuild.mesonlib import get_meson_command src_root = b.environment.source_dir bld_root = b.environment.build_dir priv_dir = os.path.join(bld_root, 'meson-private') dist_sub = os.path.join(bld_root, 'meson-dist') dist_name = b.project_name + '-' + b.project_version archives = determine_archives_to_generate(options) subprojects = {} extra_meson_args = [] if options.include_subprojects: subproject_dir = os.path.join(src_root, b.subproject_dir) for sub in b.subprojects: directory = wrap.get_directory(subproject_dir, sub) subprojects[sub] = os.path.join(b.subproject_dir, directory) extra_meson_args.append('-Dwrap_mode=nodownload') if is_git(src_root): names = create_dist_git(dist_name, archives, src_root, bld_root, dist_sub, b.dist_scripts, subprojects) elif is_hg(src_root): if subprojects: print( '--include-subprojects option currently not supported with Mercurial' ) return 1 names = create_dist_hg(dist_name, archives, src_root, bld_root, dist_sub, b.dist_scripts) else: print('Dist currently only works with Git or Mercurial repos') return 1 if names is None: return 1 rc = 0 if not options.no_tests: # Check only one. rc = check_dist(names[0], get_meson_command(), extra_meson_args, bld_root, priv_dir) if rc == 0: for name in names: create_hash(name) print('Created', name) return rc
def run_tests(self, tests): executor = None futures = [] numlen = len('%d' % len(tests)) self.open_log_files() startdir = os.getcwd() if self.options.wd: os.chdir(self.options.wd) self.build_data = build.load(os.getcwd()) try: for _ in range(self.options.repeat): for i, test in enumerate(tests): visible_name = self.get_pretty_suite(test) if not test.is_parallel or self.options.gdb: self.drain_futures(futures) futures = [] single_test = self.get_test_runner(test) res = single_test.run() self.process_test_result(res) self.print_stats(numlen, tests, visible_name, res, i) else: if not executor: executor = conc.ThreadPoolExecutor( max_workers=self.options.num_processes) single_test = self.get_test_runner(test) f = executor.submit(single_test.run) futures.append((f, numlen, tests, visible_name, i)) if self.options.repeat > 1 and self.fail_count: break if self.options.repeat > 1 and self.fail_count: break self.drain_futures(futures) self.print_summary() self.print_collected_logs() if self.logfilename: print('Full log written to %s' % self.logfilename) finally: os.chdir(startdir)
def run_tests(self, tests): executor = None futures = [] numlen = len('%d' % len(tests)) self.open_log_files() startdir = os.getcwd() if self.options.wd: os.chdir(self.options.wd) self.build_data = build.load(os.getcwd()) try: for _ in range(self.options.repeat): for i, test in enumerate(tests): visible_name = self.get_pretty_suite(test) if not test.is_parallel or self.options.gdb: self.drain_futures(futures) futures = [] single_test = self.get_test_runner(test) res = single_test.run() self.process_test_result(res) self.print_stats(numlen, tests, visible_name, res, i) else: if not executor: executor = conc.ThreadPoolExecutor(max_workers=self.options.num_processes) single_test = self.get_test_runner(test) f = executor.submit(single_test.run) futures.append((f, numlen, tests, visible_name, i)) if self.options.repeat > 1 and self.fail_count: break if self.options.repeat > 1 and self.fail_count: break self.drain_futures(futures) self.print_summary() self.print_collected_logs() if self.logfilename: print('Full log written to %s' % self.logfilename) finally: os.chdir(startdir)
def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backend, flags, commands, should_fail): compile_commands, clean_commands, install_commands, uninstall_commands = commands test_args = parse_test_args(testdir) gen_start = time.time() # Configure in-process if pass_prefix_to_test(testdir): gen_args = ['--prefix', '/usr'] else: gen_args = [] if pass_libdir_to_test(testdir): gen_args += ['--libdir', 'lib'] gen_args += [testdir, test_build_dir] + flags + test_args + extra_args nativefile = os.path.join(testdir, 'nativefile.ini') if os.path.exists(nativefile): gen_args.extend(['--native-file', nativefile]) crossfile = os.path.join(testdir, 'crossfile.ini') if os.path.exists(crossfile): gen_args.extend(['--cross-file', crossfile]) (returncode, stdo, stde) = run_configure(gen_args) try: logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() except Exception: mesonlog = no_meson_log_msg gen_time = time.time() - gen_start if should_fail == 'meson': if returncode == 1: return TestResult('', BuildStep.configure, stdo, stde, mesonlog, gen_time) elif returncode != 0: return TestResult( 'Test exited with unexpected status {}'.format(returncode), BuildStep.configure, stdo, stde, mesonlog, gen_time) else: return TestResult('Test that should have failed succeeded', BuildStep.configure, stdo, stde, mesonlog, gen_time) if returncode != 0: return TestResult('Generating the build system failed.', BuildStep.configure, stdo, stde, mesonlog, gen_time) builddata = build.load(test_build_dir) # Touch the meson.build file to force a regenerate so we can test that # regeneration works before a build is run. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) # Build with subprocess dir_args = get_backend_args_for_dir(backend, test_build_dir) build_start = time.time() pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) build_time = time.time() - build_start stdo += o stde += e if should_fail == 'build': if pc.returncode != 0: return TestResult('', BuildStep.build, stdo, stde, mesonlog, gen_time) return TestResult('Test that should have failed to build succeeded', BuildStep.build, stdo, stde, mesonlog, gen_time) if pc.returncode != 0: return TestResult('Compiling source code failed.', BuildStep.build, stdo, stde, mesonlog, gen_time, build_time) # Touch the meson.build file to force a regenerate so we can test that # regeneration works after a build is complete. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) test_start = time.time() # Test in-process (returncode, tstdo, tstde, test_log) = run_test_inprocess(test_build_dir) test_time = time.time() - test_start stdo += tstdo stde += tstde mesonlog += test_log if should_fail == 'test': if returncode != 0: return TestResult('', BuildStep.test, stdo, stde, mesonlog, gen_time) return TestResult( 'Test that should have failed to run unit tests succeeded', BuildStep.test, stdo, stde, mesonlog, gen_time) if returncode != 0: return TestResult('Running unit tests failed.', BuildStep.test, stdo, stde, mesonlog, gen_time, build_time, test_time) # Do installation, if the backend supports it if install_commands: env = os.environ.copy() env['DESTDIR'] = install_dir # Install with subprocess pi, o, e = Popen_safe(install_commands, cwd=test_build_dir, env=env) stdo += o stde += e if pi.returncode != 0: return TestResult('Running install failed.', BuildStep.install, stdo, stde, mesonlog, gen_time, build_time, test_time) # Clean with subprocess env = os.environ.copy() pi, o, e = Popen_safe(clean_commands + dir_args, cwd=test_build_dir, env=env) stdo += o stde += e if pi.returncode != 0: return TestResult('Running clean failed.', BuildStep.clean, stdo, stde, mesonlog, gen_time, build_time, test_time) if not install_commands: return TestResult('', BuildStep.install, '', '', mesonlog, gen_time, build_time, test_time) return TestResult( validate_install(testdir, install_dir, compiler, builddata.environment), BuildStep.validate, stdo, stde, mesonlog, gen_time, build_time, test_time)
def _run_test(test: TestDef, test_build_dir: str, install_dir: str, extra_args, compiler, backend, flags, commands, should_fail): compile_commands, clean_commands, install_commands, uninstall_commands = commands gen_start = time.time() # Configure in-process gen_args = [] # type: T.List[str] if 'prefix' not in test.do_not_set_opts: gen_args += ['--prefix', 'x:/usr' ] if mesonlib.is_windows() else ['--prefix', '/usr'] if 'libdir' not in test.do_not_set_opts: gen_args += ['--libdir', 'lib'] gen_args += [test.path.as_posix(), test_build_dir] + flags + extra_args nativefile = test.path / 'nativefile.ini' crossfile = test.path / 'crossfile.ini' if nativefile.exists(): gen_args.extend(['--native-file', nativefile.as_posix()]) if crossfile.exists(): gen_args.extend(['--cross-file', crossfile.as_posix()]) (returncode, stdo, stde) = run_configure(gen_args, env=test.env) try: logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() except Exception: mesonlog = no_meson_log_msg cicmds = run_ci_commands(mesonlog) testresult = TestResult(cicmds) testresult.add_step(BuildStep.configure, stdo, stde, mesonlog, time.time() - gen_start) if should_fail == 'meson': if returncode == 1: return testresult elif returncode != 0: testresult.fail( 'Test exited with unexpected status {}.'.format(returncode)) return testresult else: testresult.fail('Test that should have failed succeeded.') return testresult if returncode != 0: testresult.fail('Generating the build system failed.') return testresult builddata = build.load(test_build_dir) dir_args = get_backend_args_for_dir(backend, test_build_dir) # Build with subprocess def build_step(): build_start = time.time() pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) testresult.add_step(BuildStep.build, o, e, '', time.time() - build_start) if should_fail == 'build': if pc.returncode != 0: raise testresult testresult.fail('Test that should have failed to build succeeded.') raise testresult if pc.returncode != 0: testresult.fail('Compiling source code failed.') raise testresult # Touch the meson.build file to force a regenerate def force_regenerate(): ensure_backend_detects_changes(backend) os.utime(str(test.path / 'meson.build')) # just test building build_step() # test that regeneration works for build step force_regenerate() build_step() # TBD: assert nothing gets built after the regenerate? # test that regeneration works for test step force_regenerate() # Test in-process test_start = time.time() (returncode, tstdo, tstde, test_log) = run_test_inprocess(test_build_dir) testresult.add_step(BuildStep.test, tstdo, tstde, test_log, time.time() - test_start) if should_fail == 'test': if returncode != 0: return testresult testresult.fail( 'Test that should have failed to run unit tests succeeded.') return testresult if returncode != 0: testresult.fail('Running unit tests failed.') return testresult # Do installation, if the backend supports it if install_commands: env = os.environ.copy() env['DESTDIR'] = install_dir # Install with subprocess pi, o, e = Popen_safe(install_commands, cwd=test_build_dir, env=env) testresult.add_step(BuildStep.install, o, e) if pi.returncode != 0: testresult.fail('Running install failed.') return testresult # Clean with subprocess env = os.environ.copy() pi, o, e = Popen_safe(clean_commands + dir_args, cwd=test_build_dir, env=env) testresult.add_step(BuildStep.clean, o, e) if pi.returncode != 0: testresult.fail('Running clean failed.') return testresult # Validate installed files testresult.add_step(BuildStep.install, '', '') if not install_commands: return testresult install_msg = validate_install(test, Path(install_dir), compiler, builddata.environment) if install_msg: testresult.fail('\n' + install_msg) return testresult return testresult
def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backend, flags, commands, should_fail): compile_commands, clean_commands, install_commands, uninstall_commands = commands test_args = parse_test_args(testdir) gen_start = time.time() setup_env = None # Configure in-process if pass_prefix_to_test(testdir): gen_args = ['--prefix', 'x:/usr' ] if mesonlib.is_windows() else ['--prefix', '/usr'] else: gen_args = [] if pass_libdir_to_test(testdir): gen_args += ['--libdir', 'lib'] gen_args += [testdir, test_build_dir] + flags + test_args + extra_args nativefile = os.path.join(testdir, 'nativefile.ini') if os.path.exists(nativefile): gen_args.extend(['--native-file', nativefile]) crossfile = os.path.join(testdir, 'crossfile.ini') if os.path.exists(crossfile): gen_args.extend(['--cross-file', crossfile]) setup_env_file = os.path.join(testdir, 'setup_env.json') if os.path.exists(setup_env_file): setup_env = os.environ.copy() with open(setup_env_file, 'r') as fp: data = json.load(fp) for key, val in data.items(): val = val.replace('@ROOT@', os.path.abspath(testdir)) setup_env[key] = val (returncode, stdo, stde) = run_configure(gen_args, env=setup_env) try: logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() except Exception: mesonlog = no_meson_log_msg cicmds = run_ci_commands(mesonlog) testresult = TestResult(cicmds) testresult.add_step(BuildStep.configure, stdo, stde, mesonlog, time.time() - gen_start) if should_fail == 'meson': if returncode == 1: return testresult elif returncode != 0: testresult.fail( 'Test exited with unexpected status {}.'.format(returncode)) return testresult else: testresult.fail('Test that should have failed succeeded.') return testresult if returncode != 0: testresult.fail('Generating the build system failed.') return testresult builddata = build.load(test_build_dir) # Touch the meson.build file to force a regenerate so we can test that # regeneration works before a build is run. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) # Build with subprocess dir_args = get_backend_args_for_dir(backend, test_build_dir) build_start = time.time() pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) testresult.add_step(BuildStep.build, o, e, '', time.time() - build_start) if should_fail == 'build': if pc.returncode != 0: return testresult testresult.fail('Test that should have failed to build succeeded.') return testresult if pc.returncode != 0: testresult.fail('Compiling source code failed.') return testresult # Touch the meson.build file to force a regenerate so we can test that # regeneration works after a build is complete. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) test_start = time.time() # Test in-process (returncode, tstdo, tstde, test_log) = run_test_inprocess(test_build_dir) testresult.add_step(BuildStep.test, tstdo, tstde, test_log, time.time() - test_start) if should_fail == 'test': if returncode != 0: return testresult testresult.fail( 'Test that should have failed to run unit tests succeeded.') return testresult if returncode != 0: testresult.fail('Running unit tests failed.') return testresult # Do installation, if the backend supports it if install_commands: env = os.environ.copy() env['DESTDIR'] = install_dir # Install with subprocess pi, o, e = Popen_safe(install_commands, cwd=test_build_dir, env=env) testresult.add_step(BuildStep.install, o, e) if pi.returncode != 0: testresult.fail('Running install failed.') return testresult # Clean with subprocess env = os.environ.copy() pi, o, e = Popen_safe(clean_commands + dir_args, cwd=test_build_dir, env=env) testresult.add_step(BuildStep.clean, o, e) if pi.returncode != 0: testresult.fail('Running clean failed.') return testresult # Validate installed files testresult.add_step(BuildStep.install, '', '') if not install_commands: return testresult install_msg = validate_install(testdir, install_dir, compiler, builddata.environment) if install_msg: testresult.fail(install_msg) return testresult return testresult
def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backend, flags, commands, should_fail): compile_commands, clean_commands, install_commands, uninstall_commands = commands test_args = parse_test_args(testdir) gen_start = time.time() # Configure in-process if pass_prefix_to_test(testdir): gen_args = ['--prefix', '/usr'] else: gen_args = [] if pass_libdir_to_test(testdir): gen_args += ['--libdir', 'lib'] gen_args += [testdir, test_build_dir] + flags + test_args + extra_args (returncode, stdo, stde) = run_configure(gen_args) try: logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt') mesonlog = logfile.open(errors='ignore', encoding='utf-8').read() except Exception: mesonlog = no_meson_log_msg gen_time = time.time() - gen_start if should_fail == 'meson': if returncode == 1: return TestResult('', BuildStep.configure, stdo, stde, mesonlog, gen_time) elif returncode != 0: return TestResult('Test exited with unexpected status {}'.format(returncode), BuildStep.configure, stdo, stde, mesonlog, gen_time) else: return TestResult('Test that should have failed succeeded', BuildStep.configure, stdo, stde, mesonlog, gen_time) if returncode != 0: return TestResult('Generating the build system failed.', BuildStep.configure, stdo, stde, mesonlog, gen_time) builddata = build.load(test_build_dir) # Touch the meson.build file to force a regenerate so we can test that # regeneration works before a build is run. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) # Build with subprocess dir_args = get_backend_args_for_dir(backend, test_build_dir) build_start = time.time() pc, o, e = Popen_safe(compile_commands + dir_args, cwd=test_build_dir) build_time = time.time() - build_start stdo += o stde += e if should_fail == 'build': if pc.returncode != 0: return TestResult('', BuildStep.build, stdo, stde, mesonlog, gen_time) return TestResult('Test that should have failed to build succeeded', BuildStep.build, stdo, stde, mesonlog, gen_time) if pc.returncode != 0: return TestResult('Compiling source code failed.', BuildStep.build, stdo, stde, mesonlog, gen_time, build_time) # Touch the meson.build file to force a regenerate so we can test that # regeneration works after a build is complete. ensure_backend_detects_changes(backend) os.utime(os.path.join(testdir, 'meson.build')) test_start = time.time() # Test in-process (returncode, tstdo, tstde, test_log) = run_test_inprocess(test_build_dir) test_time = time.time() - test_start stdo += tstdo stde += tstde mesonlog += test_log if should_fail == 'test': if returncode != 0: return TestResult('', BuildStep.test, stdo, stde, mesonlog, gen_time) return TestResult('Test that should have failed to run unit tests succeeded', BuildStep.test, stdo, stde, mesonlog, gen_time) if returncode != 0: return TestResult('Running unit tests failed.', BuildStep.test, stdo, stde, mesonlog, gen_time, build_time, test_time) # Do installation, if the backend supports it if install_commands: env = os.environ.copy() env['DESTDIR'] = install_dir # Install with subprocess pi, o, e = Popen_safe(install_commands, cwd=test_build_dir, env=env) stdo += o stde += e if pi.returncode != 0: return TestResult('Running install failed.', BuildStep.install, stdo, stde, mesonlog, gen_time, build_time, test_time) # Clean with subprocess env = os.environ.copy() pi, o, e = Popen_safe(clean_commands + dir_args, cwd=test_build_dir, env=env) stdo += o stde += e if pi.returncode != 0: return TestResult('Running clean failed.', BuildStep.clean, stdo, stde, mesonlog, gen_time, build_time, test_time) if not install_commands: return TestResult('', BuildStep.install, '', '', mesonlog, gen_time, build_time, test_time) return TestResult(validate_install(testdir, install_dir, compiler, builddata.environment), BuildStep.validate, stdo, stde, mesonlog, gen_time, build_time, test_time)