Example #1
0
def check(args):
    filename = args[0]

    output = ChunkedIO()
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace, output=output)
    logger.enable_warnings(True)

    transformer = Transformer(namespace)
    transformer.set_include_paths([
        os.path.join(top_srcdir, 'gir'),
        top_builddir,
        os.path.join(top_builddir, 'gir'),
    ])
    transformer.register_include(Include.from_string('GObject-2.0'))

    ss = SourceScanner()

    options = Options()
    exit_code = process_packages(options, ['gobject-2.0'])
    if exit_code:
        sys.exit(exit_code)
    ss.set_cpp_options(options.cpp_includes, options.cpp_defines,
                       options.cpp_undefines)
    ss.parse_files([filename])
    ss.parse_macros([filename])
    transformer.parse(ss.get_symbols())

    cbp = GtkDocCommentBlockParser()
    blocks = cbp.parse_comment_blocks(ss.get_comments())

    main = MainTransformer(transformer, blocks)
    main.transform()

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()]

    expected_warnings = _extract_expected(filename)

    sortkey = lambda x: int(x.split(':')[0])
    expected_warnings.sort(key=sortkey)
    emitted_warnings.sort(key=sortkey)

    if len(expected_warnings) != len(emitted_warnings):
        raise SystemExit("ERROR in '%s': %d warnings were emitted, "
                         "expected %d:\n%s" %
                         (os.path.basename(filename), len(emitted_warnings),
                          len(expected_warnings),
                          _diff(expected_warnings, emitted_warnings)))

    for emitted_warning, expected_warning in zip(emitted_warnings,
                                                 expected_warnings):
        if expected_warning != emitted_warning:
            raise SystemExit(
                "ERROR in '%s': expected warning does not match emitted "
                "warning:\n%s" %
                (filename, _diff([expected_warning], [emitted_warning])))
Example #2
0
def check(args):
    filename = args[0]

    output = StringIO()
    namespace = Namespace("Test", "1.0")
    logger = MessageLogger.get(namespace=namespace, output=output)
    logger.enable_warnings(True)
    transformer = Transformer(namespace)
    transformer.set_include_paths(
        [os.path.join(top_srcdir, 'gir'), top_builddir])
    transformer.register_include(Include.from_string("GObject-2.0"))

    ss = SourceScanner()

    options = Options()
    exit_code = process_packages(options, ['gobject-2.0'])
    if exit_code:
        sys.exit(exit_code)
    ss.set_cpp_options(options.cpp_includes, options.cpp_defines,
                       options.cpp_undefines)
    ss.parse_files([filename])
    ss.parse_macros([filename])
    transformer.parse(ss.get_symbols())

    ap = AnnotationParser()
    blocks = ap.parse(ss.get_comments())

    main = MainTransformer(transformer, blocks)
    main.transform()

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    raw = output.getvalue()
    if raw.endswith('\n'):
        raw = raw[:-1]
    warnings = raw.split('\n')

    failed_tests = 0
    expected_warnings = _extract_expected(filename)
    if '' in warnings:
        warnings.remove('')
    if len(expected_warnings) != len(warnings):
        raise SystemExit(
            "ERROR in %r: expected %d warnings, but got %d:\n"
            "----\nexpected:\n%s\n----\ngot:\n%s\n----" %
            (os.path.basename(filename), len(expected_warnings), len(warnings),
             '\n'.join([w[1] for w in expected_warnings]), '\n'.join(
                 [w.split(':', 2)[2][1:] for w in warnings])))
    for warning, (sort_key, expected) in zip(warnings, expected_warnings):
        actual = warning.split(":", 1)[1]
        if _diff(expected, actual, filename):
            raise SystemExit("ERROR: tests %r failed" % (filename, ))
def check(args):
    filename = args[0]

    output = ChunkedIO()
    namespace = Namespace('Test', '1.0')
    logger = MessageLogger.get(namespace=namespace, output=output)
    logger.enable_warnings((WARNING, ERROR, FATAL))

    transformer = Transformer(namespace)
    transformer.set_include_paths([os.path.join(top_srcdir, 'gir'), top_builddir])
    transformer.register_include(Include.from_string('GObject-2.0'))

    ss = SourceScanner()

    options = Options()
    exit_code = process_packages(options, ['gobject-2.0'])
    if exit_code:
        sys.exit(exit_code)
    ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines)
    ss.parse_files([filename])
    ss.parse_macros([filename])
    transformer.parse(ss.get_symbols())

    cbp = GtkDocCommentBlockParser()
    blocks = cbp.parse_comment_blocks(ss.get_comments())

    main = MainTransformer(transformer, blocks)
    main.transform()

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()]

    expected_warnings = _extract_expected(filename)

    sortkey = lambda x: int(x.split(':')[0])
    expected_warnings.sort(key=sortkey)
    emitted_warnings.sort(key=sortkey)

    if len(expected_warnings) != len(emitted_warnings):
        raise SystemExit("ERROR in '%s': %d warnings were emitted, "
                         "expected %d:\n%s" % (os.path.basename(filename),
                                               len(emitted_warnings),
                                               len(expected_warnings),
                                               _diff(expected_warnings, emitted_warnings)))

    for emitted_warning, expected_warning in zip(emitted_warnings, expected_warnings):
        if expected_warning != emitted_warning:
            raise SystemExit("ERROR in '%s': expected warning does not match emitted "
                             "warning:\n%s" % (filename,
                                               _diff([expected_warning], [emitted_warning])))
def scanner_main(args):
    parser = _get_option_parser()
    (options, args) = parser.parse_args(args)

    if options.passthrough_gir:
        passthrough_gir(options.passthrough_gir, sys.stdout)
    if options.test_codegen:
        return test_codegen(options.test_codegen,
                            options.function_decoration,
                            options.include_first_header,
                            options.include_last_header,
                            options.include_first_src,
                            options.include_last_src)

    if hasattr(options, 'filelist') and not options.filelist:
        if len(args) <= 1:
            _error('Need at least one filename')

    if not options.namespace_name:
        _error('Namespace name missing')

    if options.format == 'gir':
        from giscanner.girwriter import GIRWriter as Writer
    else:
        _error("Unknown format: %s" % (options.format, ))

    if not (options.libraries
            or options.program
            or options.header_only):
        _error("Must specify --program or --library")

    namespace = create_namespace(options)
    logger = message.MessageLogger.get(namespace=namespace)
    if options.warn_all:
        logger.enable_warnings((message.WARNING, message.ERROR, message.FATAL))

    transformer = create_transformer(namespace, options)

    packages = set(options.packages)
    packages.update(transformer.get_pkgconfig_packages())
    if packages:
        exit_code = process_packages(options, packages)
        if exit_code:
            return exit_code

    ss = create_source_scanner(options, args)

    cbp = GtkDocCommentBlockParser()
    blocks = cbp.parse_comment_blocks(ss.get_comments())

    # Transform the C symbols into AST nodes
    transformer.parse(ss.get_symbols())

    if not options.header_only:
        shlibs = create_binary(transformer, options, args)
    else:
        shlibs = []

    transformer.namespace.shared_libraries = shlibs

    main = MainTransformer(transformer, blocks)
    main.transform()

    utils.break_on_debug_flag('tree')

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    warning_count = logger.get_warning_count()
    if options.warn_fatal and warning_count > 0:
        message.fatal("warnings configured as fatal")
        return 1
    elif warning_count > 0 and options.warn_all is False:
        print ("g-ir-scanner: %s: warning: %d warnings suppressed (use --warn-all to see them)"
               % (transformer.namespace.name, warning_count, ))

    # Write out AST
    if options.packages_export:
        exported_packages = options.packages_export
    else:
        exported_packages = options.packages

    transformer.namespace.c_includes = options.c_includes
    transformer.namespace.exported_packages = exported_packages
    writer = Writer(transformer.namespace)
    data = writer.get_xml()

    write_output(data, options)

    return 0
Example #5
0
def scanner_main(args):
    parser = _get_option_parser()
    (options, args) = parser.parse_args(args)

    if options.verbose:
        import distutils
        distutils.log.set_threshold(distutils.log.DEBUG)
    if options.passthrough_gir:
        passthrough_gir(options.passthrough_gir, sys.stdout)
    if options.test_codegen:
        return test_codegen(options.test_codegen,
                            options.function_decoration,
                            options.include_first_header,
                            options.include_last_header,
                            options.include_first_src,
                            options.include_last_src)

    if hasattr(options, 'filelist') and not options.filelist:
        if len(args) <= 1:
            _error('Need at least one filename')

    if not options.namespace_name:
        _error('Namespace name missing')

    if options.format == 'gir':
        from giscanner.girwriter import GIRWriter as Writer
    else:
        _error("Unknown format: %s" % (options.format, ))

    if not (options.libraries
            or options.program
            or options.header_only):
        _error("Must specify --program or --library")

    namespace = create_namespace(options)
    logger = message.MessageLogger.get(namespace=namespace)
    if options.warn_all:
        logger.enable_warnings(True)

    transformer = create_transformer(namespace, options)

    packages = set(options.packages)
    packages.update(transformer.get_pkgconfig_packages())
    if packages:
        try:
            process_packages(options, packages)
        except pkgconfig.PkgConfigError as e:
            _error(str(e))

    ss, filenames = create_source_scanner(options, args)

    cbp = GtkDocCommentBlockParser()
    blocks = cbp.parse_comment_blocks(ss.get_comments())

    # Transform the C symbols into AST nodes
    transformer.parse(ss.get_symbols())

    if not options.header_only:
        shlibs = create_binary(transformer, options, args)
    else:
        shlibs = []

    transformer.namespace.shared_libraries = shlibs

    main = MainTransformer(transformer, blocks)
    main.transform()

    utils.break_on_debug_flag('tree')

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    warning_count = logger.get_warning_count()
    if options.warn_fatal and warning_count > 0:
        message.fatal("warnings configured as fatal")
        return 1
    elif warning_count > 0 and options.warn_all is False and options.quiet is False:
        print("g-ir-scanner: %s: warning: %d warnings suppressed "
              "(use --warn-all to see them)" %
              (transformer.namespace.name, warning_count, ))

    # Write out AST
    if options.packages_export:
        exported_packages = options.packages_export
    else:
        exported_packages = options.packages

    transformer.namespace.c_includes = options.c_includes
    transformer.namespace.exported_packages = exported_packages

    sources_top_dirs = get_source_root_dirs(options, filenames)
    writer = Writer(transformer.namespace, sources_top_dirs)
    data = writer.get_encoded_xml()

    write_output(data, options)

    return 0
