예제 #1
0
def main():
    options, tasks = parse_options()

    dispatch_table = {
        # IDL definitions
        'dictionary': bind_gen.generate_dictionaries,
        'enumeration': bind_gen.generate_enumerations,
        'interface': bind_gen.generate_interfaces,
        'union': bind_gen.generate_unions,

        # GN settings
        'generated_bindings_gni': bind_gen.update_generated_bindings_gni,
    }

    for task in tasks:
        if task not in dispatch_table:
            sys.exit("Unknown task: {}".format(task))

    web_idl_database = web_idl.Database.read_from_file(
        options.web_idl_database)
    component_reldirs = {
        web_idl.Component('core'): options.output_core_reldir,
        web_idl.Component('modules'): options.output_modules_reldir,
    }

    bind_gen.init(root_src_dir=options.root_src_dir,
                  root_gen_dir=options.root_gen_dir,
                  component_reldirs=component_reldirs)

    for task in tasks:
        dispatch_table[task](web_idl_database=web_idl_database)
예제 #2
0
def main():
    options, tasks = parse_options()

    dispatch_table = {
        'callback_function': bind_gen.generate_callback_functions,
        'callback_interface': bind_gen.generate_callback_interfaces,
        'dictionary': bind_gen.generate_dictionaries,
        'enumeration': bind_gen.generate_enumerations,
        'interface': bind_gen.generate_interfaces,
        'namespace': bind_gen.generate_namespaces,
        'typedef': bind_gen.generate_typedefs,
        'union': bind_gen.generate_unions,
    }

    for task in tasks:
        if task not in dispatch_table:
            sys.exit("Unknown task: {}".format(task))

    component_reldirs = {
        web_idl.Component('core'): options.output_core_reldir,
        web_idl.Component('modules'): options.output_modules_reldir,
    }
    bind_gen.init(web_idl_database_path=options.web_idl_database,
                  root_src_dir=options.root_src_dir,
                  root_gen_dir=options.root_gen_dir,
                  component_reldirs=component_reldirs)

    task_queue = bind_gen.TaskQueue(single_process=options.single_process)

    for task in tasks:
        dispatch_table[task](task_queue)

    def print_to_console(message):
        out = sys.stdout
        if not out.isatty():
            return
        out.write(message)
        out.flush()

    def report_progress(total, done):
        percentage = (int(float(done) / float(total) *
                          100) if total != 0 else 100)
        message = "Blink-V8 bindings generation: {}% done\r".format(percentage)
        print_to_console(message)

    task_queue.run(report_progress)
    print_to_console("\n")
예제 #3
0
def main():
    options, _ = parse_options()

    filepaths = utilities.read_idl_files_list_from_file(options.idl_list_file)
    parser = blink_idl_parser.BlinkIDLParser()
    ast_group = web_idl.AstGroup(web_idl.Component(options.component))
    for filepath in filepaths:
        ast_group.add_ast_node(blink_idl_parser.parse_file(parser, filepath))
    ast_group.write_to_file(options.output)
예제 #4
0
def main():
    options, args = parse_options()
    if args:
        raise RuntimeError('unknown arguments {}'.format(args))

    filepaths = utilities.read_idl_files_list_from_file(options.idl_list_file)
    parser = blink_idl_parser.BlinkIDLParser()
    ast_group = web_idl.AstGroup(web_idl.Component(options.component))
    for filepath in filepaths:
        ast_group.add_ast_node(blink_idl_parser.parse_file(parser, filepath))
    ast_group.write_to_file(options.output)
예제 #5
0
def main():
    options, tasks = parse_options()

    dispatch_table = {
        'dictionary': bind_gen.generate_dictionaries,
        'enumeration': bind_gen.generate_enumerations,
        'interface': bind_gen.generate_interfaces,
    }

    for task in tasks:
        if task not in dispatch_table:
            sys.exit("Unknown task: {}".format(task))

    web_idl_database = web_idl.Database.read_from_file(
        options.web_idl_database)
    component_reldirs = {
        web_idl.Component('core'): options.output_core_reldir,
        web_idl.Component('modules'): options.output_modules_reldir,
    }
    bind_gen.init(root_src_dir=options.root_src_dir,
                  root_gen_dir=options.root_gen_dir,
                  component_reldirs=component_reldirs)

    task_queue = bind_gen.TaskQueue()

    for task in tasks:
        dispatch_table[task](task_queue=task_queue,
                             web_idl_database=web_idl_database)

    def report_progress(total, done):
        out = sys.stdout
        if not out.isatty():
            return
        if total == 0:
            return
        percentage = int(float(done) / float(total) * 100)
        message = "Blink-V8 bindings generation: {}% done\r".format(percentage)
        out.write(message)
        out.flush()

    task_queue.run(report_progress)
예제 #6
0
def main():
    options, tasks = parse_options()

    dispatch_table = {
        'example': bind_gen.run_example,
    }

    for task in tasks:
        if task not in dispatch_table:
            sys.exit("Unknown task: {}".format(task))

    web_idl_database = web_idl.Database.read_from_file(
        options.web_idl_database)
    output_dirs = {
        web_idl.Component('core'): options.output_dir_core,
        web_idl.Component('modules'): options.output_dir_modules,
    }

    for task in tasks:
        dispatch_table[task](web_idl_database=web_idl_database,
                             output_dirs=output_dirs)
예제 #7
0
    def __init__(self, idl_definition):
        assert self._is_initialized, self._REQUIRE_INIT_MESSAGE

        components = sorted(idl_definition.components)  # "core" < "modules"

        if len(components) == 0:
            assert isinstance(idl_definition, web_idl.Union)
            # Unions of built-in types, e.g. DoubleOrString, do not have a
            # component.
            self._is_cross_components = False
            default_component = web_idl.Component("core")
            self._api_component = default_component
            self._impl_component = default_component
        elif len(components) == 1:
            component = components[0]
            self._is_cross_components = False
            self._api_component = component
            self._impl_component = component
        elif len(components) == 2:
            assert components[0] == "core"
            assert components[1] == "modules"
            self._is_cross_components = True
            # Union does not have to support cross-component code generation
            # because clients of IDL union must be on an upper or same layer to
            # any of union members.
            if isinstance(idl_definition, web_idl.Union):
                self._api_component = components[1]
            else:
                self._api_component = components[0]
            self._impl_component = components[1]
        else:
            assert False

        self._api_dir = self._component_reldirs[self._api_component]
        self._impl_dir = self._component_reldirs[self._impl_component]
        self._api_basename = name_style.file("v8", idl_definition.identifier)
        self._impl_basename = name_style.file("v8", idl_definition.identifier)
        # TODO(peria, yukishiino): Add "v8" prefix to union's files.  Trying to
        # produce the same filepaths with the old bindings generator for the
        # time being.
        if isinstance(idl_definition, web_idl.Union):
            union_class_name = idl_definition.identifier
            union_filepath = _BACKWARD_COMPATIBLE_UNION_FILEPATHS.get(
                union_class_name, union_class_name)
            self._api_basename = name_style.file(union_filepath)
            self._impl_basename = name_style.file(union_filepath)

        if not isinstance(idl_definition, web_idl.Union):
            idl_path = idl_definition.debug_info.location.filepath
            self._blink_dir = posixpath.dirname(idl_path)
            self._blink_basename = name_style.file(
                blink_class_name(idl_definition))
예제 #8
0
def main():
    options, tasks = parse_options()

    dispatch_table = {
        'dictionary': bind_gen.generate_dictionaries,
        'interface': bind_gen.generate_interfaces,
    }

    for task in tasks:
        if task not in dispatch_table:
            sys.exit("Unknown task: {}".format(task))

    web_idl_database = web_idl.Database.read_from_file(
        options.web_idl_database)
    output_dirs = {
        web_idl.Component('core'): options.output_dir_core,
        web_idl.Component('modules'): options.output_dir_modules,
    }

    bind_gen.init(output_dirs)

    for task in tasks:
        dispatch_table[task](web_idl_database=web_idl_database,
                             output_dirs=output_dirs)
예제 #9
0
def main():
    dispatch_table = {
        'callback_function': bind_gen.generate_callback_functions,
        'callback_interface': bind_gen.generate_callback_interfaces,
        'dictionary': bind_gen.generate_dictionaries,
        'enumeration': bind_gen.generate_enumerations,
        'interface': bind_gen.generate_interfaces,
        'namespace': bind_gen.generate_namespaces,
        'observable_array': bind_gen.generate_observable_arrays,
        'typedef': bind_gen.generate_typedefs,
        'union': bind_gen.generate_unions,
    }

    options = parse_options(valid_tasks=dispatch_table.keys())

    output_reldirs = parse_output_reldirs(options.output_reldir)

    component_reldirs = {}
    for component, reldir in output_reldirs.items():
        component_reldirs[web_idl.Component(component)] = reldir

    bind_gen.init(web_idl_database_path=options.web_idl_database,
                  root_src_dir=options.root_src_dir,
                  root_gen_dir=options.root_gen_dir,
                  component_reldirs=component_reldirs,
                  enable_style_format=options.format_generated_files)

    task_queue = bind_gen.TaskQueue(single_process=options.single_process)

    for task in options.tasks:
        dispatch_table[task](task_queue)

    def print_to_console(message):
        out = sys.stdout
        if not out.isatty():
            return
        out.write(message)
        out.flush()

    def report_progress(total, done):
        percentage = (int(float(done) / float(total) *
                          100) if total != 0 else 100)
        message = "Blink-V8 bindings generation: {}% done\r".format(percentage)
        print_to_console(message)

    task_queue.run(report_progress)
    print_to_console("\n")
예제 #10
0
    def __init__(self, idl_definition):
        assert self._is_initialized, self._REQUIRE_INIT_MESSAGE

        if isinstance(idl_definition, web_idl.Dictionary):
            idl_path = PathManager.relpath_to_project_root(
                posixpath.normpath(
                    idl_definition.debug_info.location.filepath))
            idl_basepath, _ = posixpath.splitext(idl_path)
            self._idl_dir, _ = posixpath.split(idl_basepath)
        else:
            self._idl_dir = None

        components = sorted(idl_definition.components)  # "core" < "modules"

        if len(components) == 0:
            assert isinstance(idl_definition, web_idl.Union)
            # Unions of built-in types, e.g. DoubleOrString, do not have a
            # component.
            self._is_cross_components = False
            default_component = web_idl.Component("core")
            self._api_component = default_component
            self._impl_component = default_component
        elif len(components) == 1:
            component = components[0]
            self._is_cross_components = False
            self._api_component = component
            self._impl_component = component
        elif len(components) == 2:
            assert components[0] == "core"
            assert components[1] == "modules"
            self._is_cross_components = True
            self._api_component = components[0]
            self._impl_component = components[1]
        else:
            assert False

        self._api_dir = self._component_reldirs[self._api_component]
        self._impl_dir = self._component_reldirs[self._impl_component]
        self._v8_bind_basename = name_style.file("v8",
                                                 idl_definition.identifier)
        self._blink_basename = name_style.file(
            blink_class_name(idl_definition))
예제 #11
0
    def __init__(self, idl_definition):
        assert self._is_initialized, self._REQUIRE_INIT_MESSAGE

        components = sorted(idl_definition.components)  # "core" < "modules"

        if len(components) == 0:
            assert isinstance(idl_definition, web_idl.Union)
            # Unions of built-in types, e.g. DoubleOrString, do not have a
            # component.
            self._is_cross_components = False
            default_component = web_idl.Component("core")
            self._api_component = default_component
            self._impl_component = default_component
        elif len(components) == 1:
            component = components[0]
            self._is_cross_components = False
            self._api_component = component
            self._impl_component = component
        elif len(components) == 2:
            assert components[0] == "core"
            assert components[1] == "modules"
            self._is_cross_components = True
            self._api_component = components[0]
            self._impl_component = components[1]
        else:
            assert False

        self._api_dir = self._component_reldirs[self._api_component]
        self._impl_dir = self._component_reldirs[self._impl_component]
        self._v8_bind_basename = name_style.file("v8",
                                                 idl_definition.identifier)
        # TODO(peria, yukishiino): Add "v8" prefix to union's files.  Trying to
        # produce the same filepaths with the old bindings generator for the
        # time being.
        if isinstance(idl_definition, web_idl.Union):
            self._v8_bind_basename = name_style.file(idl_definition.identifier)
