| # Copyright 2014 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. |
| |
| # Generate C++ and JavaScript source files from mojom files. The output files |
| # will go under the generated file directory tree with the same path as each |
| # input file. |
| # |
| # Parameters: |
| # |
| # sources (required) |
| # List of source .mojom files to compile. |
| # |
| # deps (optional) |
| # Note: this can contain only other mojom targets. |
| # |
| # public_deps (optional) |
| # Note: this can contain only other mojom targets. |
| # |
| # testonly (optional) |
| # |
| # visibility (optional) |
| template("mojom") { |
| assert(defined(invoker.sources), |
| "\"sources\" must be defined for the $target_name template.") |
| |
| generator_root = "//mojo/public/tools/bindings" |
| generator_script = "$generator_root/mojom_bindings_generator.py" |
| generator_sources = [ |
| generator_script, |
| "$generator_root/generators/cpp_templates/enum_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/interface_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/interface_definition.tmpl", |
| "$generator_root/generators/cpp_templates/interface_macros.tmpl", |
| "$generator_root/generators/cpp_templates/interface_proxy_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/interface_request_validator_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/interface_response_validator_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/interface_stub_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/module.cc.tmpl", |
| "$generator_root/generators/cpp_templates/module.h.tmpl", |
| "$generator_root/generators/cpp_templates/module-internal.h.tmpl", |
| "$generator_root/generators/cpp_templates/params_definition.tmpl", |
| "$generator_root/generators/cpp_templates/struct_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/struct_definition.tmpl", |
| "$generator_root/generators/cpp_templates/struct_serialization_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/struct_serialization_definition.tmpl", |
| "$generator_root/generators/cpp_templates/struct_macros.tmpl", |
| "$generator_root/generators/cpp_templates/wrapper_class_declaration.tmpl", |
| "$generator_root/generators/cpp_templates/wrapper_class_definition.tmpl", |
| "$generator_root/generators/java_templates/constant_definition.tmpl", |
| "$generator_root/generators/java_templates/constants.java.tmpl", |
| "$generator_root/generators/java_templates/enum.java.tmpl", |
| "$generator_root/generators/java_templates/enum_definition.tmpl", |
| "$generator_root/generators/java_templates/header.java.tmpl", |
| "$generator_root/generators/java_templates/interface.java.tmpl", |
| "$generator_root/generators/java_templates/interface_definition.tmpl", |
| "$generator_root/generators/java_templates/interface_internal.java.tmpl", |
| "$generator_root/generators/java_templates/struct.java.tmpl", |
| "$generator_root/generators/java_templates/struct_definition.tmpl", |
| "$generator_root/generators/js_templates/enum_definition.tmpl", |
| "$generator_root/generators/js_templates/interface_definition.tmpl", |
| "$generator_root/generators/js_templates/module.amd.tmpl", |
| "$generator_root/generators/js_templates/module.html.tmpl", |
| "$generator_root/generators/js_templates/module_definition.tmpl", |
| "$generator_root/generators/js_templates/struct_definition.tmpl", |
| "$generator_root/generators/python_templates/module_macros.tmpl", |
| "$generator_root/generators/python_templates/module.py.tmpl", |
| "$generator_root/generators/mojom_cpp_generator.py", |
| "$generator_root/generators/mojom_js_generator.py", |
| "$generator_root/generators/mojom_java_generator.py", |
| "$generator_root/generators/mojom_python_generator.py", |
| "$generator_root/pylib/mojom/__init__.py", |
| "$generator_root/pylib/mojom/error.py", |
| "$generator_root/pylib/mojom/generate/__init__.py", |
| "$generator_root/pylib/mojom/generate/data.py", |
| "$generator_root/pylib/mojom/generate/generator.py", |
| "$generator_root/pylib/mojom/generate/module.py", |
| "$generator_root/pylib/mojom/generate/pack.py", |
| "$generator_root/pylib/mojom/generate/template_expander.py", |
| "$generator_root/pylib/mojom/parse/__init__.py", |
| "$generator_root/pylib/mojom/parse/ast.py", |
| "$generator_root/pylib/mojom/parse/lexer.py", |
| "$generator_root/pylib/mojom/parse/parser.py", |
| "$generator_root/pylib/mojom/parse/translate.py", |
| ] |
| generator_cpp_outputs = [ |
| "{{source_gen_dir}}/{{source_name_part}}.mojom.cc", |
| "{{source_gen_dir}}/{{source_name_part}}.mojom.h", |
| "{{source_gen_dir}}/{{source_name_part}}.mojom-internal.h", |
| ] |
| generator_java_outputs = [ |
| "{{source_gen_dir}}/{{source_name_part}}.mojom.srcjar", |
| ] |
| generator_js_outputs = [ |
| "{{source_gen_dir}}/{{source_name_part}}.mojom.js", |
| ] |
| generator_python_outputs = [ |
| "{{source_gen_dir}}/{{source_name_part}}_mojom.py", |
| ] |
| |
| if (defined(invoker.visibility)) { |
| # Need to save this because the the target_name is overwritten inside the |
| # action to be that of the action itself. Only define this in the case the |
| # var is used to avoid unused var error. |
| target_visibility = [ ":$target_name" ] |
| } |
| |
| generator_target_name = target_name + "__generator" |
| action_foreach(generator_target_name) { |
| if (defined(invoker.visibility)) { |
| visibility = target_visibility + invoker.visibility |
| } |
| script = generator_script |
| inputs = generator_sources |
| sources = invoker.sources |
| outputs = generator_cpp_outputs + |
| generator_java_outputs + |
| generator_js_outputs + |
| generator_python_outputs |
| args = [ |
| "{{source}}", |
| "--use_chromium_bundled_pylibs", |
| "-d", rebase_path("//", root_build_dir), |
| "-I", rebase_path("//", root_build_dir), |
| "-o", rebase_path(root_gen_dir), |
| ] |
| } |
| |
| source_set(target_name) { |
| if (defined(invoker.visibility)) { |
| visibility = invoker.visibility |
| } |
| if (defined(invoker.testonly)) { |
| testonly = invoker.testonly |
| } |
| sources = process_file_template(invoker.sources, generator_cpp_outputs) |
| data = process_file_template(invoker.sources, generator_js_outputs) |
| deps = [ |
| ":$generator_target_name", |
| "//mojo/public/cpp/bindings", |
| ] |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| if (defined(invoker.public_deps)) { |
| public_deps = invoker.public_deps |
| } |
| } |
| |
| all_deps = [] |
| if (defined(invoker.deps)) { |
| all_deps += invoker.deps |
| } |
| if (defined(invoker.public_deps)) { |
| all_deps += invoker.public_deps |
| } |
| |
| group("${target_name}__is_mojom") { |
| } |
| |
| # Explicitly ensure that all dependencies (invoker.deps and |
| # invoker.public_deps) are mojom targets themselves. |
| group("${target_name}__check_deps_are_all_mojom") { |
| deps = [] |
| foreach(d, all_deps) { |
| name = get_label_info(d, "label_no_toolchain") |
| toolchain = get_label_info(d, "toolchain") |
| deps += [ "${name}__is_mojom(${toolchain})" ] |
| } |
| } |
| |
| if (is_android) { |
| import("//build/config/android/rules.gni") |
| |
| java_target_name = target_name + "_java" |
| android_library(java_target_name) { |
| deps = [ |
| "//mojo/public/java:bindings", |
| "//mojo/public/java:system", |
| ] |
| |
| foreach(d, all_deps) { |
| # Resolve the name, so that a target //mojo/something becomes |
| # //mojo/something:something and we can append "_java" to get the java |
| # dependency name. |
| full_name = get_label_info(d, "label_no_toolchain") |
| deps += [ "${full_name}_java" ] |
| } |
| |
| srcjars = process_file_template(invoker.sources, generator_java_outputs) |
| } |
| } |
| } |