Пример #1
0
def run(args):
    options = parser.parse_args(args)
    if options.target is None or options.filename is None:
        sys.exit("Must specify both target and filename.")
    print('This tool is highly experimental, use with care.')
    rewriter = mesonbuild.astinterpreter.AstInterpreter(options.sourcedir, '')
    try:
        if options.commands[0] == 'add':
            rewriter.add_source(options.target, options.filename)
        elif options.commands[0] == 'remove':
            rewriter.remove_source(options.target, options.filename)
        else:
            sys.exit('Unknown command: ' + options.commands[0])
    except Exception as e:
        if isinstance(e, MesonException):
            if hasattr(e, 'file') and hasattr(e, 'lineno') and hasattr(
                    e, 'colno'):
                mlog.log(
                    mlog.red(
                        '\nMeson encountered an error in file %s, line %d, column %d:'
                        % (e.file, e.lineno, e.colno)))
            else:
                mlog.log(mlog.red('\nMeson encountered an error:'))
            mlog.log(e)
        else:
            traceback.print_exc()
        return 1
    return 0
Пример #2
0
def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('case', type=pathlib.Path, help='The test case to run')
    parser.add_argument('--subtest',
                        type=int,
                        action='append',
                        dest='subtests',
                        help='which subtests to run')
    parser.add_argument('--backend',
                        action='store',
                        help="Which backend to use")
    args = T.cast('ArgumentType', parser.parse_args())

    test = TestDef(args.case, args.case.stem, [])
    tests = load_test_json(test, False)
    if args.subtests:
        tests = [t for i, t in enumerate(tests) if i in args.subtests]

    with mesonlib.TemporaryDirectoryWinProof() as build_dir:
        fake_opts = get_fake_options('/')
        env = environment.Environment(None, build_dir, fake_opts)
        try:
            comp = env.compiler_from_language(
                'c', mesonlib.MachineChoice.HOST).get_id()
        except mesonlib.MesonException:
            raise RuntimeError('Could not detect C compiler')

    backend, backend_args = guess_backend(args.backend,
                                          shutil.which('msbuild'))
    _cmds = get_backend_commands(backend, False)
    commands = (_cmds[0], _cmds[1], _cmds[3], _cmds[4])

    results = [
        run_test(t, t.args, comp, backend, backend_args, commands, False, True)
        for t in tests
    ]
    failed = False
    for test, result in zip(tests, results):
        if result is None:
            msg = mlog.yellow('SKIP:')
        elif result.msg:
            msg = mlog.red('FAIL:')
            failed = True
        else:
            msg = mlog.green('PASS:'******'reason:', result.msg)
            if result.step is BuildStep.configure:
                # 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.
                mlog.log(result.mlog)
            else:
                mlog.log(result.stdo)
            for cmd_res in result.cicmds:
                mlog.log(cmd_res)
            mlog.log(result.stde)

    exit(1 if failed else 0)
Пример #3
0
def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('case', type=pathlib.Path, help='The test case to run')
    parser.add_argument('--subtest', type=int, action='append', dest='subtests', help='which subtests to run')
    parser.add_argument('--backend', action='store', help="Which backend to use")
    parser.add_argument('--cross-file', action='store', help='File describing cross compilation environment.')
    parser.add_argument('--native-file', action='store', help='File describing native compilation environment.')
    parser.add_argument('--use-tmpdir', action='store_true', help='Use tmp directory for temporary files.')
    args = T.cast('ArgumentType', parser.parse_args())

    setup_commands(args.backend)
    detect_system_compiler(args)
    print_tool_versions()

    test = TestDef(args.case, args.case.stem, [])
    tests = load_test_json(test, False)
    if args.subtests:
        tests = [t for i, t in enumerate(tests) if i in args.subtests]

    results = [run_test(t, t.args, '', True) for t in tests]
    failed = False
    for test, result in zip(tests, results):
        if (result is None) or (('MESON_SKIP_TEST' in result.stdo) and (skippable(str(args.case.parent), test.path.as_posix()))):
            msg = mlog.yellow('SKIP:')
        elif result.msg:
            msg = mlog.red('FAIL:')
            failed = True