Example #6
0
def scanner_main(args):
    parser = _get_option_parser()
    (options, args) = parser.parse_args(args)

    if options.passthrough_gir:
        passthrough_gir(options.passthrough_gir, sys.stdout)
    if options.test_codegen:
        return test_codegen(options.test_codegen)

    if len(args) <= 1:
        _error('Need at least one filename')

    if not options.namespace_name:
        _error('Namespace name missing')

    if options.format == 'gir':
        from giscanner.girwriter import GIRWriter as Writer
    else:
        _error("Unknown format: %s" % (options.format, ))

    if not (options.libraries
            or options.program
            or options.header_only):
        _error("Must specify --program or --library")

    namespace = create_namespace(options)
    logger = message.MessageLogger.get(namespace=namespace)
    if options.warn_all:
        logger.enable_warnings(True)
    transformer = create_transformer(namespace, options)

    packages = set(options.packages)
    packages.update(transformer.get_pkgconfig_packages())
    if packages:
        exit_code = process_packages(options, packages)
        if exit_code:
            return exit_code

    ss = create_source_scanner(options, args)

    ap = AnnotationParser()
    blocks = ap.parse(ss.get_comments())

    # Transform the C symbols into AST nodes
    transformer.set_annotations(blocks)
    transformer.parse(ss.get_symbols())

    if not options.header_only:
        shlibs = create_binary(transformer, options, args)
    else:
        shlibs = []

    main = MainTransformer(transformer, blocks)
    main.transform()

    utils.break_on_debug_flag('tree')

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    warning_count = logger.get_warning_count()
    if options.warn_fatal and warning_count > 0:
        message.fatal("warnings configured as fatal")
        return 1
    elif warning_count > 0 and options.warn_all is False:
        print ("g-ir-scanner: %s: warning: %d warnings suppressed (use --warn-all to see them)"
               % (transformer.namespace.name, warning_count, ))

    # Write out AST
    if options.packages_export:
        exported_packages = options.packages_export
    else:
        exported_packages = options.packages

    writer = Writer(transformer.namespace, shlibs, transformer.get_includes(),
                    exported_packages, options.c_includes)
    data = writer.get_xml()

    write_output(data, options)

    return 0
def scanner_main(args):
    parser = _get_option_parser()
    (options, args) = parser.parse_args(args)

    if options.passthrough_gir:
        passthrough_gir(options.passthrough_gir, sys.stdout)
    if options.test_codegen:
        return test_codegen(options.test_codegen)

    if len(args) <= 1:
        _error('Need at least one filename')

    if not options.namespace_name:
        _error('Namespace name missing')

    if options.format == 'gir':
        from giscanner.girwriter import GIRWriter as Writer
    else:
        _error("Unknown format: %s" % (options.format, ))

    if not (options.libraries or options.program):
        _error("Must specify --program or --library")

    namespace = create_namespace(options)
    logger = message.MessageLogger.get(namespace=namespace)
    if options.warn_all:
        logger.enable_warnings(True)
    transformer = create_transformer(namespace, options)

    packages = set(options.packages)
    packages.update(transformer.get_pkgconfig_packages())
    exit_code = process_packages(options, packages)
    if exit_code:
        return exit_code

    ss = create_source_scanner(options, args)

    ap = AnnotationParser()
    blocks = ap.parse(ss.get_comments())

    # Transform the C symbols into AST nodes
    transformer.set_annotations(blocks)
    transformer.parse(ss.get_symbols())

    shlibs = create_binary(transformer, options, args)

    main = MainTransformer(transformer, blocks)
    main.transform()

    utils.break_on_debug_flag('tree')

    final = IntrospectablePass(transformer, blocks)
    final.validate()

    warning_count = logger.get_warning_count()
    if options.warn_fatal and warning_count > 0:
        message.fatal("warnings configured as fatal")
        return 1
    elif warning_count > 0 and options.warn_all is False:
        print ("g-ir-scanner: %s: warning: %d warnings suppressed (use --warn-all to see them)"
               % (transformer.namespace.name, warning_count, ))

    # Write out AST
    if options.packages_export:
        exported_packages = options.packages_export
    else:
        exported_packages = options.packages

    writer = Writer(transformer.namespace, shlibs, transformer.get_includes(),
                    exported_packages, options.c_includes)
    data = writer.get_xml()

    write_output(data, options)

    return 0