Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Unified Diff: mojo/public/tools/bindings/mojom.gni

Issue 2237913004: Mojo C++ bindings: support generating code shared by different variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/mojom.gni
diff --git a/mojo/public/tools/bindings/mojom.gni b/mojo/public/tools/bindings/mojom.gni
index 4705a5f46692d64d08ad336a2e2cd87931b72cb1..1fe901b4cae62d9ce461489fc4ac00545cbc6d02 100644
--- a/mojo/public/tools/bindings/mojom.gni
+++ b/mojo/public/tools/bindings/mojom.gni
@@ -136,6 +136,77 @@ template("mojom") {
}
}
+ # 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),
+ "--bytecode_path",
+ rebase_path("$root_gen_dir/mojo/public/tools/bindings"),
+ ]
+
+ if (defined(invoker.import_dirs)) {
+ foreach(import_dir, invoker.import_dirs) {
+ common_generator_args += [
+ "-I",
+ rebase_path(import_dir, root_build_dir),
+ ]
+ }
+ }
+
+ 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++",
+ ]
+ }
+ }
+
+ shared_cpp_sources_suffix = "shared_cpp_sources"
+ shared_cpp_sources_target_name = "${target_name}_${shared_cpp_sources_suffix}"
+ 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 = []
+ 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_cpp_sources_suffix}" ]
+ }
+ }
+
+ # Generate code for variants.
foreach(bindings_configuration, _bindings_configurations) {
cpp_only = false
variant_suffix = ""
@@ -207,28 +278,7 @@ template("mojom") {
]
outputs = generator_cpp_outputs + generator_java_outputs +
generator_js_outputs
- args = [
- "--use_bundled_pylibs",
- "generate",
- "{{source}}",
- "-d",
- rebase_path("//", root_build_dir),
- "-I",
- rebase_path("//", root_build_dir),
- "-o",
- rebase_path(root_gen_dir),
- "--bytecode_path",
- rebase_path("$root_gen_dir/mojo/public/tools/bindings"),
- ]
-
- if (defined(invoker.import_dirs)) {
- foreach(import_dir, invoker.import_dirs) {
- args += [
- "-I",
- rebase_path(import_dir, root_build_dir),
- ]
- }
- }
+ args = common_generator_args
if (cpp_only) {
args += [
@@ -386,6 +436,7 @@ template("mojom") {
sources = process_file_template(enabled_sources, generator_cpp_outputs)
}
deps = [
+ ":$shared_cpp_sources_target_name",
"//mojo/public/cpp/bindings:struct_traits",
"//mojo/public/interfaces/bindings:bindings__generator",
]
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_cpp_generator.py ('k') | mojo/public/tools/bindings/mojom_bindings_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698