Пример #4
0
def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('case', type=pathlib.Path, help='The test case to run')
    parser.add_argument('--subtest',
                        type=int,
                        action='append',
                        dest='subtests',
                        help='which subtests to run')
    parser.add_argument('--backend',
                        action='store',
                        help="Which backend to use")
    parser.add_argument('--cross-file',
                        action='store',
                        help='File describing cross compilation environment.')
    parser.add_argument('--native-file',
                        action='store',
                        help='File describing native compilation environment.')
    parser.add_argument('--use-tmpdir',
                        action='store_true',
                        help='Use tmp directory for temporary files.')
    args = T.cast('ArgumentType', parser.parse_args())

    setup_commands(args.backend)
    detect_system_compiler(args)
    print_tool_versions()

    test = TestDef(args.case, args.case.stem, [])
    tests = load_test_json(test, False)
    if args.subtests:
        tests = [t for i, t in enumerate(tests) if i in args.subtests]

    results = [run_test(t, t.args, '', True) for t in tests]
    failed = False
    for test, result in zip(tests, results):
        if (result is None) or ('MESON_SKIP_TEST' in result.stdo):
            msg = mlog.yellow('SKIP:')
        elif result.msg:
            msg = mlog.red('FAIL:')
            failed = True
        else:
            msg = mlog.green('PASS:'******'MESON_SKIP_TEST' not in result.stdo:
            mlog.log('reason:', result.msg)
            if result.step is BuildStep.configure:
                # 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.
                mlog.log(result.mlog)
            else:
                mlog.log(result.stdo)
            for cmd_res in result.cicmds:
                mlog.log(cmd_res)
            mlog.log(result.stde)

    exit(1 if failed else 0)
Пример #5
0
def run(args):
    options = parser.parse_args(args)
    if options.target is None or options.filename is None:
        sys.exit("Must specify both target and filename.")
    print('This tool is highly experimental, use with care.')
    rewriter = mesonbuild.astinterpreter.AstInterpreter(options.sourcedir, '')
    try:
        if options.commands[0] == 'add':
            rewriter.add_source(options.target, options.filename)
        elif options.commands[0] == 'remove':
            rewriter.remove_source(options.target, options.filename)
        else:
            sys.exit('Unknown command: ' + options.commands[0])
    except Exception as e:
        if isinstance(e, MesonException):
            if hasattr(e, 'file') and hasattr(e, 'lineno') and hasattr(e, 'colno'):
                mlog.log(mlog.red('\nMeson encountered an error in file %s, line %d, column %d:' % (e.file, e.lineno, e.colno)))
            else:
                mlog.log(mlog.red('\nMeson encountered an error:'))
            mlog.log(e)
        else:
            traceback.print_exc()
        return 1
    return 0
Пример #6
0
def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('case', type=pathlib.Path, help='The test case to run')
    parser.add_argument('--subtest',
                        type=int,
                        action='append',
                        dest='subtests',
                        help='which subtests to run')
    parser.add_argument('--backend',
                        action='store',
                        help="Which backend to use")
    args = T.cast('ArgumentType', parser.parse_args())

    test = TestDef(args.case, args.case.stem, [])
    tests = load_test_json(test, False)
    if args.subtests:
        tests = [t for i, t in enumerate(tests) if i in args.subtests]

    with mesonlib.TemporaryDirectoryWinProof() as build_dir:
        fake_opts = get_fake_options('/')
        env = environment.Environment(None, build_dir, fake_opts)
        try:
            comp = env.compiler_from_language(
                'c', mesonlib.MachineChoice.HOST).get_id()
        except mesonlib.MesonException:
            raise RuntimeError('Could not detect C compiler')

    backend, backend_args = guess_backend(args.backend,
                                          shutil.which('msbuild'))
    _cmds = get_backend_commands(backend, False)
    commands = (_cmds[0], _cmds[1], _cmds[3], _cmds[4])

    results = [
        run_test(t, t.args, comp, backend, backend_args, commands, False, True)
        for t in tests
    ]
    failed = False
    for test, result in zip(tests, results):
        if (result is None) or (
            ('MESON_SKIP_TEST' in result.stdo) and
            (skippable(str(args.case.parent), test.path.as_posix()))):
            msg = mlog.yellow('SKIP:')
        elif result.msg:
            msg = mlog.red('FAIL:')
            failed = True
Пример #7
0
    def declaration(self, state, args, kwargs):
        if len(args) != 2:
            raise InterpreterException('declaration takes exactly two arguments.')
        check_stringlist(args)

        disabled, required, _ = extract_required_kwarg(kwargs, state.subproject)
        if disabled:
            return ModuleReturnValue(False, [False])

        lang, compiler = self._compiler(state)
        parser = declaration_parsers.get(lang)
        if not parser:
            raise InterpreterException('no declaration parser for language %s' % lang)

        compiler_args = self._compile_args(compiler, state, kwargs)
        compiler_args += compiler.get_werror_args()

        pkg = args[0]
        decl = args[1]

        tree = parser.parse(decl)
        name = extract_declaration_name(tree)
        proto = rewrite_declaration(tree, name)

        check_prototype = not is_lone_identifier(tree)

        if check_prototype:
            checker = prototype_checkers.get(lang)
            if not checker:
                raise InterpreterException('no checker program for language %s' % lang)

            prog = checker(tree, pkg, name)
            ok = compiler.compiles(prog, state.environment, compiler_args, None)
            status = mlog.green('YES') if ok else mlog.red('NO')
            mlog.log('Checking that', mlog.bold(name, True), 'has prototype', mlog.bold(proto, True), ':', status)
        else:
            ok = compiler.has_header_symbol(pkg, name, '', state.environment, compiler_args, None)
            self._checklog('declaration for', name, ok)

        self._set_config_var(state, ok, name, kwargs)
        if not ok and required:
            raise InterpreterException('{} declaration {} required but not found.'.format(lang, name))
        return ModuleReturnValue(ok, [ok])
Пример #8
0
 def _generate_object(self, obj: Object) -> None:
     tags = []
     tags += [{
         ObjectType.ELEMENTARY: mlog.yellow('[elementary]'),
         ObjectType.BUILTIN: mlog.green('[builtin]'),
         ObjectType.MODULE: mlog.blue('[module]'),
         ObjectType.RETURNED: mlog.cyan('[returned]'),
     }[obj.obj_type]]
     if obj.is_container:
         tags += [mlog.red('[container]')]
     mlog.log()
     mlog.log('Object', mlog.bold(obj.name), *tags)
     with my_nested():
         desc = obj.description
         if '\n' in desc:
             desc = desc[:desc.index('\n')]
         mlog.log('Description:', mlog.bold(desc))
         mlog.log('Returned by:', mlog.bold(str([x.name for x in obj.returned_by])))
         mlog.log('Methods:')
         with my_nested():
             for m in obj.methods:
                 self._generate_function(m)
Пример #9
0
def red(text):
    return mlog.red(text).get_text(mlog.colorize_console)
Пример #10
0
def red(text):
    return mlog.red(text).get_text(mlog.colorize_console)
Пример #11
0
                    help='Path to source directory.')
