| # Copyright 2021 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| import("//third_party/grpc/grpc_library.gni") |
| import("//third_party/protobuf/proto_library.gni") |
| import("//third_party/cast_core/public/src/build/chromium/proto.gni") |
| |
| # Base template to compile Cast Core proto and gRPC targets. Same parameters |
| # are used as in proto_library.gni, with default values set for import_dirs, |
| # generate_python, extra_configs. The rule also adds built-in protos to deps. |
| template("cast_core_proto_library_base") { |
| _link_deps = [ |
| "//third_party/cast_core/public/src/proto:base_protos", |
| ] |
| |
| _extra_configs = [ |
| "//third_party/cast_core/public/src/proto:force_local_well_known_protos", |
| ] |
| if (defined(invoker.extra_configs)) { |
| _extra_configs += invoker.extra_configs |
| } |
| |
| _import_dirs = [ |
| "//third_party/protobuf/src", |
| ] |
| if (defined(invoker.import_dirs)) { |
| _import_dirs += invoker.import_dirs |
| } |
| |
| target(invoker.target_type, target_name) { |
| forward_variables_from(invoker, |
| [ |
| "sources", |
| "proto_in_dir", |
| "proto_out_dir", |
| "deps", |
| "proto_deps", |
| "generate_javascript", |
| "testonly", |
| ]) |
| link_deps = _link_deps |
| extra_configs = _extra_configs |
| import_dirs = _import_dirs |
| |
| generate_python = false |
| } |
| } |
| |
| # For .proto files without RPC definitions. |
| template("cast_core_proto_library") { |
| cast_core_proto_library_base(target_name) { |
| target_type = "proto_library" |
| forward_variables_from(invoker, "*") |
| } |
| } |
| |
| # For .proto files with RPC definitions. |
| template("cast_core_grpc_library") { |
| if (!defined(invoker.proto_in_dir)) { |
| # By default, protos should be referenced by source root. |
| invoker.proto_in_dir = "//" |
| } |
| |
| cast_core_proto_library_base(target_name) { |
| target_type = "grpc_library" |
| # The variables must be forwarded explicitly to allow introduction of new |
| #ones in this rule (eg 'generate_castcore_grpc'). |
| forward_variables_from(invoker, |
| [ |
| "sources", |
| "deps", |
| "proto_in_dir", |
| "proto_out_dir", |
| "generate_javascript", |
| "link_deps", |
| "proto_deps", |
| "extra_configs", |
| "import_dirs", |
| "testonly", |
| "visibility", |
| ]) |
| } |
| |
| # By default, generate Cast Core gRPC stubs. |
| if (defined(invoker.generate_castcore_stubs) && invoker.generate_castcore_stubs) { |
| cast_core_grpc_stub_library(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "sources", |
| "deps", |
| "import_dirs", |
| "proto_in_dir", |
| "proto_out_dir", |
| "generate_javascript", |
| "testonly", |
| "visibility", |
| ]) |
| } |
| } |
| } |