| # Copyright 2021 The Cobalt Authors. All Rights Reserved. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import("//cobalt/bindings/blink_variables.gni") |
| import("//cobalt/script/v8c/v8c_variables.gni") |
| |
| # The allowlist of what extended attributes we support. If an attribute |
| # not in this list is encountered, it will cause an error in the |
| # pipeline. |
| _extended_attributes_file = "//cobalt/bindings/IDLExtendedAttributes.txt" |
| |
| # Additional files used by the idl compilation scripts. |
| _bindings_extra_inputs = [ |
| "//cobalt/bindings/code_generator_cobalt.py", |
| "//cobalt/bindings/expression_generator.py", |
| "//cobalt/bindings/contexts.py", |
| "//cobalt/bindings/idl_compiler_cobalt.py", |
| "//cobalt/bindings/generate_conversion_header.py", |
| "//cobalt/bindings/name_conversion.py", |
| "//cobalt/bindings/overload_context.py", |
| ] |
| _bindings_extra_inputs += engine_bindings_scripts |
| _bindings_extra_inputs += idl_lexer_parser_files |
| _bindings_extra_inputs += idl_compiler_files |
| |
| # Template definitions. |
| template("idl_compile") { |
| action_foreach(target_name) { |
| script = engine_idl_compiler |
| |
| sources = invoker.sources |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "deps", |
| "public_deps", |
| "public_configs", |
| ]) |
| |
| inputs = [ |
| _extended_attributes_file, |
| invoker.component_info, |
| invoker.interfaces_info, |
| ] |
| inputs += _bindings_extra_inputs |
| |
| generated_file_path = |
| invoker.output_directory + "/{{source_root_relative_dir}}" |
| |
| if (defined(invoker.header_prefix)) { |
| header_prefix = invoker.header_prefix + "_" |
| } else { |
| header_prefix = "" |
| } |
| |
| outputs = [ |
| "$generated_file_path/${header_prefix}{{source_name_part}}.h", |
| "$generated_file_path/${generated_bindings_prefix}_{{source_name_part}}.cc", |
| ] |
| |
| args = [ |
| "--cache-directory", |
| rebase_path(invoker.cache_directory), |
| "--output-directory", |
| rebase_path(invoker.output_directory), |
| "--interfaces-info", |
| rebase_path(invoker.interfaces_info), |
| "--component-info", |
| rebase_path(invoker.component_info), |
| "--extended-attributes", |
| rebase_path(_extended_attributes_file), |
| "{{source}}", |
| ] |
| } |
| } |
| |
| template("generate_type_conversion") { |
| action(target_name) { |
| script = engine_conversion_header_generator_script |
| |
| deps = invoker.deps |
| |
| public_deps = engine_dependencies |
| |
| inputs = [ |
| _extended_attributes_file, |
| "//cobalt/bindings/shared/idl_conditional_macros.h", |
| ] |
| inputs += _bindings_extra_inputs |
| inputs += invoker.inputs |
| |
| foreach(interface, invoker.interfaces) { |
| # IDL files that define all the constructors that are on the global scope |
| # objects. |
| inputs += |
| [ invoker.global_names_idl_path + "/${interface}Constructors.idl" ] |
| } |
| |
| # Generated header file that contains forward declarations for converting |
| # to/from JS value and generated types. |
| outputs = [ "${invoker.output_dir}/${generated_bindings_prefix}_gen_type_conversion.h" ] |
| |
| args = [ |
| "--cache-directory", |
| rebase_path(invoker.cache_directory, root_build_dir), |
| "--output-dir", |
| rebase_path(invoker.output_dir, root_build_dir), |
| "--interfaces-info", |
| rebase_path(invoker.interfaces_info, root_build_dir), |
| "--component-info", |
| rebase_path(invoker.component_info, root_build_dir), |
| ] |
| } |
| } |
| |
| template("compute_global_objects") { |
| action(target_name) { |
| script = "$bindings_scripts_dir/compute_global_objects.py" |
| |
| inputs = [ "$bindings_scripts_dir/utilities.py" ] |
| inputs += invoker.idl_files |
| |
| outputs = [ invoker.global_objects_file ] |
| |
| idl_files_list = "$target_gen_dir/${target_name}_idl_files_list.tmp" |
| write_file(idl_files_list, rebase_path(invoker.idl_files, root_build_dir)) |
| |
| args = [ |
| "--idl-files-list", |
| rebase_path(idl_files_list, root_build_dir), |
| "--", |
| rebase_path(invoker.global_objects_file, root_build_dir), |
| ] |
| } |
| } |
| |
| template("compute_global_constructors_idls") { |
| action(target_name) { |
| script = "$bindings_scripts_dir/generate_global_constructors.py" |
| |
| deps = invoker.deps |
| |
| inputs = [ |
| "$bindings_scripts_dir/utilities.py", |
| invoker.global_objects_file, |
| ] |
| inputs += invoker.idl_files |
| outputs = [] |
| |
| # Write the file list to a unique temp file to avoid blowing out the |
| # command line length limit. |
| idl_files_list = "$target_gen_dir/${target_name}_static_idl_files_list.tmp" |
| write_file(idl_files_list, rebase_path(invoker.idl_files, root_build_dir)) |
| |
| args = [ |
| "--idl-files-list", |
| rebase_path(idl_files_list, root_build_dir), |
| "--global-objects-file", |
| rebase_path(invoker.global_objects_file, root_build_dir), |
| "--", |
| ] |
| |
| # Interfaces and Generated files must be added to the outputs and passed at |
| # command line |
| foreach(interface, invoker.interfaces) { |
| file_base = invoker.global_names_idl_path + "/${interface}Constructors" |
| |
| # Generated IDL files that will define all the constructors that should be |
| # on the global scope objects. |
| idl_file = file_base + ".idl" |
| |
| # Dummy header file which is generated because the idl compiler assumes |
| # there is a header for each IDL. |
| header_file = file_base + ".h" |
| |
| outputs += [ |
| idl_file, |
| header_file, |
| ] |
| |
| args += [ |
| "${interface}", |
| rebase_path(idl_file, root_build_dir), |
| ] |
| } |
| } |
| } |
| |
| template("compute_interfaces_info_individual") { |
| action(target_name) { |
| script = "$bindings_scripts_dir/compute_interfaces_info_individual.py" |
| |
| deps = invoker.deps |
| |
| inputs = [ |
| "$bindings_scripts_dir/utilities.py", |
| _extended_attributes_file, |
| ] |
| inputs += invoker.idl_files |
| |
| outputs = [ |
| invoker.interfaces_info_file, |
| invoker.component_info_file, |
| ] |
| |
| # Write the file list to a unique temp file to avoid blowing out the |
| # command line length limit. |
| idl_files_list = "$target_gen_dir/${target_name}_static_idl_files_list.tmp" |
| write_file(idl_files_list, rebase_path(invoker.idl_files, root_build_dir)) |
| |
| dependency_idl_files_paths = |
| rebase_path(invoker.dependency_idl_files, root_build_dir) |
| dependency_idl_files_list = string_join(" ", dependency_idl_files_paths) |
| args = [ |
| "--cache-directory", |
| rebase_path(invoker.cache_directory, root_build_dir), |
| "--root-directory", |
| rebase_path("//", root_build_dir), |
| "--idl-files-list", |
| rebase_path(idl_files_list, root_build_dir), |
| "--interfaces-info-file", |
| rebase_path(invoker.interfaces_info_file, root_build_dir), |
| "--component-info-file", |
| rebase_path(invoker.component_info_file, root_build_dir), |
| "--extended-attributes", |
| rebase_path(_extended_attributes_file, root_build_dir), |
| "--dependency-idl-files", |
| dependency_idl_files_list, |
| "--", |
| ] |
| |
| # IDL files and Generated files must be added to the inputs and passed at |
| # command line |
| foreach(interface, invoker.interfaces) { |
| # IDL files that define all the constructors that are on the global scope |
| # objects. |
| idl_file = invoker.global_names_idl_path + "/${interface}Constructors.idl" |
| inputs += [ idl_file ] |
| args += [ rebase_path(idl_file, root_build_dir) ] |
| } |
| } |
| } |
| |
| template("generate_interfaces_info_overall") { |
| action(target_name) { |
| script = "$bindings_scripts_dir/compute_interfaces_info_overall.py" |
| |
| deps = invoker.deps |
| |
| inputs = [ invoker.individual_interfaces_file ] |
| |
| outputs = [ invoker.combined_interfaces_file ] |
| |
| args = [ |
| "--", |
| rebase_path(invoker.individual_interfaces_file, root_build_dir), |
| rebase_path(invoker.combined_interfaces_file, root_build_dir), |
| ] |
| } |
| } |
| |
| template("cache_lex_tables") { |
| action(target_name) { |
| script = "$bindings_scripts_dir/blink_idl_parser.py" |
| |
| inputs = idl_lexer_parser_files |
| outputs = [ |
| "${invoker.output_dir}/lextab.py", |
| "${invoker.output_dir}/parsetab.pickle", |
| ] |
| |
| args = [ rebase_path(invoker.output_dir, root_build_dir) ] |
| } |
| } |
| |
| template("cache_templates") { |
| action(target_name) { |
| script = "//cobalt/bindings/code_generator_cobalt.py" |
| |
| inputs = [ |
| "//cobalt/bindings/path_generator.py", |
| "//third_party/jinja2/__init__.py", |
| "//third_party/markupsafe/__init__.py", # jinja2 dep |
| ] |
| |
| # Cobalt's Jinja templates. |
| inputs += engine_template_files |
| |
| # Templates that are shared by the code generation for multiple engines. |
| inputs += [ |
| "//cobalt/bindings/templates/dictionary.h.template", |
| "//cobalt/bindings/templates/interface-base.cc.template", |
| "//cobalt/bindings/templates/interface-base.h.template", |
| "//cobalt/bindings/templates/callback-interface-base.cc.template", |
| "//cobalt/bindings/templates/callback-interface-base.h.template", |
| ] |
| |
| # The filenames are hashes of the template file path. |
| outputs = [ |
| "${invoker.output_dir}/__jinja2_0458bc0cdbf0dcc5ede1938c55c599dc57dcae71.cache", |
| "${invoker.output_dir}/__jinja2_303dad9caff7b8c046562177d5460bb9f7b159df.cache", |
| "${invoker.output_dir}/__jinja2_4038c00836c6764d385cf4c46462430f9aaf17be.cache", |
| "${invoker.output_dir}/__jinja2_435670c71610a56f1cef61f2d38133c78acac78f.cache", |
| "${invoker.output_dir}/__jinja2_4a2a64213caba2133a0b71aada741965e14fc1bb.cache", |
| "${invoker.output_dir}/__jinja2_4c7f97150281049711d4ce10a328cc061253b390.cache", |
| "${invoker.output_dir}/__jinja2_5d45ad6b9cacef6d9d179dc9099ec37cf6ee1724.cache", |
| "${invoker.output_dir}/__jinja2_65e7aef6627bae7400833440f6e4ae091c710908.cache", |
| "${invoker.output_dir}/__jinja2_74db451681d577fcb9c39eae42a296cbbcf752c7.cache", |
| "${invoker.output_dir}/__jinja2_8e238dc5f6ff498c4406817387ddb7ece64b45bd.cache", |
| "${invoker.output_dir}/__jinja2_b0197cf1f0bbd6fc7944725aec13712883090f68.cache", |
| "${invoker.output_dir}/__jinja2_d049954a9d5a3dc383d37b7673da54b661ec34b0.cache", |
| "${invoker.output_dir}/__jinja2_d09b22d687fad0727f239c3feb23cadd73ac6bc0.cache", |
| "${invoker.output_dir}/__jinja2_df2da080300d5d4b19c5c7b8b87f6a5521d00c89.cache", |
| ] |
| |
| args = [ |
| rebase_path("${invoker.output_dir}", root_build_dir), |
| rebase_path("$engine_templates_dir", root_build_dir), |
| rebase_path("${invoker.output_dir}/cached_jinja_templates.stamp", |
| root_build_dir), |
| ] |
| } |
| } |