parser.add_argument('--target', default=None,
                    help='Name of target to edit.')
parser.add_argument('--filename', default=None,
                    help='Name of source file to add or remove to target.')
parser.add_argument('commands', nargs='+')

if __name__ == '__main__':
    options = parser.parse_args()
    if options.target is None or options.filename is None:
        sys.exit("Must specify both target and filename.")
    print('This tool is highly experimental, use with care.')
    rewriter = mesonbuild.astinterpreter.AstInterpreter(options.sourcedir, '')
    try:
        if options.commands[0] == 'add':
            rewriter.add_source(options.target, options.filename)
        elif options.commands[0] == 'remove':
            rewriter.remove_source(options.target, options.filename)
        else:
            sys.exit('Unknown command: ' + options.commands[0])
    except Exception as e:
        if isinstance(e, MesonException):
            if hasattr(e, 'file') and hasattr(e, 'lineno') and hasattr(e, 'colno'):
                mlog.log(mlog.red('\nMeson encountered an error in file %s, line %d, column %d:' % (e.file, e.lineno, e.colno)))
            else:
                mlog.log(mlog.red('\nMeson encountered an error:'))
            mlog.log(e)
        else:
            traceback.print_exc()
        sys.exit(1)
Пример #12
0
 def _checklog(self, which, what, ok):
     status = mlog.green('YES') if ok else mlog.red('NO')
     mlog.log('Checking that', which, mlog.bold(what, True), 'exists:', status)
