Commit 2da1a1ed authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Auto-generate the build target files

Auto-generate bindings/{core,modules}/v8/generated_bindings.gni
which defines the list of generated source files.

Bug: 839389
Change-Id: Ic4342e392509a613bfc7739c2e0002e627ec528e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022042Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735341}
parent 0ceca87e
...@@ -35,6 +35,7 @@ from . import style_format ...@@ -35,6 +35,7 @@ from . import style_format
from .dictionary import generate_dictionaries from .dictionary import generate_dictionaries
from .enumeration import generate_enumerations from .enumeration import generate_enumerations
from .interface import generate_interfaces from .interface import generate_interfaces
from .output_file_list import update_generated_bindings_gni
from .path_manager import PathManager from .path_manager import PathManager
from .union import generate_unions from .union import generate_unions
......
...@@ -173,7 +173,7 @@ class CodeGenContext(object): ...@@ -173,7 +173,7 @@ class CodeGenContext(object):
idl_def = self.member_like or self.idl_definition idl_def = self.member_like or self.idl_definition
if idl_def and not isinstance(idl_def, web_idl.Union): if idl_def and not isinstance(idl_def, web_idl.Union):
location = idl_def.debug_info.location location = idl_def.debug_info.location
text = PathManager.relpath_to_project_root(location.filepath) text = location.filepath
if location.line_number is not None: if location.line_number is not None:
text += ":{}".format(location.line_number) text += ":{}".format(location.line_number)
return text return text
......
...@@ -90,19 +90,6 @@ def enclose_with_header_guard(code_node, header_guard): ...@@ -90,19 +90,6 @@ def enclose_with_header_guard(code_node, header_guard):
]) ])
def enclose_with_namespace(code_node, namespace):
assert isinstance(code_node, CodeNode)
assert isinstance(namespace, str)
return SequenceNode([
LiteralNode("namespace {} {{".format(namespace)),
EmptyNode(),
code_node,
EmptyNode(),
LiteralNode("}} // namespace {}".format(namespace)),
])
def collect_include_headers_of_idl_types(idl_types): def collect_include_headers_of_idl_types(idl_types):
""" """
Returns a set of header paths that are required by |idl_types|. Returns a set of header paths that are required by |idl_types|.
......
...@@ -31,7 +31,6 @@ from .codegen_format import format_template as _format ...@@ -31,7 +31,6 @@ from .codegen_format import format_template as _format
from .codegen_utils import collect_include_headers_of_idl_types from .codegen_utils import collect_include_headers_of_idl_types
from .codegen_utils import component_export from .codegen_utils import component_export
from .codegen_utils import enclose_with_header_guard from .codegen_utils import enclose_with_header_guard
from .codegen_utils import enclose_with_namespace
from .codegen_utils import make_copyright_header from .codegen_utils import make_copyright_header
from .codegen_utils import make_forward_declarations from .codegen_utils import make_forward_declarations
from .codegen_utils import make_header_include_directives from .codegen_utils import make_header_include_directives
......
# 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)
def filepaths(self, component):
assert isinstance(component, web_idl.Component)
return iter(sorted(self._filelist[component]))
def make_file_list_in_gni(gni_var_name, component, file_list):
assert isinstance(gni_var_name, str)
assert isinstance(component, web_idl.Component)
assert isinstance(file_list, _FileList)
filepaths = map(
lambda filepath: TextNode("\"$root_gen_dir/{}\"".format(filepath)),
file_list.filepaths(component))
return ListNode([
TextNode("{} = [".format(gni_var_name)),
ListNode(filepaths, separator=",\n", tail=","),
TextNode("]"),
])
def update_generated_bindings_gni(web_idl_database):
enumeration_files = _FileList()
files = enumeration_files
for enumeration in web_idl_database.enumerations:
path_manager = PathManager(enumeration)
files.add(path_manager.api_component, path_manager.api_path(ext="h"))
files.add(path_manager.api_component, path_manager.api_path(ext="cc"))
def name(kind, component):
return "generated_{kind}_sources_in_{component}".format(
kind=kind, component=component)
for component in (_COMPONENT_CORE, _COMPONENT_MODULES):
gni_path = PathManager.src_path_to(
"third_party/blink/renderer/bindings/{}/v8/generated_bindings.gni".
format(component))
gni_node = ListNode(tail="\n")
gni_node.set_accumulator(CodeGenAccumulator())
gni_node.set_renderer(MakoRenderer())
gni_node.append(
TextNode("""\
# 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.
# This file is automatically generated. DO NOT EDIT.
"""))
gni_node.append(
make_file_list_in_gni(
name("enumeration", component), component, enumeration_files))
gni_node.append(EmptyNode())
write_code_node_to_file(gni_node, gni_path)
...@@ -62,22 +62,23 @@ class PathManager(object): ...@@ -62,22 +62,23 @@ class PathManager(object):
} }
cls._is_initialized = True cls._is_initialized = True
@staticmethod @classmethod
def gen_path_to(path): def gen_path_to(cls, path):
""" """
Returns the absolute path of |path| that must be relative to the root Returns the absolute path of |path| that must be relative to the root
directory of generated files. directory of generated files.
""" """
assert PathManager._is_initialized, PathManager._REQUIRE_INIT_MESSAGE assert cls._is_initialized, cls._REQUIRE_INIT_MESSAGE
return os.path.abspath(os.path.join(PathManager._root_gen_dir, path)) return os.path.abspath(os.path.join(cls._root_gen_dir, path))
@classmethod @classmethod
def relpath_to_project_root(cls, path): def src_path_to(cls, path):
index = path.find(cls._blink_path_prefix) """
if index < 0: Returns the absolute path of |path| that must be relative to the
assert path.startswith(cls._blink_path_prefix[1:]) project root directory.
return path """
return path[index + 1:] assert cls._is_initialized, cls._REQUIRE_INIT_MESSAGE
return os.path.abspath(os.path.join(cls._root_src_dir, path))
def __init__(self, idl_definition): def __init__(self, idl_definition):
assert self._is_initialized, self._REQUIRE_INIT_MESSAGE assert self._is_initialized, self._REQUIRE_INIT_MESSAGE
......
...@@ -18,7 +18,6 @@ from .codegen_context import CodeGenContext ...@@ -18,7 +18,6 @@ from .codegen_context import CodeGenContext
from .codegen_format import format_template as _format from .codegen_format import format_template as _format
from .codegen_utils import component_export from .codegen_utils import component_export
from .codegen_utils import enclose_with_header_guard from .codegen_utils import enclose_with_header_guard
from .codegen_utils import enclose_with_namespace
from .codegen_utils import make_copyright_header from .codegen_utils import make_copyright_header
from .codegen_utils import make_forward_declarations from .codegen_utils import make_forward_declarations
from .codegen_utils import make_header_include_directives from .codegen_utils import make_header_include_directives
......
...@@ -47,10 +47,14 @@ def main(): ...@@ -47,10 +47,14 @@ def main():
options, tasks = parse_options() options, tasks = parse_options()
dispatch_table = { dispatch_table = {
# IDL definitions
'dictionary': bind_gen.generate_dictionaries, 'dictionary': bind_gen.generate_dictionaries,
'enumeration': bind_gen.generate_enumerations, 'enumeration': bind_gen.generate_enumerations,
'interface': bind_gen.generate_interfaces, 'interface': bind_gen.generate_interfaces,
'union': bind_gen.generate_unions, 'union': bind_gen.generate_unions,
# GN settings
'generated_bindings_gni': bind_gen.update_generated_bindings_gni,
} }
for task in tasks: for task in tasks:
......
...@@ -45,6 +45,7 @@ bind_gen/enumeration.py ...@@ -45,6 +45,7 @@ bind_gen/enumeration.py
bind_gen/interface.py bind_gen/interface.py
bind_gen/mako_renderer.py bind_gen/mako_renderer.py
bind_gen/name_style.py bind_gen/name_style.py
bind_gen/output_file_list.py
bind_gen/path_manager.py bind_gen/path_manager.py
bind_gen/style_format.py bind_gen/style_format.py
bind_gen/union.py bind_gen/union.py
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment