| # Copyright 2021 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # GN template to generate static library for the given mojom files. |
| # How to use: |
| # [platform2/pkg/BUILD.gn] |
| # mojom_connectivity("foo_mojo_bindings") { |
| # mojo_root = "${platform2_root}" |
| # sources = [ |
| # "mojo/foo.mojom", |
| # "mojo/foo_sub.mojom", |
| # ] |
| # } |
| # |
| # Then this generates static library for the mojom files and the header files |
| # under ${root_gen_dir}/include,. E.g. |
| # ${root_gen_dir}/include/pkg/mojo/foo.mojom.h etc., where "mojo" directory |
| # comes from "sources", and "pkg" comes from the target path relative to |
| # |mojo_root|. |
| # |
| # Parameters: |
| # sources |
| # The .mojom file paths. |
| # generator_overrides (optional) |
| # The overrides config files. |
| # All flags which can be interpreted by static_library target: |
| # The values are used as if static_library does. Note that some flags |
| # may be modified in order to reflect the parameters described above |
| # and build mojom generated files. |
| |
| import("//common-mk/pkg_config.gni") |
| |
| # This gn generates header files under ${root_gen_dir}/include. |
| _mojo_output_base = "${root_gen_dir}/include" |
| |
| _mojom_connectivity_generator = |
| "${platform2_root}/diagnostics/bindings/connectivity/generator.py" |
| |
| _mojom_bindings_suffixes = [ |
| "-connectivity-forward.h", |
| "-connectivity.h", |
| "-connectivity.cc", |
| ] |
| |
| _connectivity_root = "//diagnostics/bindings/connectivity" |
| _connectivity_template_root = "$_connectivity_root/templates" |
| _connectivity_template_sources = [ |
| "$_connectivity_template_root/connectivity-forward.h.j2", |
| "$_connectivity_template_root/connectivity.cc.j2", |
| "$_connectivity_template_root/connectivity.h.j2", |
| "$_connectivity_template_root/enum-generator.cc.j2", |
| "$_connectivity_template_root/enum-generator.h.j2", |
| "$_connectivity_template_root/method-macro.cc.j2", |
| "$_connectivity_template_root/struct-generator.cc.j2", |
| "$_connectivity_template_root/struct-generator.h.j2", |
| "$_connectivity_template_root/test-consumer.cc.j2", |
| "$_connectivity_template_root/test-consumer.h.j2", |
| "$_connectivity_template_root/test-provider.cc.j2", |
| "$_connectivity_template_root/test-provider.h.j2", |
| "$_connectivity_template_root/union-generator.cc.j2", |
| "$_connectivity_template_root/union-generator.h.j2", |
| ] |
| |
| # Generates C++ mojo bindings source code and headers. |
| template("mojom_connectivity_gen") { |
| forward_variables_from(invoker, |
| [ |
| "generator_overrides", |
| "mojo_root", |
| ]) |
| if (!defined(mojo_root)) { |
| mojo_root = "${platform2_root}" |
| } |
| mojo_root = rebase_path(mojo_root) |
| |
| if (!defined(generator_overrides)) { |
| generator_overrides = [] |
| } |
| |
| action(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "sources", |
| ]) |
| inputs = [ _mojom_connectivity_generator ] + |
| _connectivity_template_sources + generator_overrides |
| outputs = [] |
| filelist = [] |
| mojo_output_dir = _mojo_output_base + "/" + rebase_path(".", mojo_root) |
| foreach(source, invoker.sources) { |
| filename = get_path_info("$source", "file") |
| dirname = get_path_info("$source", "gen_dir") |
| relative_dir = rebase_path(dirname, target_gen_dir) |
| foreach(suffix, _mojom_bindings_suffixes) { |
| outputs += [ "${mojo_output_dir}/${relative_dir}/${filename}${suffix}" ] |
| } |
| filelist += [ rebase_path("$source") ] |
| } |
| |
| response_file_contents = filelist |
| |
| script = _mojom_connectivity_generator |
| args = [ |
| "--mojo-root", |
| mojo_root, |
| "--output-dir", |
| _mojo_output_base, |
| "--mojom-file-list={{response_file_name}}", |
| ] |
| foreach(generator_override, generator_overrides) { |
| args += [ |
| "--generator-overrides", |
| rebase_path(generator_override), |
| ] |
| } |
| } |
| } |
| |
| # Generates a static library for the given mojom files. |
| template("mojom_connectivity") { |
| target_gen_name = target_name + "_gen" |
| mojom_connectivity_gen(target_gen_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "generator_overrides", |
| "mojo_root", |
| "sources", |
| ]) |
| } |
| |
| target_pkg_deps_name = target_name + "_pkg_deps" |
| pkg_config(target_pkg_deps_name) { |
| pkg_deps = [ |
| "libchrome", |
| "libmojo", |
| ] |
| } |
| |
| static_library(target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| # Exclude mojo related inputs. |
| "generator_overrides", |
| "mojo_root", |
| "sources", |
| |
| # Exclude fields, which are manually handled. |
| "all_dependent_configs", |
| "configs", |
| "deps", |
| "include_dirs", |
| ]) |
| all_dependent_configs = [ ":${target_pkg_deps_name}" ] |
| if (defined(invoker.all_dependent_configs)) { |
| all_dependent_configs += invoker.all_dependent_configs |
| } |
| |
| include_dirs = [ _mojo_output_base ] |
| if (defined(invoker.include_dirs)) { |
| include_dirs += invoker.include_dirs |
| } |
| |
| if (defined(invoker.configs)) { |
| configs += invoker.configs |
| } |
| deps = [ |
| ":${target_gen_name}", |
| "//diagnostics/bindings/connectivity:libconnectivity", |
| ] |
| deps += invoker.deps |
| |
| sources = get_target_outputs(":${target_gen_name}") |
| } |
| } |