mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 22:36:09 +03:00
1055 lines
38 KiB
Plaintext
1055 lines
38 KiB
Plaintext
# 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.
|
|
|
|
import("//build/config/jumbo.gni")
|
|
|
|
# TODO(rockot): Maybe we can factor these dependencies out of //mojo. They're
|
|
# used to conditionally enable message ID scrambling in a way which is
|
|
# consistent across toolchains and which is affected by branded vs non-branded
|
|
# Chrome builds. Ideally we could create some generic knobs here that could be
|
|
# flipped elsewhere though.
|
|
import("//build/config/chrome_build.gni")
|
|
import("//build/config/nacl/config.gni")
|
|
import("//components/nacl/features.gni")
|
|
|
|
declare_args() {
|
|
# Indicates whether typemapping should be supported in this build
|
|
# configuration. This may be disabled when building external projects which
|
|
# depend on //mojo but which do not need/want all of the Chromium tree
|
|
# dependencies that come with typemapping.
|
|
#
|
|
# Note that (perhaps obviously) a huge amount of Chromium code will not build
|
|
# with typemapping disabled, so it is never valid to set this to |false| in
|
|
# any Chromium build configuration.
|
|
enable_mojom_typemapping = true
|
|
}
|
|
|
|
# NOTE: We would like to avoid scrambling message IDs where it doesn't add
|
|
# value, so we limit the behavior to desktop builds for now. There is some
|
|
# redundancy in the conditions here, but it is tolerated for clarity:
|
|
# We're explicit about Mac, Windows, and Linux desktop support, but it's
|
|
# also necessary to ensure that bindings in alternate toolchains (e.g.
|
|
# NaCl IRT) are always consistent with the default toolchain; for that
|
|
# reason we always enable scrambling within NaCl toolchains when possible,
|
|
# as well as within the default toolchain when NaCl is enabled.
|
|
#
|
|
# Finally, because we *cannot* enable scrambling on Chrome OS (it would break
|
|
# ARC) we have to explicitly opt out there even when NaCl is enabled (and
|
|
# consequently also when building for NaCl toolchains.) For this reason we
|
|
# check |target_os| explicitly, as it's consistent across all toolchains.
|
|
enable_scrambled_message_ids =
|
|
is_mac || is_win || (is_linux && !is_chromeos) ||
|
|
((enable_nacl || is_nacl || is_nacl_nonsfi) && target_os != "chromeos")
|
|
|
|
mojom_generator_root = "//mojo/public/tools/bindings"
|
|
mojom_generator_script = "$mojom_generator_root/mojom_bindings_generator.py"
|
|
mojom_generator_sources = [
|
|
"$mojom_generator_root/generators/mojom_cpp_generator.py",
|
|
"$mojom_generator_root/generators/mojom_js_generator.py",
|
|
"$mojom_generator_root/generators/mojom_java_generator.py",
|
|
"$mojom_generator_root/pylib/mojom/__init__.py",
|
|
"$mojom_generator_root/pylib/mojom/error.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/__init__.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/constant_resolver.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/generator.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/module.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/pack.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/template_expander.py",
|
|
"$mojom_generator_root/pylib/mojom/generate/translate.py",
|
|
"$mojom_generator_root/pylib/mojom/parse/__init__.py",
|
|
"$mojom_generator_root/pylib/mojom/parse/ast.py",
|
|
"$mojom_generator_root/pylib/mojom/parse/lexer.py",
|
|
"$mojom_generator_root/pylib/mojom/parse/parser.py",
|
|
"$mojom_generator_script",
|
|
]
|
|
|
|
if (enable_scrambled_message_ids) {
|
|
declare_args() {
|
|
# The path to a file whose contents can be used as the basis for a message
|
|
# ID scrambling salt.
|
|
mojom_message_id_salt_path = "//chrome/VERSION"
|
|
|
|
# The path to a file whose contents will be concatenated to the contents of
|
|
# the file at |mojom_message_id_salt_path| to form a complete salt for
|
|
# message ID scrambling. May be the empty string, in which case the contents
|
|
# of the above file alone are used as the complete salt.
|
|
if (is_chrome_branded) {
|
|
mojom_message_id_salt_suffix_path =
|
|
"//mojo/internal/chrome-message-id-salt-suffix"
|
|
} else {
|
|
mojom_message_id_salt_suffix_path = ""
|
|
}
|
|
}
|
|
|
|
mojom_generator_sources += [ mojom_message_id_salt_path ]
|
|
if (mojom_message_id_salt_suffix_path != "") {
|
|
mojom_generator_sources += [ mojom_message_id_salt_suffix_path ]
|
|
}
|
|
}
|
|
|
|
generate_export_header_script =
|
|
"$mojom_generator_root/generate_export_header.py"
|
|
|
|
if (enable_mojom_typemapping) {
|
|
if (!is_ios) {
|
|
_bindings_configuration_files = [
|
|
"//mojo/public/tools/bindings/chromium_bindings_configuration.gni",
|
|
"//mojo/public/tools/bindings/blink_bindings_configuration.gni",
|
|
]
|
|
} else {
|
|
_bindings_configuration_files =
|
|
[ "//mojo/public/tools/bindings/chromium_bindings_configuration.gni" ]
|
|
}
|
|
_bindings_configurations = []
|
|
foreach(config_file, _bindings_configuration_files) {
|
|
_bindings_configurations += [ read_file(config_file, "scope") ]
|
|
}
|
|
foreach(configuration, _bindings_configurations) {
|
|
# Check that the mojom field of each typemap refers to a mojom that exists.
|
|
foreach(typemap, configuration.typemaps) {
|
|
_typemap_config = {
|
|
}
|
|
_typemap_config = typemap.config
|
|
read_file(_typemap_config.mojom, "")
|
|
}
|
|
}
|
|
} else {
|
|
_bindings_configuration_files = []
|
|
_bindings_configurations = [
|
|
{
|
|
typemaps = []
|
|
component_macro_suffix = ""
|
|
},
|
|
{
|
|
variant = "blink"
|
|
component_macro_suffix = "_BLINK"
|
|
for_blink = true
|
|
typemaps = []
|
|
},
|
|
]
|
|
}
|
|
|
|
# Generates targets for building C++, JavaScript and Java bindings from mojom
|
|
# files. The output files will go under the generated file directory tree with
|
|
# the same path as each input file.
|
|
#
|
|
# Other targets should depend on one of these generated targets (where "foo"
|
|
# is the target name):
|
|
#
|
|
# foo
|
|
# C++ bindings.
|
|
#
|
|
# foo_blink
|
|
# C++ bindings using Blink standard types.
|
|
#
|
|
# foo_java
|
|
# Java bindings.
|
|
#
|
|
# foo_js
|
|
# JavaScript bindings; used as compile-time dependency.
|
|
#
|
|
# foo_js_data_deps
|
|
# JavaScript bindings; used as run-time dependency.
|
|
#
|
|
# Parameters:
|
|
#
|
|
# sources (optional if one of the deps sets listed below is present)
|
|
# List of source .mojom files to compile.
|
|
#
|
|
# deps (optional)
|
|
# Note: this can contain only other mojom targets.
|
|
#
|
|
# DEPRECATED: This is synonymous with public_deps because all mojom
|
|
# dependencies must be public by design. Please use public_deps.
|
|
#
|
|
# public_deps (optional)
|
|
# Note: this can contain only other mojom targets.
|
|
#
|
|
# import_dirs (optional)
|
|
# List of import directories that will get added when processing sources.
|
|
#
|
|
# testonly (optional)
|
|
#
|
|
# visibility (optional)
|
|
#
|
|
# visibility_blink (optional)
|
|
# The value to use for visibility for the blink variant. If unset,
|
|
# |visibility| is used.
|
|
#
|
|
# use_once_callback (optional)
|
|
# If set to true, generated classes will use base::OnceCallback instead of
|
|
# base::RepeatingCallback.
|
|
# Default value is true.
|
|
# TODO(dcheng):
|
|
# - Convert everything to use OnceCallback.
|
|
# - Remove support for the old mode.
|
|
#
|
|
# cpp_only (optional)
|
|
# If set to true, only the C++ bindings targets will be generated.
|
|
#
|
|
# use_new_js_bindings (optional)
|
|
# If set to true, the generated JS code will use the new module loading
|
|
# approach and the core API exposed by Web IDL.
|
|
# Default value is true.
|
|
# TODO(yzshen): Convert all users to use new JS bindings and remove the
|
|
# old mode.
|
|
#
|
|
# js_bindings_mode (optional)
|
|
# |js_bindings_mode| and |use_new_js_bindings| are mutually exclusive. You
|
|
# can only specify at most one of them.
|
|
# - "new" (default): generate only the new-style JS bindings;
|
|
# - "both": generate both the old- and new-style JS bindings;
|
|
# - "old": generate only the old-style JS bindings.
|
|
# TODO(yzshen): Convert all users to use new JS bindings and remove the
|
|
# old mode.
|
|
#
|
|
# support_lazy_serialization (optional)
|
|
# If set to |true|, generated C++ bindings will effectively prefer to
|
|
# transmit messages in an unserialized form when going between endpoints
|
|
# in the same process. This avoids the runtime cost of serialization,
|
|
# deserialization, and validation logic at the expensive of increased
|
|
# code size. Defaults to |false|.
|
|
#
|
|
# disable_variants (optional)
|
|
# If |true|, no variant sources will be generated for the target. Defaults
|
|
# to |false|.
|
|
#
|
|
# allow_native_structs (optional)
|
|
# If set to |true| (the default), mojoms in this target may apply the
|
|
# [Native] attribute to struct declarations, causing that mojom struct to
|
|
# be serialized and deserialized using a legacy IPC::ParamTraits
|
|
# specialization.
|
|
#
|
|
# scramble_message_ids (optional)
|
|
# If set to |true| (the default), generated mojom interfaces will use
|
|
# scrambled ordinal identifiers in encoded messages.
|
|
#
|
|
# component_output_prefix (optional)
|
|
# The prefix to use for the output_name of any component library emitted
|
|
# for generated C++ bindings. If this is omitted, C++ bindings targets are
|
|
# emitted as source_sets instead. Because this controls the name of the
|
|
# output shared library binary in the root output directory, it must be
|
|
# unique across the entire build configuration.
|
|
#
|
|
# This is required if |component_macro_prefix| is specified.
|
|
#
|
|
# component_macro_prefix (optional)
|
|
# This specifies a macro prefix to use for component export macros and
|
|
# should therefore be globally unique in the project. For example if this
|
|
# is "FOO_BAR", then the generated C++ sources will be built with
|
|
# FOO_BAR_IMPL defined, and the generated public headers will affix
|
|
# FOO_BAR_EXPORT to all public symbol definitions; the meaning of the
|
|
# EXPORT macro depends on whether the corresponding IMPL macro is defined,
|
|
# per standard practice with Chromium component exports.
|
|
#
|
|
# The following parameters are used to support the component build. They are
|
|
# needed so that bindings which are linked with a component can use the same
|
|
# export settings for classes. The first three are for the chromium variant, and
|
|
# the last three are for the blink variant. These parameters are mutually
|
|
# exclusive to |component_macro_prefix|, but |component_output_prefix| may still
|
|
# be used to uniqueify the generated invariant (i.e. shared) output component.
|
|
# export_class_attribute (optional)
|
|
# The attribute to add to the class declaration. e.g. "CONTENT_EXPORT"
|
|
# export_define (optional)
|
|
# A define to be added to the source_set which is needed by the export
|
|
# header. e.g. "CONTENT_IMPLEMENTATION=1"
|
|
# export_header (optional)
|
|
# A header to be added to the generated bindings to support the component
|
|
# build. e.g. "content/common/content_export.h"
|
|
# export_class_attribute_blink (optional)
|
|
# export_define_blink (optional)
|
|
# export_header_blink (optional)
|
|
# These three parameters are the blink variants of the previous 3.
|
|
#
|
|
# The following parameters are used to correct component build dependencies.
|
|
# They are needed so mojom-mojom dependencies follow the rule that dependencies
|
|
# on a source set in another component are replaced by a dependency on the
|
|
# containing component. The first two are for the chromium variant; the other
|
|
# two are for the blink variant.
|
|
# overridden_deps (optional)
|
|
# The list of mojom deps to be overridden.
|
|
# component_deps (optional)
|
|
# The list of component deps to add to replace overridden_deps.
|
|
# overridden_deps_blink (optional)
|
|
# component_deps_blink (optional)
|
|
# These two parameters are the blink variants of the previous two.
|
|
template("mojom") {
|
|
assert(
|
|
defined(invoker.sources) || defined(invoker.deps) ||
|
|
defined(invoker.public_deps),
|
|
"\"sources\" or \"deps\" must be defined for the $target_name template.")
|
|
|
|
assert(!defined(invoker.use_new_js_bindings) ||
|
|
!defined(invoker.js_bindings_mode),
|
|
"You shouldn't specify both \"use_new_js_bindings\" and " +
|
|
"\"js_bindings_mode\".")
|
|
|
|
if (defined(invoker.export_class_attribute) ||
|
|
defined(invoker.export_define) || defined(invoker.export_header)) {
|
|
assert(defined(invoker.export_class_attribute))
|
|
assert(defined(invoker.export_define))
|
|
assert(defined(invoker.export_header))
|
|
assert(!defined(invoker.component_macro_prefix))
|
|
}
|
|
if (defined(invoker.export_class_attribute_blink) ||
|
|
defined(invoker.export_define_blink) ||
|
|
defined(invoker.export_header_blink)) {
|
|
assert(defined(invoker.export_class_attribute_blink))
|
|
assert(defined(invoker.export_define_blink))
|
|
assert(defined(invoker.export_header_blink))
|
|
assert(!defined(invoker.component_macro_prefix))
|
|
}
|
|
if (defined(invoker.overridden_deps) || defined(invoker.component_deps)) {
|
|
assert(defined(invoker.overridden_deps))
|
|
assert(defined(invoker.component_deps))
|
|
}
|
|
|
|
if (defined(invoker.overridden_deps_blink) ||
|
|
defined(invoker.component_deps_blink)) {
|
|
assert(defined(invoker.overridden_deps_blink))
|
|
assert(defined(invoker.component_deps_blink))
|
|
}
|
|
|
|
js_bindings_mode = "new"
|
|
if (defined(invoker.js_bindings_mode)) {
|
|
js_bindings_mode = invoker.js_bindings_mode
|
|
}
|
|
if (defined(invoker.use_new_js_bindings) && !invoker.use_new_js_bindings) {
|
|
js_bindings_mode = "old"
|
|
}
|
|
assert(js_bindings_mode == "new" || js_bindings_mode == "both" ||
|
|
js_bindings_mode == "old",
|
|
"Invalid js_bindings_mode value.")
|
|
|
|
all_deps = []
|
|
if (defined(invoker.deps)) {
|
|
all_deps += invoker.deps
|
|
}
|
|
if (defined(invoker.public_deps)) {
|
|
all_deps += invoker.public_deps
|
|
}
|
|
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
assert(defined(invoker.component_output_prefix))
|
|
}
|
|
|
|
group("${target_name}__is_mojom") {
|
|
}
|
|
|
|
# Explicitly ensure that all dependencies (invoker.deps and
|
|
# invoker.public_deps) are mojom targets.
|
|
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})" ]
|
|
}
|
|
}
|
|
|
|
# Generate code that is shared by different variants.
|
|
if (defined(invoker.sources)) {
|
|
common_generator_args = [
|
|
"--use_bundled_pylibs",
|
|
"generate",
|
|
"{{source}}",
|
|
"-d",
|
|
rebase_path("//", root_build_dir),
|
|
"-I",
|
|
rebase_path("//", root_build_dir),
|
|
"-o",
|
|
rebase_path(root_gen_dir, root_build_dir),
|
|
"--bytecode_path",
|
|
rebase_path("$root_gen_dir/mojo/public/tools/bindings", root_build_dir),
|
|
]
|
|
|
|
if (!defined(invoker.scramble_message_ids) || invoker.scramble_message_ids) {
|
|
# Scramble message IDs if enabled, unless the target has explicitly opted
|
|
# out.
|
|
if (enable_scrambled_message_ids) {
|
|
assert(mojom_message_id_salt_path != "")
|
|
common_generator_args += [
|
|
"--scrambled_message_id_salt_path",
|
|
rebase_path(mojom_message_id_salt_path, root_build_dir),
|
|
]
|
|
|
|
if (mojom_message_id_salt_suffix_path != "") {
|
|
common_generator_args += [
|
|
"--scrambled_message_id_salt_path",
|
|
rebase_path(mojom_message_id_salt_suffix_path, root_build_dir),
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!defined(invoker.allow_native_structs) || invoker.allow_native_structs) {
|
|
common_generator_args += [ "--allow_native_structs" ]
|
|
}
|
|
|
|
if (defined(invoker.import_dirs)) {
|
|
foreach(import_dir, invoker.import_dirs) {
|
|
common_generator_args += [
|
|
"-I",
|
|
rebase_path(import_dir, root_build_dir),
|
|
]
|
|
}
|
|
}
|
|
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
shared_component_export_macro =
|
|
"${invoker.component_macro_prefix}_SHARED_EXPORT"
|
|
shared_component_impl_macro =
|
|
"${invoker.component_macro_prefix}_SHARED_IMPL"
|
|
shared_component_output_name = "${invoker.component_output_prefix}_shared"
|
|
} else if (defined(invoker.export_class_attribute_shared) ||
|
|
defined(invoker.export_class_attribute)) {
|
|
if (defined(invoker.export_class_attribute_shared)) {
|
|
assert(defined(invoker.export_header_shared))
|
|
shared_component_export_macro = invoker.export_class_attribute_shared
|
|
shared_component_impl_macro = invoker.export_define_shared
|
|
} else {
|
|
assert(!defined(invoker.export_header_shared))
|
|
|
|
# If no explicit shared attribute/define was provided by the invoker,
|
|
# we derive some reasonable settings frorm the default variant. A new
|
|
# export header will be generated for these and used by shared code.
|
|
shared_component_export_macro =
|
|
"MOJOM_SHARED_" + invoker.export_class_attribute
|
|
shared_component_impl_macro = "MOJOM_SHARED_" + invoker.export_define
|
|
}
|
|
|
|
if (defined(invoker.component_output_prefix)) {
|
|
shared_component_output_name =
|
|
"${invoker.component_output_prefix}_shared"
|
|
} else {
|
|
shared_component_output_name = "${target_name}_shared"
|
|
}
|
|
}
|
|
|
|
if (defined(shared_component_export_macro) &&
|
|
!defined(invoker.export_header_shared)) {
|
|
generated_shared_export_header =
|
|
rebase_path("${target_name}_shared_export.h", "", target_gen_dir)
|
|
shared_export_header =
|
|
rebase_path(generated_shared_export_header, root_gen_dir)
|
|
} else if (defined(invoker.export_header_shared)) {
|
|
shared_export_header = invoker.export_header_shared
|
|
}
|
|
|
|
generator_shared_cpp_outputs = [
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom-shared-internal.h",
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom-shared.cc",
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom-shared.h",
|
|
]
|
|
generator_shared_target_name = "${target_name}_shared__generator"
|
|
action_foreach(generator_shared_target_name) {
|
|
script = mojom_generator_script
|
|
inputs = mojom_generator_sources
|
|
sources = invoker.sources
|
|
deps = [
|
|
"//mojo/public/tools/bindings:precompile_templates",
|
|
]
|
|
outputs = generator_shared_cpp_outputs
|
|
args = common_generator_args
|
|
args += [
|
|
"--generate_non_variant_code",
|
|
"-g",
|
|
"c++",
|
|
]
|
|
depfile = "{{source_gen_dir}}/${generator_shared_target_name}_{{source_name_part}}.d"
|
|
args += [
|
|
"--depfile",
|
|
depfile,
|
|
"--depfile_target",
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom-shared-internal.h",
|
|
]
|
|
|
|
if (defined(shared_component_export_macro)) {
|
|
args += [
|
|
"--export_attribute",
|
|
shared_component_export_macro,
|
|
"--export_header",
|
|
shared_export_header,
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
if (defined(generated_shared_export_header)) {
|
|
shared_export_generator_target_name =
|
|
"${target_name}__generate_shared_export_header"
|
|
action(shared_export_generator_target_name) {
|
|
script = generate_export_header_script
|
|
outputs = [
|
|
get_path_info(generated_shared_export_header, "abspath"),
|
|
]
|
|
args = [
|
|
"--export_macro",
|
|
shared_component_export_macro,
|
|
"--impl_macro",
|
|
shared_component_impl_macro,
|
|
"--output_file",
|
|
rebase_path(generated_shared_export_header, root_build_dir),
|
|
"--relative_path",
|
|
rebase_path(generated_shared_export_header, root_gen_dir),
|
|
]
|
|
}
|
|
}
|
|
|
|
shared_cpp_sources_target_name = "${target_name}_shared_cpp_sources"
|
|
jumbo_source_set(shared_cpp_sources_target_name) {
|
|
if (defined(invoker.testonly)) {
|
|
testonly = invoker.testonly
|
|
}
|
|
deps = []
|
|
if (defined(invoker.sources)) {
|
|
sources =
|
|
process_file_template(invoker.sources, generator_shared_cpp_outputs)
|
|
deps += [ ":$generator_shared_target_name" ]
|
|
}
|
|
public_deps = [
|
|
"//mojo/public/cpp/bindings",
|
|
]
|
|
foreach(d, all_deps) {
|
|
# Resolve the name, so that a target //mojo/something becomes
|
|
# //mojo/something:something and we can append shared_cpp_sources_suffix
|
|
# to get the cpp dependency name.
|
|
full_name = get_label_info("$d", "label_no_toolchain")
|
|
public_deps += [ "${full_name}_shared" ]
|
|
}
|
|
if (defined(shared_component_impl_macro)) {
|
|
defines = [ shared_component_impl_macro ]
|
|
}
|
|
if (defined(generated_shared_export_header)) {
|
|
sources += [ get_path_info(generated_shared_export_header, "abspath") ]
|
|
public_deps += [ ":$shared_export_generator_target_name" ]
|
|
}
|
|
}
|
|
|
|
shared_cpp_library_target_name = "${target_name}_shared"
|
|
if (defined(shared_component_output_name)) {
|
|
component(shared_cpp_library_target_name) {
|
|
if (defined(invoker.testonly)) {
|
|
testonly = invoker.testonly
|
|
}
|
|
output_name = "$shared_component_output_name"
|
|
public_deps = [
|
|
":$shared_cpp_sources_target_name",
|
|
]
|
|
}
|
|
} else {
|
|
group(shared_cpp_library_target_name) {
|
|
if (defined(invoker.testonly)) {
|
|
testonly = invoker.testonly
|
|
}
|
|
public_deps = [
|
|
":$shared_cpp_sources_target_name",
|
|
]
|
|
}
|
|
}
|
|
|
|
# Generate code for variants.
|
|
if (!defined(invoker.disable_variants) || !invoker.disable_variants) {
|
|
enabled_configurations = _bindings_configurations
|
|
} else {
|
|
first_config = _bindings_configurations[0]
|
|
assert(!defined(first_config.variant))
|
|
enabled_configurations = [ first_config ]
|
|
}
|
|
foreach(bindings_configuration, enabled_configurations) {
|
|
cpp_only = false
|
|
if (defined(invoker.cpp_only)) {
|
|
cpp_only = invoker.cpp_only
|
|
}
|
|
variant_suffix = ""
|
|
if (defined(bindings_configuration.variant)) {
|
|
variant = bindings_configuration.variant
|
|
variant_suffix = "_${variant}"
|
|
cpp_only = true
|
|
}
|
|
type_mappings_target_name = "${target_name}${variant_suffix}__type_mappings"
|
|
type_mappings_path =
|
|
"$target_gen_dir/${target_name}${variant_suffix}__type_mappings"
|
|
active_typemaps = []
|
|
enabled_sources = []
|
|
if (defined(invoker.sources)) {
|
|
generator_cpp_outputs = []
|
|
generator_java_outputs = []
|
|
variant_dash_suffix = ""
|
|
if (defined(variant)) {
|
|
variant_dash_suffix = "-${variant}"
|
|
}
|
|
generator_cpp_outputs += [
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom${variant_dash_suffix}.cc",
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom${variant_dash_suffix}.h",
|
|
]
|
|
enabled_sources = []
|
|
if (defined(bindings_configuration.blacklist)) {
|
|
foreach(source, invoker.sources) {
|
|
blacklisted = false
|
|
foreach(blacklisted_source, bindings_configuration.blacklist) {
|
|
if (get_path_info(source, "abspath") == blacklisted_source) {
|
|
blacklisted = true
|
|
}
|
|
}
|
|
if (!blacklisted) {
|
|
enabled_sources += [ source ]
|
|
}
|
|
}
|
|
} else {
|
|
enabled_sources = invoker.sources
|
|
}
|
|
foreach(source, enabled_sources) {
|
|
# TODO(sammc): Use a map instead of a linear scan when GN supports maps.
|
|
foreach(typemap, bindings_configuration.typemaps) {
|
|
_typemap_config = {
|
|
}
|
|
_typemap_config = typemap.config
|
|
if (get_path_info(source, "abspath") == _typemap_config.mojom) {
|
|
enabled = false
|
|
if (!defined(_typemap_config.os_whitelist)) {
|
|
enabled = true
|
|
} else {
|
|
foreach(os, _typemap_config.os_whitelist) {
|
|
if (os == "android" && is_android) {
|
|
enabled = true
|
|
} else if (os == "chromeos" && is_chromeos) {
|
|
enabled = true
|
|
} else if (os == "fuchsia" && is_fuchsia) {
|
|
enabled = true
|
|
} else if (os == "ios" && is_ios) {
|
|
enabled = true
|
|
} else if (os == "linux" && is_linux) {
|
|
enabled = true
|
|
} else if (os == "mac" && is_mac) {
|
|
enabled = true
|
|
} else if (os == "posix" && is_posix) {
|
|
enabled = true
|
|
} else if (os == "win" && is_win) {
|
|
enabled = true
|
|
}
|
|
}
|
|
}
|
|
if (enabled) {
|
|
active_typemaps += [ typemap ]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
export_header_generator_target_name =
|
|
"${target_name}${variant_suffix}__generate_export_header"
|
|
generated_export_header =
|
|
rebase_path("${target_name}${variant_suffix}_export.h",
|
|
"",
|
|
target_gen_dir)
|
|
action(export_header_generator_target_name) {
|
|
script = generate_export_header_script
|
|
outputs = [
|
|
get_path_info(generated_export_header, "abspath"),
|
|
]
|
|
args = [
|
|
"--export_macro",
|
|
"${invoker.component_macro_prefix}${bindings_configuration.component_macro_suffix}_EXPORT",
|
|
"--impl_macro",
|
|
"${invoker.component_macro_prefix}${bindings_configuration.component_macro_suffix}_IMPL",
|
|
"--output_file",
|
|
rebase_path(generated_export_header, root_build_dir),
|
|
"--relative_path",
|
|
rebase_path(generated_export_header, root_gen_dir),
|
|
]
|
|
}
|
|
}
|
|
|
|
if (!cpp_only) {
|
|
generator_java_outputs =
|
|
[ "{{source_gen_dir}}/{{source_name_part}}.mojom.srcjar" ]
|
|
}
|
|
generator_target_name = "${target_name}${variant_suffix}__generator"
|
|
action_foreach(generator_target_name) {
|
|
script = mojom_generator_script
|
|
inputs = mojom_generator_sources
|
|
sources = invoker.sources
|
|
deps = [
|
|
":$type_mappings_target_name",
|
|
"//mojo/public/tools/bindings:precompile_templates",
|
|
]
|
|
outputs = generator_cpp_outputs + generator_java_outputs
|
|
args = common_generator_args
|
|
|
|
if (cpp_only) {
|
|
args += [
|
|
"-g",
|
|
"c++",
|
|
]
|
|
} else {
|
|
args += [
|
|
"-g",
|
|
"c++,java",
|
|
]
|
|
}
|
|
|
|
if (defined(bindings_configuration.variant)) {
|
|
args += [
|
|
"--variant",
|
|
bindings_configuration.variant,
|
|
]
|
|
}
|
|
depfile =
|
|
"{{source_gen_dir}}/${generator_target_name}_{{source_name_part}}.d"
|
|
args += [
|
|
"--depfile",
|
|
depfile,
|
|
"--depfile_target",
|
|
"{{source_gen_dir}}/{{source_name_part}}.mojom${variant_dash_suffix}.cc",
|
|
]
|
|
|
|
args += [
|
|
"--typemap",
|
|
rebase_path(type_mappings_path, root_build_dir),
|
|
]
|
|
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
args += [
|
|
"--export_attribute",
|
|
"${invoker.component_macro_prefix}${bindings_configuration.component_macro_suffix}_EXPORT",
|
|
"--export_header",
|
|
rebase_path(generated_export_header, root_gen_dir),
|
|
]
|
|
}
|
|
|
|
if (defined(bindings_configuration.for_blink) &&
|
|
bindings_configuration.for_blink) {
|
|
args += [ "--for_blink" ]
|
|
if (defined(invoker.export_class_attribute_blink)) {
|
|
args += [
|
|
"--export_attribute",
|
|
invoker.export_class_attribute_blink,
|
|
"--export_header",
|
|
invoker.export_header_blink,
|
|
]
|
|
}
|
|
} else {
|
|
if (defined(invoker.export_class_attribute)) {
|
|
args += [
|
|
"--export_attribute",
|
|
invoker.export_class_attribute,
|
|
"--export_header",
|
|
invoker.export_header,
|
|
]
|
|
}
|
|
}
|
|
|
|
if (!defined(invoker.use_once_callback) || invoker.use_once_callback) {
|
|
args += [ "--use_once_callback" ]
|
|
}
|
|
|
|
if (defined(invoker.support_lazy_serialization) &&
|
|
invoker.support_lazy_serialization) {
|
|
args += [ "--support_lazy_serialization" ]
|
|
}
|
|
}
|
|
}
|
|
|
|
action(type_mappings_target_name) {
|
|
inputs = _bindings_configuration_files
|
|
outputs = [
|
|
type_mappings_path,
|
|
]
|
|
script = "$mojom_generator_root/generate_type_mappings.py"
|
|
deps = []
|
|
args = [
|
|
"--output",
|
|
rebase_path(type_mappings_path, root_build_dir),
|
|
]
|
|
|
|
foreach(d, all_deps) {
|
|
name = get_label_info(d, "label_no_toolchain")
|
|
toolchain = get_label_info(d, "toolchain")
|
|
dependency_output = "${name}${variant_suffix}__type_mappings"
|
|
dependency_target = "${dependency_output}(${toolchain})"
|
|
deps += [ dependency_target ]
|
|
dependency_output_dir =
|
|
get_label_info(dependency_output, "target_gen_dir")
|
|
dependency_name = get_label_info(dependency_output, "name")
|
|
dependency_path =
|
|
rebase_path("$dependency_output_dir/${dependency_name}",
|
|
root_build_dir)
|
|
args += [
|
|
"--dependency",
|
|
dependency_path,
|
|
]
|
|
}
|
|
|
|
if (enabled_sources != []) {
|
|
# TODO(sammc): Pass the typemap description in a file to avoid command
|
|
# line length limitations.
|
|
typemap_description = []
|
|
foreach(typemap, active_typemaps) {
|
|
_typemap_config = {
|
|
}
|
|
_typemap_config = typemap.config
|
|
typemap_description += [ "--start-typemap" ]
|
|
if (defined(_typemap_config.public_headers)) {
|
|
foreach(value, _typemap_config.public_headers) {
|
|
typemap_description += [ "public_headers=$value" ]
|
|
}
|
|
}
|
|
if (defined(_typemap_config.traits_headers)) {
|
|
foreach(value, _typemap_config.traits_headers) {
|
|
typemap_description += [ "traits_headers=$value" ]
|
|
}
|
|
}
|
|
foreach(value, _typemap_config.type_mappings) {
|
|
typemap_description += [ "type_mappings=$value" ]
|
|
}
|
|
|
|
# The typemap configuration files are not actually used as inputs here
|
|
# but this establishes a necessary build dependency to ensure that
|
|
# typemap changes force a rebuild of affected targets.
|
|
inputs += [ typemap.filename ]
|
|
}
|
|
args += typemap_description
|
|
}
|
|
}
|
|
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
output_target_type = "component"
|
|
} else {
|
|
output_target_type = "source_set"
|
|
}
|
|
|
|
target("jumbo_" + output_target_type, "${target_name}${variant_suffix}") {
|
|
if (defined(bindings_configuration.for_blink) &&
|
|
bindings_configuration.for_blink &&
|
|
defined(invoker.visibility_blink)) {
|
|
visibility = invoker.visibility_blink
|
|
} else if (defined(invoker.visibility)) {
|
|
visibility = invoker.visibility
|
|
}
|
|
if (defined(invoker.testonly)) {
|
|
testonly = invoker.testonly
|
|
}
|
|
defines = []
|
|
if (defined(invoker.testonly)) {
|
|
testonly = invoker.testonly
|
|
}
|
|
if (defined(invoker.export_define)) {
|
|
defines += [ invoker.export_define ]
|
|
}
|
|
if (defined(invoker.export_define_blink)) {
|
|
defines += [ invoker.export_define_blink ]
|
|
}
|
|
if (enabled_sources != []) {
|
|
sources = process_file_template(enabled_sources, generator_cpp_outputs)
|
|
}
|
|
deps = [
|
|
"//mojo/public/cpp/bindings:struct_traits",
|
|
"//mojo/public/interfaces/bindings:bindings__generator",
|
|
"//mojo/public/interfaces/bindings:bindings_shared__generator",
|
|
]
|
|
public_deps = [
|
|
":$shared_cpp_library_target_name",
|
|
"//base",
|
|
"//mojo/public/cpp/bindings",
|
|
]
|
|
if (enabled_sources != []) {
|
|
public_deps += [ ":$generator_target_name" ]
|
|
}
|
|
if (defined(invoker.component_macro_prefix)) {
|
|
output_name = "${invoker.component_output_prefix}${variant_suffix}"
|
|
defines += [ "${invoker.component_macro_prefix}${bindings_configuration.component_macro_suffix}_IMPL" ]
|
|
sources += [ get_path_info(generated_export_header, "abspath") ]
|
|
deps += [ ":$export_header_generator_target_name" ]
|
|
}
|
|
foreach(d, all_deps) {
|
|
# Resolve the name, so that a target //mojo/something becomes
|
|
# //mojo/something:something and we can append variant_suffix to
|
|
# get the cpp dependency name.
|
|
full_name = get_label_info("$d", "label_no_toolchain")
|
|
public_deps += [ "${full_name}${variant_suffix}" ]
|
|
}
|
|
if (defined(bindings_configuration.for_blink) &&
|
|
bindings_configuration.for_blink) {
|
|
if (defined(invoker.overridden_deps_blink)) {
|
|
foreach(d, invoker.overridden_deps_blink) {
|
|
# Resolve the name, so that a target //mojo/something becomes
|
|
# //mojo/something:something and we can append variant_suffix
|
|
# to get the cpp dependency name.
|
|
full_name = get_label_info("$d", "label_no_toolchain")
|
|
public_deps -= [ "${full_name}${variant_suffix}" ]
|
|
}
|
|
public_deps += invoker.component_deps_blink
|
|
}
|
|
} else {
|
|
if (defined(invoker.overridden_deps)) {
|
|
foreach(d, invoker.overridden_deps) {
|
|
# Resolve the name, so that a target //mojo/something becomes
|
|
# //mojo/something:something and we can append variant_suffix
|
|
# to get the cpp dependency name.
|
|
full_name = get_label_info("$d", "label_no_toolchain")
|
|
public_deps -= [ "${full_name}${variant_suffix}" ]
|
|
}
|
|
public_deps += invoker.component_deps
|
|
}
|
|
}
|
|
foreach(typemap, active_typemaps) {
|
|
_typemap_config = {
|
|
}
|
|
_typemap_config = typemap.config
|
|
if (defined(_typemap_config.public_headers)) {
|
|
sources += _typemap_config.public_headers
|
|
}
|
|
if (defined(_typemap_config.traits_headers)) {
|
|
sources += _typemap_config.traits_headers
|
|
}
|
|
if (defined(_typemap_config.sources)) {
|
|
sources += _typemap_config.sources
|
|
}
|
|
if (defined(_typemap_config.public_deps)) {
|
|
public_deps += _typemap_config.public_deps
|
|
}
|
|
if (defined(_typemap_config.deps)) {
|
|
deps += _typemap_config.deps
|
|
}
|
|
}
|
|
if (defined(invoker.export_header)) {
|
|
sources += [ "//" + invoker.export_header ]
|
|
}
|
|
if (defined(bindings_configuration.for_blink) &&
|
|
bindings_configuration.for_blink) {
|
|
public_deps += [ "//mojo/public/cpp/bindings:wtf_support" ]
|
|
}
|
|
}
|
|
|
|
if (!cpp_only && is_android) {
|
|
import("//build/config/android/rules.gni")
|
|
|
|
java_srcjar_target_name = target_name + "_java_sources"
|
|
action(java_srcjar_target_name) {
|
|
script = "//mojo/public/tools/gn/zip.py"
|
|
inputs = []
|
|
if (enabled_sources != []) {
|
|
inputs =
|
|
process_file_template(enabled_sources, generator_java_outputs)
|
|
}
|
|
output = "$target_gen_dir/$target_name.srcjar"
|
|
outputs = [
|
|
output,
|
|
]
|
|
rebase_inputs = rebase_path(inputs, root_build_dir)
|
|
rebase_output = rebase_path(output, root_build_dir)
|
|
args = [
|
|
"--zip-inputs=$rebase_inputs",
|
|
"--output=$rebase_output",
|
|
]
|
|
deps = []
|
|
if (enabled_sources != []) {
|
|
deps = [
|
|
":$generator_target_name",
|
|
]
|
|
}
|
|
}
|
|
|
|
java_target_name = target_name + "_java"
|
|
android_library(java_target_name) {
|
|
deps = [
|
|
"//base:base_java",
|
|
"//mojo/public/java:bindings_java",
|
|
"//mojo/public/java:system_java",
|
|
]
|
|
|
|
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" ]
|
|
}
|
|
|
|
srcjar_deps = [ ":$java_srcjar_target_name" ]
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!defined(invoker.cpp_only) || !invoker.cpp_only) {
|
|
if (defined(invoker.sources)) {
|
|
generator_js_target_name = "${target_name}_js__generator"
|
|
generator_js_outputs =
|
|
[ "{{source_gen_dir}}/{{source_name_part}}.mojom.js" ]
|
|
action_foreach(generator_js_target_name) {
|
|
script = mojom_generator_script
|
|
inputs = mojom_generator_sources
|
|
sources = []
|
|
if (defined(invoker.sources)) {
|
|
sources += invoker.sources
|
|
}
|
|
deps = [
|
|
"//mojo/public/tools/bindings:precompile_templates",
|
|
]
|
|
outputs = generator_js_outputs
|
|
args = common_generator_args
|
|
args += [
|
|
"-g",
|
|
"javascript",
|
|
]
|
|
|
|
args += [
|
|
"--js_bindings_mode",
|
|
js_bindings_mode,
|
|
]
|
|
}
|
|
}
|
|
|
|
js_target_name = target_name + "_js"
|
|
group(js_target_name) {
|
|
public_deps = []
|
|
if (defined(invoker.sources)) {
|
|
public_deps += [ ":$generator_js_target_name" ]
|
|
}
|
|
|
|
foreach(d, all_deps) {
|
|
full_name = get_label_info(d, "label_no_toolchain")
|
|
public_deps += [ "${full_name}_js" ]
|
|
}
|
|
}
|
|
|
|
js_data_deps_target_name = target_name + "_js_data_deps"
|
|
group(js_data_deps_target_name) {
|
|
deps = []
|
|
if (defined(invoker.sources)) {
|
|
data = process_file_template(invoker.sources, generator_js_outputs)
|
|
deps += [ ":$generator_js_target_name" ]
|
|
}
|
|
|
|
data_deps = []
|
|
foreach(d, all_deps) {
|
|
full_name = get_label_info(d, "label_no_toolchain")
|
|
data_deps += [ "${full_name}_js_data_deps" ]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# A helper for the mojom() template above when component libraries are desired
|
|
# for generated C++ bindings units. Supports all the same arguments as mojom()
|
|
# except for the optional |component_output_prefix| and |component_macro_prefix|
|
|
# arguments. These are instead shortened to |output_prefix| and |macro_prefix|
|
|
# and are *required*.
|
|
template("mojom_component") {
|
|
assert(defined(invoker.output_prefix) && defined(invoker.macro_prefix))
|
|
|
|
mojom(target_name) {
|
|
forward_variables_from(invoker,
|
|
"*",
|
|
[
|
|
"output_prefix",
|
|
"macro_prefix",
|
|
])
|
|
component_output_prefix = invoker.output_prefix
|
|
component_macro_prefix = invoker.macro_prefix
|
|
}
|
|
}
|