summaryrefslogtreecommitdiff
path: root/utils/ipc/mojo/public/tools/bindings
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2020-09-08 20:47:19 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2021-05-26 13:03:27 +0900
commit139d8855747799da9218f36720004fb1927bd2ef (patch)
tree7f3f47e68e08cfcf19ee9f37cc91f31690b9fc53 /utils/ipc/mojo/public/tools/bindings
parenta7ded8e8f5dd0ae0841960280fe9a7107f945a34 (diff)
utils: ipc: Update mojo
Update mojo from the Chromium repository. The commit from which this was taken is: 9c138d992bfc1fb8f4f7bcf58d00bf19c219e4e2 "Updating trunk VERSION from 4523.0 to 4524.0" The update-mojo.sh script was used for this update. Bug: https://bugs.libcamera.org/show_bug.cgi?id=34 Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'utils/ipc/mojo/public/tools/bindings')
-rw-r--r--utils/ipc/mojo/public/tools/bindings/BUILD.gn9
-rw-r--r--utils/ipc/mojo/public/tools/bindings/README.md187
-rw-r--r--utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py8
-rwxr-xr-xutils/ipc/mojo/public/tools/bindings/generate_type_mappings.py60
-rw-r--r--utils/ipc/mojo/public/tools/bindings/mojom.gni526
5 files changed, 464 insertions, 326 deletions
diff --git a/utils/ipc/mojo/public/tools/bindings/BUILD.gn b/utils/ipc/mojo/public/tools/bindings/BUILD.gn
index 8ba6e922..3e242532 100644
--- a/utils/ipc/mojo/public/tools/bindings/BUILD.gn
+++ b/utils/ipc/mojo/public/tools/bindings/BUILD.gn
@@ -2,10 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import("//build/config/python.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//third_party/jinja2/jinja2.gni")
-action("precompile_templates") {
+# TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+python2_action("precompile_templates") {
sources = mojom_generator_sources
sources += [
"$mojom_generator_root/generators/cpp_templates/enum_macros.tmpl",
@@ -69,11 +71,16 @@ action("precompile_templates") {
"$mojom_generator_root/generators/js_templates/fuzzing.tmpl",
"$mojom_generator_root/generators/js_templates/interface_definition.tmpl",
"$mojom_generator_root/generators/js_templates/lite/enum_definition.tmpl",
+ "$mojom_generator_root/generators/js_templates/lite/enum_definition_for_module.tmpl",
"$mojom_generator_root/generators/js_templates/lite/interface_definition.tmpl",
+ "$mojom_generator_root/generators/js_templates/lite/interface_definition_for_module.tmpl",
"$mojom_generator_root/generators/js_templates/lite/module_definition.tmpl",
"$mojom_generator_root/generators/js_templates/lite/mojom-lite.js.tmpl",
+ "$mojom_generator_root/generators/js_templates/lite/mojom.m.js.tmpl",
"$mojom_generator_root/generators/js_templates/lite/struct_definition.tmpl",
+ "$mojom_generator_root/generators/js_templates/lite/struct_definition_for_module.tmpl",
"$mojom_generator_root/generators/js_templates/lite/union_definition.tmpl",
+ "$mojom_generator_root/generators/js_templates/lite/union_definition_for_module.tmpl",
"$mojom_generator_root/generators/js_templates/module.amd.tmpl",
"$mojom_generator_root/generators/js_templates/module_definition.tmpl",
"$mojom_generator_root/generators/js_templates/struct_definition.tmpl",
diff --git a/utils/ipc/mojo/public/tools/bindings/README.md b/utils/ipc/mojo/public/tools/bindings/README.md
index 1a3d5c58..43882450 100644
--- a/utils/ipc/mojo/public/tools/bindings/README.md
+++ b/utils/ipc/mojo/public/tools/bindings/README.md
@@ -113,8 +113,8 @@ for message parameters.
Every Mojom file may optionally specify a single **module** to which it belongs.
-This is used strictly for aggregaging all defined symbols therein within a
-common Mojom namespace. The specific impact this has on generated binidngs code
+This is used strictly for aggregating all defined symbols therein within a
+common Mojom namespace. The specific impact this has on generated bindings code
varies for each target language. For example, if the following Mojom is used to
generate bindings:
@@ -132,7 +132,7 @@ Generated C++ bindings will define a class interface `MoneyGenerator` in the
bindings at this time are unaffected by module declarations.
**NOTE:** By convention in the Chromium codebase, **all** Mojom files should
-declare a module name with at least (and preferrably exactly) one top-level name
+declare a module name with at least (and preferably exactly) one top-level name
as well as an inner `mojom` module suffix. *e.g.*, `chrome.mojom`,
`business.mojom`, *etc.*
@@ -271,7 +271,7 @@ code, see
### Unions
Mojom supports tagged unions using the **union** keyword. A union is a
-collection of fields which may taken the value of any single one of those fields
+collection of fields which may take the value of any single one of those fields
at a time. Thus they provide a way to represent a variant value type while
minimizing storage requirements.
@@ -320,7 +320,7 @@ enum definition. By default, values are based at zero and increment by
1 sequentially.
The effect of nested definitions on generated bindings varies depending on the
-target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages)
+target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages).
### Constants
@@ -346,7 +346,7 @@ struct Employee {
```
The effect of nested definitions on generated bindings varies depending on the
-target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages)
+target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages).
### Interfaces
@@ -379,58 +379,82 @@ Mojom definitions may have their meaning altered by **attributes**, specified
with a syntax similar to Java or C# attributes. There are a handle of
interesting attributes supported today.
-**`[Sync]`**
-: The `Sync` attribute may be specified for any interface method which expects
- a response. This makes it so that callers of the method can wait
- synchronously for a response. See
- [Synchronous Calls](/mojo/public/cpp/bindings/README.md#Synchronous-Calls)
- in the C++ bindings documentation. Note that sync methods are only actually
- synchronous when called from C++.
-
-**`[Extensible]`**
-: The `Extensible` attribute may be specified for any enum definition. This
- essentially disables builtin range validation when receiving values of the
- enum type in a message, allowing older bindings to tolerate unrecognized
- values from newer versions of the enum.
-
-**`[Native]`**
-: The `Native` attribute may be specified for an empty struct declaration to
- provide a nominal bridge between Mojo IPC and legacy `IPC::ParamTraits` or
- `IPC_STRUCT_TRAITS*` macros.
- See
- [Repurposing Legacy IPC Traits](/docs/mojo_ipc_conversion.md#repurposing-and-invocations)
- for more details. Note support for this attribute is strictly limited to C++
- bindings generation.
-
-**`[MinVersion=N]`**
-: The `MinVersion` attribute is used to specify the version at which a given
- field, enum value, interface method, or method parameter was introduced.
- See [Versioning](#Versioning) for more details.
-
-**`[Stable]`**
-: The `Stable` attribute specifies that a given mojom type or interface
- definition can be considered stable over time, meaning it is safe to use for
- things like persistent storage or communication between independent
- version-skewed binaries. Stable definitions may only depend on builtin mojom
- types or other stable definitions, and changes to such definitions MUST
- preserve backward-compatibility through appropriate use of versioning.
- Backward-compatibility of changes is enforced in the Chromium tree using a
- strict presubmit check. See [Versioning](#Versioning) for more details on
- backward-compatibility constraints.
-
-**`[EnableIf=value]`**
-: The `EnableIf` attribute is used to conditionally enable definitions when
- the mojom is parsed. If the `mojom` target in the GN file does not include
- the matching `value` in the list of `enabled_features`, the definition
- will be disabled. This is useful for mojom definitions that only make
- sense on one platform. Note that the `EnableIf` attribute can only be set
- once per definition.
+* **`[Sync]`**:
+ The `Sync` attribute may be specified for any interface method which expects a
+ response. This makes it so that callers of the method can wait synchronously
+ for a response. See [Synchronous
+ Calls](/mojo/public/cpp/bindings/README.md#Synchronous-Calls) in the C++
+ bindings documentation. Note that sync methods are only actually synchronous
+ when called from C++.
+
+* **`[NoInterrupt]`**:
+ When a thread is waiting for a reply to a `Sync` message, it's possible to be
+ woken up to dispatch other unrelated incoming `Sync` messages. This measure
+ helps to avoid deadlocks. If a `Sync` message is also marked as `NoInterrupt`
+ however, this behavior is disabled: instead the calling thread will only wake
+ up for the precise message being waited upon. This attribute must be used with
+ extreme caution, because it can lead to deadlocks otherwise.
+
+* **`[Default]`**:
+ The `Default` attribute may be used to specify an enumerator value that
+ will be used if an `Extensible` enumeration does not deserialize to a known
+ value on the receiver side, i.e. the sender is using a newer version of the
+ enum. This allows unknown values to be mapped to a well-defined value that can
+ be appropriately handled.
+
+* **`[Extensible]`**:
+ The `Extensible` attribute may be specified for any enum definition. This
+ essentially disables builtin range validation when receiving values of the
+ enum type in a message, allowing older bindings to tolerate unrecognized
+ values from newer versions of the enum.
+
+ Note: in the future, an `Extensible` enumeration will require that a `Default`
+ enumerator value also be specified.
+
+* **`[Native]`**:
+ The `Native` attribute may be specified for an empty struct declaration to
+ provide a nominal bridge between Mojo IPC and legacy `IPC::ParamTraits` or
+ `IPC_STRUCT_TRAITS*` macros. See [Repurposing Legacy IPC
+ Traits](/docs/mojo_ipc_conversion.md#repurposing-and-invocations) for more
+ details. Note support for this attribute is strictly limited to C++ bindings
+ generation.
+
+* **`[MinVersion=N]`**:
+ The `MinVersion` attribute is used to specify the version at which a given
+ field, enum value, interface method, or method parameter was introduced.
+ See [Versioning](#Versioning) for more details.
+
+* **`[Stable]`**:
+ The `Stable` attribute specifies that a given mojom type or interface
+ definition can be considered stable over time, meaning it is safe to use for
+ things like persistent storage or communication between independent
+ version-skewed binaries. Stable definitions may only depend on builtin mojom
+ types or other stable definitions, and changes to such definitions MUST
+ preserve backward-compatibility through appropriate use of versioning.
+ Backward-compatibility of changes is enforced in the Chromium tree using a
+ strict presubmit check. See [Versioning](#Versioning) for more details on
+ backward-compatibility constraints.
+
+* **`[Uuid=<UUID>]`**:
+ Specifies a UUID to be associated with a given interface. The UUID is intended
+ to remain stable across all changes to the interface definition, including
+ name changes. The value given for this attribute should be a standard UUID
+ string representation as specified by RFC 4122. New UUIDs can be generated
+ with common tools such as `uuidgen`.
+
+* **`[EnableIf=value]`**:
+ The `EnableIf` attribute is used to conditionally enable definitions when the
+ mojom is parsed. If the `mojom` target in the GN file does not include the
+ matching `value` in the list of `enabled_features`, the definition will be
+ disabled. This is useful for mojom definitions that only make sense on one
+ platform. Note that the `EnableIf` attribute can only be set once per
+ definition.
## Generated Code For Target Languages
When the bindings generator successfully processes an input Mojom file, it emits
corresponding code for each supported target language. For more details on how
-Mojom concepts translate to a given target langauge, please refer to the
+Mojom concepts translate to a given target language, please refer to the
bindings API documentation for that language:
* [C++ Bindings](/mojo/public/cpp/bindings/README.md)
@@ -441,7 +465,7 @@ bindings API documentation for that language:
Regardless of target language, all interface messages are validated during
deserialization before they are dispatched to a receiving implementation of the
-interface. This helps to ensure consitent validation across interfaces without
+interface. This helps to ensure consistent validation across interfaces without
leaving the burden to developers and security reviewers every time a new message
is added.
@@ -555,25 +579,37 @@ struct Employee {
};
```
-and you would like to add a birthday field. You can do:
+and you would like to add birthday and nickname fields. You can add them as
+optional types with a `MinVersion` like so:
``` cpp
struct Employee {
uint64 employee_id;
string name;
[MinVersion=1] Date? birthday;
+ [MinVersion=1] string? nickname;
};
```
+*** note
+**NOTE:** Mojo object or handle types added with a `MinVersion` **MUST** be
+optional (nullable). See [Primitive Types](#Primitive-Types) for details on
+nullable values.
+***
+
By default, fields belong to version 0. New fields must be appended to the
struct definition (*i.e*., existing fields must not change **ordinal value**)
with the `MinVersion` attribute set to a number greater than any previous
existing versions.
+The value of `MinVersion` is unrelated to ordinals. The choice of a particular
+version number is arbitrary. All its usage means is that a field isn't present
+before the numbered version.
+
*** note
**NOTE:** do not change existing fields in versioned structs, as this is
not backwards-compatible. Instead, rename the old field to make its
-deprecation clear and add a new field with the new version number.
+deprecation clear and add a new field with a new `MinVersion` number.
***
**Ordinal value** refers to the relative positional layout of a struct's fields
@@ -602,14 +638,10 @@ struct Employee {
uint64 employee_id@0;
[MinVersion=1] Date? birthday@2;
string name@1;
+ [MinVersion=1] string? nickname@3;
};
```
-*** note
-**NOTE:** Newly added fields of Mojo object or handle types MUST be nullable.
-See [Primitive Types](#Primitive-Types).
-***
-
### Versioned Interfaces
There are two dimensions on which an interface can be extended
@@ -706,6 +738,39 @@ values and will need to deal with them gracefully. See
[C++ Versioning Considerations](/mojo/public/cpp/bindings/README.md#Versioning-Considerations)
for details.
+### Renaming versioned structs
+It's possible to rename versioned structs by using the `[RenamedFrom]` attribute.
+RenamedFrom
+
+``` cpp
+module asdf.mojom;
+
+// Old version:
+[Stable]
+struct OldStruct {
+};
+
+// New version:
+[Stable, RenamedFrom="asdf.mojom.OldStruct"]
+struct NewStruct {
+};
+```
+
+## Component targets
+
+If there are multiple components depending on the same mojom target within one binary,
+the target will need to be defined as `mojom_component` instead of `mojom`.
+Since `mojom` targets are generated `source_set` targets and `mojom_component` targets
+are generated `component` targets, you would use `mojom_component` in the same cases
+where you would use `component` for non-mojom files.
+*** note
+**NOTE**: by default, components for both blink and non-blink bindings are generated.
+Use the `disable_variants` target parameter to generate only non-blink bindings.
+You can also generate a `source_set` for one of the variants by defining
+[export_*](https://source.chromium.org/chromium/chromium/src/+/main:mojo/public/tools/bindings/mojom.gni;drc=739b9fbce50310c1dd2b59c279cd90a9319cb6e8;l=318)
+parameters for the `mojom_component` target.
+***
+
## Grammar Reference
Below is the (BNF-ish) context-free grammar of the Mojom language:
diff --git a/utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py b/utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py
index 79c9e50e..8b78d092 100644
--- a/utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py
+++ b/utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py
@@ -18,7 +18,6 @@ import os
import re
import sys
-from cStringIO import StringIO
from optparse import OptionParser
sys.path.insert(
@@ -41,12 +40,9 @@ def main():
pattern = re.compile(options.pattern)
files = [f for f in os.listdir(options.directory) if pattern.match(f)]
- stream = StringIO()
- for f in files:
- print(f, file=stream)
+ contents = '\n'.join(f for f in files) + '\n'
+ WriteFile(contents, options.output)
- WriteFile(stream.getvalue(), options.output)
- stream.close()
if __name__ == '__main__':
sys.exit(main())
diff --git a/utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py b/utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py
index 64ca048f..a0096649 100755
--- a/utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py
+++ b/utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py
@@ -75,14 +75,6 @@ def ReadTypemap(path):
return json.load(f)['c++']
-def ParseTypemapArgs(args):
- typemaps = [s for s in '\n'.join(args).split('--start-typemap\n') if s]
- result = {}
- for typemap in typemaps:
- result.update(ParseTypemap(typemap))
- return result
-
-
def LoadCppTypemapConfig(path):
configs = {}
with open(path) as f:
@@ -102,52 +94,6 @@ def LoadCppTypemapConfig(path):
}
return configs
-
-def ParseTypemap(typemap):
- values = {'type_mappings': [], 'public_headers': [], 'traits_headers': []}
- for line in typemap.split('\n'):
- if not line:
- continue
- key, _, value = line.partition('=')
- values[key].append(value.lstrip('/'))
- result = {}
- mapping_pattern = \
- re.compile(r"""^([^=]+) # mojom type
- =
- ([^[]+) # native type
- (?:\[([^]]+)\])?$ # optional attribute in square brackets
- """, re.X)
- for typename in values['type_mappings']:
- match_result = mapping_pattern.match(typename)
- assert match_result, (
- "Cannot parse entry in the \"type_mappings\" section: %s" % typename)
-
- mojom_type = match_result.group(1)
- native_type = match_result.group(2)
- attributes = []
- if match_result.group(3):
- attributes = match_result.group(3).split(',')
-
- assert mojom_type not in result, (
- "Cannot map multiple native types (%s, %s) to the same mojom type: %s" %
- (result[mojom_type]['typename'], native_type, mojom_type))
-
- result[mojom_type] = {
- 'public_headers': values['public_headers'],
- 'traits_headers': values['traits_headers'],
- 'typename': native_type,
-
- # Attributes supported for individual mappings.
- 'copyable_pass_by_value': 'copyable_pass_by_value' in attributes,
- 'force_serialize': 'force_serialize' in attributes,
- 'hashable': 'hashable' in attributes,
- 'move_only': 'move_only' in attributes,
- 'non_copyable_non_movable': 'non_copyable_non_movable' in attributes,
- 'nullable_is_same_type': 'nullable_is_same_type' in attributes,
- }
- return result
-
-
def main():
parser = argparse.ArgumentParser(
description=__doc__,
@@ -170,10 +116,10 @@ def main():
type=str,
required=True,
help='The path to which to write the generated JSON.')
- params, typemap_params = parser.parse_known_args()
- typemaps = ParseTypemapArgs(typemap_params)
+ params, _ = parser.parse_known_args()
+ typemaps = {}
if params.cpp_config_path:
- typemaps.update(LoadCppTypemapConfig(params.cpp_config_path))
+ typemaps = LoadCppTypemapConfig(params.cpp_config_path)
missing = [path for path in params.dependency if not os.path.exists(path)]
if missing:
raise IOError('Missing dependencies: %s' % ', '.join(missing))
diff --git a/utils/ipc/mojo/public/tools/bindings/mojom.gni b/utils/ipc/mojo/public/tools/bindings/mojom.gni
index a739fa6e..fe2a1da3 100644
--- a/utils/ipc/mojo/public/tools/bindings/mojom.gni
+++ b/utils/ipc/mojo/public/tools/bindings/mojom.gni
@@ -2,7 +2,7 @@
# 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")
+import("//build/config/python.gni")
import("//third_party/closure_compiler/closure_args.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/protobuf/proto_library.gni")
@@ -64,10 +64,13 @@ declare_args() {
# 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.
+#
+# TODO(crbug.com/1052397): Remove !chromeos_is_browser_only once
+# lacros-chrome switches to target_os="chromeos"
enable_scrambled_message_ids =
enable_mojom_message_id_scrambling &&
- (is_mac || is_win || (is_linux && !is_chromeos && !is_chromecast &&
- !chromeos_is_browser_only) ||
+ (is_mac || is_win ||
+ (is_linux && !is_chromeos_ash && !is_chromecast && !is_chromeos_lacros) ||
((enable_nacl || is_nacl || is_nacl_nonsfi) &&
(target_os != "chromeos" && !chromeos_is_browser_only)))
@@ -78,7 +81,6 @@ mojom_parser_sources = [
"$_mojom_library_root/__init__.py",
"$_mojom_library_root/error.py",
"$_mojom_library_root/generate/__init__.py",
- "$_mojom_library_root/generate/constant_resolver.py",
"$_mojom_library_root/generate/generator.py",
"$_mojom_library_root/generate/module.py",
"$_mojom_library_root/generate/pack.py",
@@ -94,6 +96,7 @@ mojom_generator_root = "$_mojom_tools_root/bindings"
mojom_generator_script = "$mojom_generator_root/mojom_bindings_generator.py"
mojom_generator_sources =
mojom_parser_sources + [
+ "$mojom_generator_root/generators/cpp_util.py",
"$mojom_generator_root/generators/mojom_cpp_generator.py",
"$mojom_generator_root/generators/mojom_java_generator.py",
"$mojom_generator_root/generators/mojom_mojolpm_generator.py",
@@ -107,17 +110,6 @@ if (enable_scrambled_message_ids) {
# 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 = ""
- }
}
assert(mojom_message_id_salt_path != "")
@@ -126,56 +118,11 @@ if (enable_scrambled_message_ids) {
rebase_path(mojom_message_id_salt_path, root_build_dir),
]
message_scrambling_inputs = [ mojom_message_id_salt_path ]
-
- if (mojom_message_id_salt_suffix_path != "") {
- message_scrambling_args += [
- "--scrambled_message_id_salt_path",
- rebase_path(mojom_message_id_salt_suffix_path, root_build_dir),
- ]
- message_scrambling_inputs += [ mojom_message_id_salt_suffix_path ]
- }
} else {
message_scrambling_args = []
message_scrambling_inputs = []
}
-if (enable_mojom_typemapping) {
- _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 = ""
- },
- ]
-}
-
-if (!is_ios) {
- _bindings_configurations += [
- {
- 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.
@@ -218,6 +165,15 @@ if (!is_ios) {
# import_dirs (optional)
# List of import directories that will get added when processing sources.
#
+# input_root_override (optional)
+# Root path for the .mojom files used to generate the namespaces for
+# interfaces. Useful with targets outside //, e.g. in parent directories
+# above "//". The default input root is //
+# Example: Vivaldi's source root is "//vivaldi/",
+# and "//vivaldi/chromium/" is "//"
+# In such cases, not using this argument lead to the output files being
+# located in different directories than expected.
+#
# testonly (optional)
#
# visibility (optional)
@@ -245,6 +201,43 @@ if (!is_ios) {
# blink_cpp_typemaps (optional)
# Same as above, but for the Blink variant of generated C++ bindings.
#
+# cpp_proxy_target (optional)
+# The name of a target which all C++ dependencies will link against
+# instead of linking directly against this mojom target's generated C++
+# sources. Normally when declaring invoking the mojom("foo") target, GN
+# emits a source_set or component target named "foo" which encompasses the
+# default variant of generated C++ bindings. This changes that to instead
+# emit a group("foo") which merely forwards public_deps to the named
+# `cpp_proxy_target`. That target must in turn depend on
+# "foo_cpp_sources".
+#
+# This is useful primarily in conjunction with export_define et al to
+# embed generated C++ bindings within an existing component target.
+#
+# blink_cpp_proxy_target (optional)
+# Same concept as `cpp_proxy_target` above, but affects the generated
+# "foo_blink" Blink-variant C++ bindings.
+#
+# cpp_configs (optional)
+# A list of extra configs to apply to the default variant of generated C++
+# bindings.
+#
+# blink_cpp_configs (optional)
+# A list of extra configs to apply to the Blink variant of generated C++
+# bindings.
+#
+# mojom_source_deps (optional)
+# A list of mojoms this target depends upon. This is equivalent to
+# public_deps except that the C++ bindings depend on each of the named
+# "foo" targets' "foo_cpp_sources" rather than on foo's
+# `cpp_proxy_target`. It only makes sense to use this for dependencies
+# that set `cpp_proxy_target`, and only when the dependent mojom() would
+# otherwise have circular dependencies with that proxy target.
+#
+# mojom_blink_source_deps (optional)
+# Same as above but depends on "foo_blink_cpp_sources" and is used for
+# dependencies that specify a `blink_cpp_proxy_target`.
+#
# generate_java (optional)
# If set to true, Java bindings are generated for Android builds. If
# |cpp_only| is set to true, it overrides this to prevent generation of
@@ -327,6 +320,21 @@ if (!is_ios) {
# List of extra C++ templates that are used to generate additional source
# and/or header files. The templates should end with extension ".tmpl".
#
+# webui_module_path (optional)
+# The path or URL at which modules generated by this target will be
+# accessible to WebUI pages. This may either be an absolute path or
+# a full URL path starting with "chrome://resources/mojo".
+#
+# If an absolute path, a WebUI page may only import these modules if
+# they are manually packaged and mapped independently by that page's
+# WebUIDataSource. The mapped path must match the path given here.
+#
+# If this is is instead a URL string starting with
+# "chrome://resources/mojo", the generated resources must be added to
+# content_resources.grd and registered with
+# content::SharedResourcesDataSource with a corresponding path, at which
+# point they will be made available to all WebUI pages at the given URL.
+#
# 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
@@ -410,8 +418,8 @@ if (!is_ios) {
# traits for the type must define IsNull and SetToNull methods.
#
# When false, nullable fields are represented by wrapping the C++
-# type with base::Optional, and null values are simply
-# base::nullopt.
+# type with absl::optional, and null values are simply
+# absl::nullopt.
#
# hashable (optional)
# A boolean value (default false) indicating whether the C++ type is
@@ -463,14 +471,15 @@ template("mojom") {
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_define) || defined(invoker.cpp_configs))
assert(defined(invoker.export_header))
}
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_define_blink) ||
+ defined(invoker.blink_cpp_configs))
assert(defined(invoker.export_header_blink))
# Not all platforms use the Blink variant, so make sure GN doesn't complain
@@ -506,12 +515,22 @@ template("mojom") {
!invoker.disallow_interfaces
all_deps = []
+ mojom_cpp_deps = []
if (defined(invoker.deps)) {
all_deps += invoker.deps
+ mojom_cpp_deps += invoker.deps
}
if (defined(invoker.public_deps)) {
all_deps += invoker.public_deps
+ mojom_cpp_deps += invoker.public_deps
+ }
+ if (defined(invoker.mojom_source_deps)) {
+ all_deps += invoker.mojom_source_deps
}
+ if (defined(invoker.mojom_blink_source_deps)) {
+ all_deps += invoker.mojom_blink_source_deps
+ }
+ not_needed([ "mojom_deps" ])
if (defined(invoker.component_macro_prefix)) {
assert(defined(invoker.component_output_prefix))
@@ -536,12 +555,6 @@ template("mojom") {
sources_list = invoker.sources
}
- # Reset sources_assignment_filter for the BUILD.gn file to prevent
- # regression during the migration of Chromium away from the feature.
- # See docs/no_sources_assignment_filter.md for more information.
- # TODO(crbug.com/1018739): remove this when migration is done.
- set_sources_assignment_filter([])
-
# Listed sources may be relative to the current target dir, or they may be
# absolute paths, including paths to generated mojom files. While those are
# fine as-is for input references, deriving output paths can be more subtle.
@@ -571,7 +584,11 @@ template("mojom") {
# for the naming of any generated output files derived from their
# corresponding input mojoms. These paths are always considered to be relative
# to root_gen_dir.
- source_abspaths = rebase_path(sources_list, "//")
+ if (defined(invoker.input_root_override)) {
+ source_abspaths = rebase_path(sources_list, invoker.input_root_override)
+ } else {
+ source_abspaths = rebase_path(sources_list, "//")
+ }
output_file_base_paths = []
foreach(path, source_abspaths) {
output_file_base_paths +=
@@ -643,21 +660,31 @@ template("mojom") {
}
if (is_android) {
enabled_features += [ "is_android" ]
- } else if (is_chromeos) {
- enabled_features += [ "is_chromeos" ]
+ } else if (is_chromeos_ash) {
+ enabled_features += [
+ "is_chromeos",
+ "is_chromeos_ash",
+ ]
} else if (is_fuchsia) {
enabled_features += [ "is_fuchsia" ]
} else if (is_ios) {
enabled_features += [ "is_ios" ]
- } else if (is_linux) {
+ } else if (is_linux || is_chromeos_lacros) {
enabled_features += [ "is_linux" ]
+ if (is_chromeos_lacros) {
+ enabled_features += [
+ "is_chromeos",
+ "is_chromeos_lacros",
+ ]
+ }
} else if (is_mac) {
enabled_features += [ "is_mac" ]
} else if (is_win) {
enabled_features += [ "is_win" ]
}
- action(parser_target_name) {
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(parser_target_name) {
script = mojom_parser_script
inputs = mojom_parser_sources + [ build_metadata_filename ]
sources = sources_list
@@ -679,7 +706,7 @@ template("mojom") {
# Resolve relative input mojom paths against both the root src dir and
# the root gen dir.
"--input-root",
- rebase_path("//"),
+ rebase_path("//."),
"--input-root",
rebase_path(root_gen_dir),
@@ -692,12 +719,26 @@ template("mojom") {
rebase_path(build_metadata_filename),
]
+ if (defined(invoker.input_root_override)) {
+ args += [
+ "--input-root",
+ rebase_path(invoker.input_root_override),
+ ]
+ }
+
foreach(enabled_feature, enabled_features) {
args += [
"--enable-feature",
enabled_feature,
]
}
+
+ if (defined(invoker.webui_module_path)) {
+ args += [
+ "--add-module-metadata",
+ "webui_module_path=${invoker.webui_module_path}",
+ ]
+ }
}
}
@@ -705,18 +746,29 @@ template("mojom") {
# Generate code that is shared by different variants.
if (sources_list != []) {
+ base_dir = "//"
+ if (defined(invoker.input_root_override)) {
+ base_dir = invoker.input_root_override
+ }
+
common_generator_args = [
"--use_bundled_pylibs",
"-o",
rebase_path(root_gen_dir, root_build_dir),
"generate",
"-d",
- rebase_path("//", root_build_dir),
+ rebase_path(base_dir, root_build_dir),
"-I",
rebase_path("//", root_build_dir),
"--bytecode_path",
rebase_path("$root_gen_dir/mojo/public/tools/bindings", root_build_dir),
]
+ if (defined(invoker.input_root_override)) {
+ common_generator_args += [
+ "-I",
+ rebase_path(invoker.input_root_override, root_build_dir),
+ ]
+ }
if (defined(invoker.disallow_native_types) &&
invoker.disallow_native_types) {
@@ -767,7 +819,8 @@ template("mojom") {
}
}
- action(generator_cpp_message_ids_target_name) {
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_cpp_message_ids_target_name) {
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
sources = sources_list
@@ -806,7 +859,9 @@ template("mojom") {
}
generator_shared_target_name = "${target_name}_shared__generator"
- action(generator_shared_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_shared_target_name) {
visibility = [ ":*" ]
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
@@ -864,7 +919,7 @@ template("mojom") {
}
shared_cpp_sources_target_name = "${target_name}_shared_cpp_sources"
- jumbo_source_set(shared_cpp_sources_target_name) {
+ source_set(shared_cpp_sources_target_name) {
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
@@ -925,7 +980,9 @@ template("mojom") {
generator_mojolpm_proto_target_name =
"${target_name}_mojolpm_proto_generator"
- action(generator_mojolpm_proto_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_mojolpm_proto_target_name) {
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
sources = invoker.sources
@@ -960,11 +1017,10 @@ template("mojom") {
sources = process_file_template(
invoker.sources,
[ "{{source_gen_dir}}/{{source_file_part}}.mojolpm.proto" ])
- import_dirs = [ "${root_gen_dir}" ]
+ import_dirs = [ "//" ]
proto_in_dir = "${root_gen_dir}"
proto_out_dir = "."
- proto_deps = [ "//mojo/public/tools/fuzzers:mojolpm_proto_copy" ]
- proto_deps += [ ":$generator_mojolpm_proto_target_name" ]
+ proto_deps = [ ":$generator_mojolpm_proto_target_name" ]
link_deps = [ "//mojo/public/tools/fuzzers:mojolpm_proto" ]
foreach(d, all_deps) {
@@ -995,12 +1051,22 @@ template("mojom") {
}
# Generate code for variants.
- if (!defined(invoker.disable_variants) || !invoker.disable_variants) {
- enabled_configurations = _bindings_configurations
+ default_variant = {
+ component_macro_suffix = ""
+ }
+ if ((!defined(invoker.disable_variants) || !invoker.disable_variants) &&
+ !is_ios) {
+ blink_variant = {
+ variant = "blink"
+ component_macro_suffix = "_BLINK"
+ for_blink = true
+ }
+ enabled_configurations = [
+ default_variant,
+ blink_variant,
+ ]
} else {
- first_config = _bindings_configurations[0]
- assert(!defined(first_config.variant))
- enabled_configurations = [ first_config ]
+ enabled_configurations = [ default_variant ]
}
foreach(bindings_configuration, enabled_configurations) {
cpp_only = false
@@ -1018,6 +1084,11 @@ template("mojom") {
export_defines = []
export_defines_overridden = false
force_source_set = false
+ proxy_target = ""
+ extra_configs = []
+ output_visibility = []
+ output_visibility = [ "*" ]
+ cpp_source_deps = []
if (defined(bindings_configuration.for_blink) &&
bindings_configuration.for_blink) {
if (defined(invoker.blink_cpp_typemaps)) {
@@ -1028,18 +1099,47 @@ template("mojom") {
export_defines = [ invoker.export_define_blink ]
force_source_set = true
}
+ if (defined(invoker.blink_cpp_configs)) {
+ extra_configs += invoker.blink_cpp_configs
+ }
+ if (defined(invoker.blink_cpp_proxy_target)) {
+ proxy_target = invoker.blink_cpp_proxy_target
+ }
+ if (defined(invoker.visibility_blink)) {
+ output_visibility = []
+ output_visibility = invoker.visibility_blink
+ }
+ if (defined(invoker.mojom_blink_source_deps)) {
+ cpp_source_deps = invoker.mojom_blink_source_deps
+ }
} else {
if (defined(invoker.cpp_typemaps)) {
cpp_typemap_configs = invoker.cpp_typemaps
}
-
if (defined(invoker.export_define)) {
export_defines_overridden = true
export_defines = [ invoker.export_define ]
force_source_set = true
}
+ if (defined(invoker.cpp_configs)) {
+ extra_configs += invoker.cpp_configs
+ }
+ if (defined(invoker.cpp_proxy_target)) {
+ proxy_target = invoker.cpp_proxy_target
+ }
+ if (defined(invoker.visibility)) {
+ output_visibility = []
+ output_visibility = invoker.visibility
+ }
+ if (defined(invoker.mojom_source_deps)) {
+ cpp_source_deps = invoker.mojom_source_deps
+ }
}
not_needed([ "cpp_typemap_configs" ])
+ if (proxy_target != "") {
+ group("${target_name}${variant_suffix}__has_cpp_proxy") {
+ }
+ }
if (!export_defines_overridden && defined(invoker.component_macro_prefix)) {
output_name_override =
@@ -1089,7 +1189,6 @@ template("mojom") {
type_mappings_target_name = "${target_name}${variant_suffix}__type_mappings"
type_mappings_path =
"$target_gen_dir/${target_name}${variant_suffix}__type_mappings"
- active_typemaps = []
if (sources_list != []) {
generator_cpp_output_suffixes = []
variant_dash_suffix = ""
@@ -1104,20 +1203,11 @@ template("mojom") {
"${variant_dash_suffix}.cc",
"${variant_dash_suffix}.h",
]
- foreach(source, sources_list) {
- # 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) {
- active_typemaps += [ typemap ]
- }
- }
- }
generator_target_name = "${target_name}${variant_suffix}__generator"
- action(generator_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_target_name) {
visibility = [ ":*" ]
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
@@ -1249,6 +1339,7 @@ template("mojom") {
# mojolpm only uses the no-variant type.
":$mojolpm_generator_target_name",
":$mojolpm_proto_target_name",
+ "//base",
"//mojo/public/tools/fuzzers:mojolpm",
]
@@ -1260,18 +1351,6 @@ template("mojom") {
public_deps += [ "${full_name}_mojolpm" ]
}
- foreach(typemap, active_typemaps) {
- _typemap_config = {
- }
- _typemap_config = typemap.config
-
- if (defined(_typemap_config.deps)) {
- deps += _typemap_config.deps
- }
- if (defined(_typemap_config.public_deps)) {
- public_deps += _typemap_config.public_deps
- }
- }
foreach(config, cpp_typemap_configs) {
if (defined(config.traits_deps)) {
deps += config.traits_deps
@@ -1309,7 +1388,9 @@ template("mojom") {
}
write_file(_typemap_config_filename, _rebased_typemap_configs, "json")
_mojom_target_name = target_name
- action(_typemap_validator_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(_typemap_validator_target_name) {
script = "$mojom_generator_root/validate_typemap_config.py"
inputs = [ _typemap_config_filename ]
outputs = [ _typemap_stamp_filename ]
@@ -1320,9 +1401,10 @@ template("mojom") {
]
}
- action(type_mappings_target_name) {
- inputs = _bindings_configuration_files + mojom_generator_sources +
- jinja2_sources + [ _typemap_stamp_filename ]
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(type_mappings_target_name) {
+ inputs =
+ mojom_generator_sources + jinja2_sources + [ _typemap_stamp_filename ]
outputs = [ type_mappings_path ]
script = "$mojom_generator_root/generate_type_mappings.py"
deps = [ ":$_typemap_validator_target_name" ]
@@ -1349,46 +1431,12 @@ template("mojom") {
]
}
- if (sources_list != []) {
- # 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.
- if (defined(typemap.filename)) {
- inputs += [ typemap.filename ]
- }
- }
- args += typemap_description
-
- # Newer GN-based typemaps are aggregated into a single config.
- inputs += [ _typemap_config_filename ]
- args += [
- "--cpp-typemap-config",
- rebase_path(_typemap_config_filename, root_build_dir),
- ]
- }
+ # Newer GN-based typemaps are aggregated into a single config.
+ inputs += [ _typemap_config_filename ]
+ args += [
+ "--cpp-typemap-config",
+ rebase_path(_typemap_config_filename, root_build_dir),
+ ]
}
group("${target_name}${variant_suffix}_headers") {
@@ -1404,32 +1452,45 @@ template("mojom") {
full_name = get_label_info("$d", "label_no_toolchain")
public_deps += [ "${full_name}${variant_suffix}_headers" ]
}
+ if (defined(bindings_configuration.for_blink) &&
+ bindings_configuration.for_blink) {
+ public_deps += [ "//mojo/public/cpp/bindings:wtf_support" ]
+ }
}
+ js_data_deps_target_name = target_name + "_js_data_deps"
+ not_needed([ "js_data_deps_target_name" ])
+
if (!force_source_set && defined(invoker.component_macro_prefix)) {
- output_target_type = "component"
+ sources_target_type = "component"
} else {
- output_target_type = "source_set"
+ sources_target_type = "source_set"
}
- js_data_deps_target_name = target_name + "_js_data_deps"
- not_needed([ "js_data_deps_target_name" ])
+ output_target_name = "${target_name}${variant_suffix}"
+ if (proxy_target != "") {
+ group(output_target_name) {
+ public_deps = [ proxy_target ]
+ visibility = output_visibility
+ if (defined(invoker.testonly)) {
+ testonly = invoker.testonly
+ }
+ }
+ sources_target_name = "${output_target_name}_cpp_sources"
+ } else {
+ sources_target_name = output_target_name
+ }
- target("jumbo_" + output_target_type, "${target_name}${variant_suffix}") {
+ target(sources_target_type, sources_target_name) {
if (defined(output_name_override)) {
output_name = output_name_override
}
- 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
- }
+ visibility = output_visibility + [ ":$output_target_name" ]
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
defines = export_defines
+ configs += extra_configs
if (output_file_base_paths != []) {
sources = []
foreach(base_path, output_file_base_paths) {
@@ -1456,13 +1517,20 @@ template("mojom") {
if (sources_list != []) {
public_deps += [ ":$generator_target_name" ]
}
- foreach(d, all_deps) {
+ foreach(d, mojom_cpp_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")
+ full_name = get_label_info(d, "label_no_toolchain")
public_deps += [ "${full_name}${variant_suffix}" ]
}
+ foreach(d, cpp_source_deps) {
+ full_name = get_label_info(d, "label_no_toolchain")
+ public_deps += [
+ "${full_name}${variant_suffix}__has_cpp_proxy",
+ "${full_name}${variant_suffix}_cpp_sources",
+ ]
+ }
if (defined(bindings_configuration.for_blink) &&
bindings_configuration.for_blink) {
if (defined(invoker.overridden_deps_blink)) {
@@ -1493,20 +1561,6 @@ template("mojom") {
public_deps += invoker.component_deps
}
}
- foreach(typemap, active_typemaps) {
- _typemap_config = {
- }
- _typemap_config = typemap.config
- 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
- }
- }
foreach(config, cpp_typemap_configs) {
if (defined(config.traits_sources)) {
sources += config.traits_sources
@@ -1518,18 +1572,10 @@ template("mojom") {
public_deps += config.traits_public_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 (generate_fuzzing) {
- # Generate JS bindings by default if IPC fuzzer is enabled.
- public_deps += [ ":$js_data_deps_target_name" ]
- }
}
if (generate_java && is_android) {
@@ -1537,7 +1583,8 @@ template("mojom") {
java_generator_target_name = target_name + "_java__generator"
if (sources_list != []) {
- action(java_generator_target_name) {
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(java_generator_target_name) {
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
sources = sources_list
@@ -1576,7 +1623,9 @@ template("mojom") {
}
java_srcjar_target_name = target_name + "_java_sources"
- action(java_srcjar_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(java_srcjar_target_name) {
script = "//build/android/gyp/zip.py"
inputs = []
if (output_file_base_paths != []) {
@@ -1605,6 +1654,7 @@ template("mojom") {
"//base:base_java",
"//mojo/public/java:bindings_java",
"//mojo/public/java:system_java",
+ "//third_party/androidx:androidx_annotation_annotation_java",
]
# Disable warnings/checks on these generated files.
@@ -1635,7 +1685,9 @@ template("mojom") {
!use_typescript_for_target) {
if (sources_list != []) {
generator_js_target_name = "${target_name}_js__generator"
- action(generator_js_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_js_target_name) {
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
sources = sources_list
@@ -1656,10 +1708,15 @@ template("mojom") {
outputs += [
"$root_gen_dir/$base_path.js",
"$root_gen_dir/$base_path.externs.js",
+ "$root_gen_dir/$base_path.m.js",
"$root_gen_dir/$base_path-lite.js",
"$root_gen_dir/$base_path.html",
"$root_gen_dir/$base_path-lite-for-compile.js",
]
+
+ if (defined(invoker.webui_module_path)) {
+ outputs += [ "$root_gen_dir/mojom-webui/$base_path-webui.js" ]
+ }
}
response_file_contents = filelist
@@ -1708,13 +1765,19 @@ template("mojom") {
foreach(base_path, output_file_base_paths) {
data += [
"$root_gen_dir/${base_path}.js",
+ "$root_gen_dir/${base_path}.m.js",
"$root_gen_dir/${base_path}-lite.js",
]
}
deps += [ ":$generator_js_target_name" ]
}
- data_deps = []
+ if (defined(invoker.disallow_native_types) &&
+ invoker.disallow_native_types) {
+ data_deps = []
+ } else {
+ data_deps = [ "//mojo/public/js:bindings_module" ]
+ }
foreach(d, all_deps) {
full_name = get_label_info(d, "label_no_toolchain")
data_deps += [ "${full_name}_js_data_deps" ]
@@ -1770,6 +1833,64 @@ template("mojom") {
group(js_library_for_compile_target_name) {
}
}
+
+ js_modules_target_name = "${target_name}_js_modules"
+ if (sources_list != []) {
+ js_library(js_modules_target_name) {
+ extra_public_deps = [ ":$generator_js_target_name" ]
+ sources = []
+ foreach(base_path, output_file_base_paths) {
+ sources += [ "$root_gen_dir/${base_path}.m.js" ]
+ }
+ externs_list = [
+ "${externs_path}/mojo_core.js",
+ "${externs_path}/pending.js",
+ ]
+ if (defined(invoker.disallow_native_types) &&
+ invoker.disallow_native_types) {
+ deps = []
+ } else {
+ deps = [ "//mojo/public/js:bindings_uncompiled" ]
+ }
+ foreach(d, all_deps) {
+ full_name = get_label_info(d, "label_no_toolchain")
+ deps += [ "${full_name}_js_modules" ]
+ }
+ }
+ } else {
+ group(js_modules_target_name) {
+ }
+ }
+
+ if (defined(invoker.webui_module_path)) {
+ webui_js_target_name = "${target_name}_webui_js"
+ if (sources_list != []) {
+ js_library(webui_js_target_name) {
+ extra_public_deps = [ ":$generator_js_target_name" ]
+ sources = []
+ foreach(base_path, output_file_base_paths) {
+ sources += [ "$root_gen_dir/mojom-webui/${base_path}-webui.js" ]
+ }
+ externs_list = [
+ "${externs_path}/mojo_core.js",
+ "${externs_path}/pending.js",
+ ]
+ if (defined(invoker.disallow_native_types) &&
+ invoker.disallow_native_types) {
+ deps = []
+ } else {
+ deps = [ "//mojo/public/js:bindings_uncompiled" ]
+ }
+ foreach(d, all_deps) {
+ full_name = get_label_info(d, "label_no_toolchain")
+ deps += [ "${full_name}_webui_js" ]
+ }
+ }
+ } else {
+ group(webui_js_target_name) {
+ }
+ }
+ }
}
if ((generate_fuzzing || !defined(invoker.cpp_only) || !invoker.cpp_only) &&
use_typescript_for_target) {
@@ -1806,7 +1927,9 @@ template("mojom") {
# Generate Typescript bindings.
generator_ts_target_name =
"${target_name}_${dependency_type.name}__ts__generator"
- action(generator_ts_target_name) {
+
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_ts_target_name) {
script = mojom_generator_script
inputs = mojom_generator_sources + jinja2_sources
sources = sources_list
@@ -1873,7 +1996,8 @@ template("mojom") {
"${target_name}_${dependency_type.name}__js__generator"
generator_js_target_names += [ generator_js_target_name ]
- action(generator_js_target_name) {
+ # TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
+ python2_action(generator_js_target_name) {
script = "$mojom_generator_root/compile_typescript.py"
sources = ts_outputs
outputs = js_outputs