Пример #13
0
def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument('case', type=pathlib.Path, help='The test case to run')
    parser.add_argument('--subtest',
                        type=int,
                        action='append',
                        dest='subtests',
                        help='which subtests to run')
    parser.add_argument('--backend',
                        action='store',
                        help="Which backend to use")
    parser.add_argument('--cross-file',
                        action='store',
                        help='File describing cross compilation environment.')
    parser.add_argument('--native-file',
                        action='store',
                        help='File describing native compilation environment.')
    parser.add_argument('--use-tmpdir',
                        action='store_true',
                        help='Use tmp directory for temporary files.')
    args = T.cast('ArgumentType', parser.parse_args())

    setup_commands(args.backend)
    detect_system_compiler(args)
    print_tool_versions()

    test = TestDef(args.case, args.case.stem, [])
    tests = load_test_json(test, False)
    if args.subtests:
        tests = [t for i, t in enumerate(tests) if i in args.subtests]

    def should_fail(path: pathlib.Path) -> str:
        dir_ = path.parent.stem
        # FIXME: warning tets might not be handled correctly still…
        if dir_.startswith(('failing', 'warning')):
            if ' ' in dir_:
                return dir_.split(' ')[1]
            return 'meson'
        return ''

    results = [
        run_test(t, t.args, should_fail(t.path), args.use_tmpdir)
        for t in tests
    ]
    failed = False
    for test, result in zip(tests, results):
        if result is None:
            is_skipped = True
            skip_reason = 'not run because preconditions were not met'
        else:
            for l in result.stdo.splitlines():
                if test_emits_skip_msg(l):
                    is_skipped = True
                    offset = l.index('MESON_SKIP_TEST') + 16
                    skip_reason = l[offset:].strip()
                    break
            else:
                is_skipped = False
                skip_reason = ''

        if is_skipped:
            msg = mlog.yellow('SKIP:')
        elif result.msg:
            msg = mlog.red('FAIL:')
            failed = True
        else:
            msg = mlog.green('PASS:'******'Reason:'), skip_reason)
        if result is not None and result.msg and 'MESON_SKIP_TEST' not in result.stdo:
            mlog.log('reason:', result.msg)
            if result.step is BuildStep.configure:
                # 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.
                mlog.log(result.mlog)
            else:
                mlog.log(result.stdo)
            for cmd_res in result.cicmds:
                mlog.log(cmd_res)
            mlog.log(result.stde)

    exit(1 if failed else 0)
Пример #14
0
                    help='Name of source file to add or remove to target.')
parser.add_argument('commands', nargs='+')

if __name__ == '__main__':
    options = parser.parse_args()
    if options.target is None or options.filename is None:
        sys.exit("Must specify both target and filename.")
    print('This tool is highly experimental, use with care.')
    rewriter = mesonbuild.astinterpreter.AstInterpreter(options.sourcedir, '')
    try:
        if options.commands[0] == 'add':
            rewriter.add_source(options.target, options.filename)
        elif options.commands[0] == 'remove':
            rewriter.remove_source(options.target, options.filename)
        else:
            sys.exit('Unknown command: ' + options.commands[0])
    except Exception as e:
        if isinstance(e, MesonException):
            if hasattr(e, 'file') and hasattr(e, 'lineno') and hasattr(
                    e, 'colno'):
                mlog.log(
                    mlog.red(
                        '\nMeson encountered an error in file %s, line %d, column %d:'
                        % (e.file, e.lineno, e.colno)))
            else:
                mlog.log(mlog.red('\nMeson encountered an error:'))
            mlog.log(e)
        else:
            traceback.print_exc()
        sys.exit(1)