예제 #12
0
    def __init__(self, idl_definition):
        assert self._is_initialized, self._REQUIRE_INIT_MESSAGE

        components = sorted(idl_definition.components)  # "core" < "modules"

        if len(components) == 0:
            assert isinstance(idl_definition,
                              (web_idl.Union, web_idl.NewUnion))
            # Unions of built-in types, e.g. (double or DOMString), do not have
            # a component.
            self._is_cross_components = False
            default_component = web_idl.Component("core")
            self._api_component = default_component
            self._impl_component = default_component
        elif len(components) == 1:
            component = components[0]
            self._is_cross_components = False
            self._api_component = component
            self._impl_component = component
        elif len(components) == 2:
            assert components[0] == "core"
            assert components[1] == "modules"
            self._is_cross_components = True
            # Union does not support cross-component code generation because
            # clients of IDL union must be on an upper or same layer to any of
            # union members.
            if isinstance(idl_definition, (web_idl.Union, web_idl.NewUnion)):
                self._api_component = components[1]
            else:
                self._api_component = components[0]
            self._impl_component = components[1]
        else:
            assert False

        self._api_dir = self._component_reldirs[self._api_component]
        self._impl_dir = self._component_reldirs[self._impl_component]
        self._api_basename = name_style.file("v8", idl_definition.identifier)
        self._impl_basename = name_style.file("v8", idl_definition.identifier)
        if isinstance(idl_definition, web_idl.NewUnion):
            # In case of IDL unions, underscore is used as a separator of union
            # members, so we don't want any underscore inside a union member.
            # For example, (Foo or Bar or Baz) and (FooBar or Baz) are defined
            # in v8_union_foo_bar_baz.ext and v8_union_foobar_baz.ext
            # respectively.
            #
            # Avoid name_style.file not to make "Int32Array" into
            # "int_32_array".
            filename = "v8_union_{}".format("_".join(
                idl_definition.member_tokens)).lower()
            self._api_basename = filename
            self._impl_basename = filename
        elif isinstance(idl_definition, web_idl.Union):
            union_class_name = idl_definition.identifier
            union_filepath = _BACKWARD_COMPATIBLE_UNION_FILEPATHS.get(
                union_class_name, union_class_name)
            self._api_basename = name_style.file(union_filepath)
            self._impl_basename = name_style.file(union_filepath)

        if isinstance(idl_definition, (web_idl.Union, web_idl.NewUnion)):
            self._blink_dir = None
            self._blink_basename = None
        else:
            idl_path = idl_definition.debug_info.location.filepath
            self._blink_dir = posixpath.dirname(idl_path)
            self._blink_basename = name_style.file(
                blink_class_name(idl_definition))
예제 #13
0
파일: typedef.py 프로젝트: zoritle/chromium
def generate_typedefs_all(filepath_basename):
    assert isinstance(filepath_basename, str)

    web_idl_database = package_initializer().web_idl_database()

    # Components
    c1 = web_idl.Component("core")
    c2 = web_idl.Component("modules")
    components = (c1, c2)

    # Filepaths
    header_path = {}
    for component in components:
        header_path[component] = PathManager.component_path(
            component, "{}.h".format(filepath_basename))

    # Root nodes
    header_node = {}
    for component in components:
        node = ListNode(tail="\n")
        node.set_accumulator(CodeGenAccumulator())
        node.set_renderer(MakoRenderer())
        header_node[component] = node

    # Namespaces
    header_blink_ns = {}
    for component in components:
        node = CxxNamespaceNode(name_style.namespace("blink"))
        header_blink_ns[component] = node

    # Header part (copyright, include directives, and forward declarations)
    for component in components:
        header_node[component].extend([
            make_copyright_header(),
            EmptyNode(),
            enclose_with_header_guard(
                ListNode([
                    make_header_include_directives(
                        header_node[component].accumulator),
                    EmptyNode(),
                    header_blink_ns[component],
                ]), name_style.header_guard(header_path[component])),
        ])
        header_blink_ns[component].body.extend([
            make_forward_declarations(header_node[component].accumulator),
            EmptyNode(),
        ])

    # Implementation parts
    component_selectors = {
        c1: lambda xs: all(c2 not in x.components for x in xs),
        c2: lambda xs: any(c2 in x.components for x in xs),
    }

    all_typedefs = sorted(web_idl_database.typedefs,
                          key=lambda x: x.identifier)
    for component in components:
        header_blink_ns[component].body.extend([
            make_typedefs(all_typedefs, component_selectors[component]),
            EmptyNode(),
        ])

    all_unions = sorted(web_idl_database.new_union_types,
                        key=lambda x: x.identifier)
    for component in components:
        header_blink_ns[component].body.extend([
            make_unions(all_unions, component_selectors[component]),
            EmptyNode(),
        ])

    # Write down to the files.
    for component in components:
        write_code_node_to_file(
            header_node[component],
            PathManager.gen_path_to(header_path[component]))
예제 #14
0
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import web_idl

from .code_node import EmptyNode
from .code_node import ListNode
from .code_node import TextNode
from .codegen_accumulator import CodeGenAccumulator
from .codegen_utils import make_copyright_header
from .codegen_utils import write_code_node_to_file
from .mako_renderer import MakoRenderer
from .path_manager import PathManager

_COMPONENT_CORE = web_idl.Component("core")
_COMPONENT_MODULES = web_idl.Component("modules")


class _FileList(object):
    def __init__(self):
        self._filelist = {
            _COMPONENT_CORE: [],
            _COMPONENT_MODULES: [],
        }

    def add(self, component, filepath):
        assert isinstance(component, web_idl.Component)
        assert isinstance(filepath, str)
        self._filelist[component].append(filepath)