Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Pigweed Authors |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | # use this file except in compliance with the License. You may obtain a copy of |
| 5 | # the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations under |
| 13 | # the License. |
| 14 | |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 15 | import("$dir_pw_build/input_group.gni") |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 16 | import("$dir_pw_build/python_script.gni") |
| 17 | |
| 18 | # Python script that invokes protoc. |
| 19 | _gen_script_path = |
| 20 | "$dir_pw_protobuf_compiler/py/pw_protobuf_compiler/generate_protos.py" |
| 21 | |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 22 | _forwarded_vars = [ |
| 23 | "testonly", |
| 24 | "visibility", |
| 25 | ] |
| 26 | |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 27 | # Generates pw_protobuf C++ code for proto files, creating a source_set of the |
| 28 | # generated files. This is internal and should not be used outside of this file. |
| 29 | # Use pw_proto_library instead. |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 30 | # |
| 31 | # Args: |
| 32 | # protos: List of input .proto files. |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 33 | template("_pw_pwpb_proto_library") { |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 34 | _proto_gen_dir = "$root_gen_dir/protos" |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 35 | _module_path = get_path_info(".", "abspath") |
| 36 | _relative_proto_paths = rebase_path(invoker.protos, _module_path) |
| 37 | |
| 38 | _outputs = [] |
| 39 | foreach(_proto, _relative_proto_paths) { |
| 40 | _output = string_replace(_proto, ".proto", ".pwpb.h") |
| 41 | _outputs += [ "$_proto_gen_dir/$_output" ] |
| 42 | } |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 43 | |
| 44 | _gen_target = "${target_name}_gen" |
| 45 | pw_python_script(_gen_target) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 46 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 47 | script = _gen_script_path |
| 48 | args = [ |
| 49 | "--language", |
| 50 | "cc", |
| 51 | "--module-path", |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 52 | _module_path, |
| 53 | "--include-file", |
| 54 | invoker.include_file, |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 55 | "--out-dir", |
| 56 | _proto_gen_dir, |
| 57 | ] + get_path_info(invoker.protos, "abspath") |
| 58 | inputs = invoker.protos |
| 59 | outputs = _outputs |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 60 | deps = invoker.deps |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 61 | if (defined(invoker.protoc_deps)) { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 62 | deps += invoker.protoc_deps |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 63 | } |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | # For C++ proto files, the generated proto directory is added as an include |
| 67 | # path for the code. This requires using "all_dependent_configs" to force the |
| 68 | # include on any code that transitively depends on the generated protos. |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 69 | _include_config_target = "${target_name}_includes" |
| 70 | config(_include_config_target) { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 71 | include_dirs = [ "$_proto_gen_dir" ] |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | # Create a library with the generated source files. |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 75 | source_set(target_name) { |
| 76 | all_dependent_configs = [ ":$_include_config_target" ] |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 77 | deps = [ ":$_gen_target" ] |
| 78 | public_deps = [ dir_pw_protobuf ] + invoker.gen_deps |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 79 | sources = get_target_outputs(":$_gen_target") |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 80 | public = filter_include(sources, [ "*.pwpb.h" ]) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | # Generates nanopb code for proto files, creating a source_set of the generated |
| 85 | # files. This is internal and should not be used outside of this file. Use |
| 86 | # pw_proto_library instead. |
| 87 | # |
| 88 | # Args: |
| 89 | # protos: List of input .proto files. |
| 90 | template("_pw_nanopb_proto_library") { |
| 91 | assert(defined(dir_third_party_nanopb) && dir_third_party_nanopb != "", |
| 92 | "\$dir_third_party_nanopb must be set to compile nanopb protobufs") |
| 93 | |
| 94 | _proto_gen_dir = "$root_gen_dir/protos" |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 95 | _module_path = get_path_info(".", "abspath") |
| 96 | _relative_proto_paths = rebase_path(invoker.protos, _module_path) |
| 97 | |
| 98 | _outputs = [] |
| 99 | foreach(_proto, _relative_proto_paths) { |
| 100 | _output_h = string_replace(_proto, ".proto", ".pb.h") |
| 101 | _output_c = string_replace(_proto, ".proto", ".pb.c") |
| 102 | _outputs += [ |
| 103 | "$_proto_gen_dir/$_output_h", |
| 104 | "$_proto_gen_dir/$_output_c", |
| 105 | ] |
| 106 | } |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 107 | |
| 108 | _nanopb_plugin = "$dir_third_party_nanopb/generator/protoc-gen-nanopb" |
| 109 | if (host_os == "win") { |
| 110 | _nanopb_plugin += ".bat" |
| 111 | } |
| 112 | |
| 113 | # Create a target which runs protoc configured with the nanopb plugin to |
| 114 | # generate the C proto sources. |
| 115 | _gen_target = "${target_name}_gen" |
| 116 | pw_python_script(_gen_target) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 117 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 118 | script = _gen_script_path |
| 119 | args = [ |
| 120 | "--language", |
| 121 | "nanopb", |
| 122 | "--module-path", |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 123 | _module_path, |
Alexei Frolov | ac5b674 | 2020-05-01 13:28:14 -0700 | [diff] [blame] | 124 | "--include-paths", |
| 125 | "$dir_third_party_nanopb/generator/proto", |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 126 | "--include-file", |
| 127 | invoker.include_file, |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 128 | "--out-dir", |
| 129 | _proto_gen_dir, |
| 130 | "--custom-plugin", |
| 131 | get_path_info(_nanopb_plugin, "abspath"), |
| 132 | ] + get_path_info(invoker.protos, "abspath") |
| 133 | inputs = invoker.protos |
| 134 | outputs = _outputs |
| 135 | |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 136 | deps = invoker.deps |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 137 | if (defined(invoker.protoc_deps)) { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 138 | deps += invoker.protoc_deps |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | # For C++ proto files, the generated proto directory is added as an include |
| 143 | # path for the code. This requires using "all_dependent_configs" to force the |
| 144 | # include on any code that transitively depends on the generated protos. |
| 145 | _include_root = rebase_path(get_path_info(".", "abspath"), "//") |
| 146 | _include_config_target = "${target_name}_includes" |
| 147 | config(_include_config_target) { |
| 148 | include_dirs = [ |
| 149 | "$_proto_gen_dir", |
| 150 | "$_proto_gen_dir/$_include_root", |
| 151 | ] |
| 152 | } |
| 153 | |
| 154 | # Create a library with the generated source files. |
| 155 | source_set(target_name) { |
| 156 | all_dependent_configs = [ ":$_include_config_target" ] |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 157 | deps = [ ":$_gen_target" ] |
| 158 | public_deps = [ dir_third_party_nanopb ] + invoker.gen_deps |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 159 | sources = get_target_outputs(":$_gen_target") |
| 160 | public = filter_include(sources, [ "*.pb.h" ]) |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 164 | # Generates Go code for proto files, listing the proto output directory in the |
| 165 | # metadata variable GOPATH. Internal use only. |
| 166 | # |
| 167 | # Args: |
| 168 | # protos: List of input .proto files. |
| 169 | template("_pw_go_proto_library") { |
| 170 | _proto_gopath = "$root_gen_dir/go" |
| 171 | _proto_gen_dir = "$_proto_gopath/src" |
| 172 | _rebased_gopath = rebase_path(_proto_gopath) |
| 173 | |
| 174 | pw_python_script(target_name) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 175 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 176 | metadata = { |
| 177 | gopath = [ "GOPATH+=$_rebased_gopath" ] |
Alexei Frolov | c15a988 | 2019-12-23 14:29:02 -0800 | [diff] [blame] | 178 | external_deps = [ |
| 179 | "github.com/golang/protobuf/proto", |
| 180 | "google.golang.org/grpc", |
| 181 | ] |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 182 | } |
| 183 | script = _gen_script_path |
| 184 | args = [ |
| 185 | "--language", |
| 186 | "go", |
| 187 | "--module-path", |
| 188 | "//", |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 189 | "--include-file", |
| 190 | invoker.include_file, |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 191 | "--out-dir", |
| 192 | _proto_gen_dir, |
| 193 | ] + get_path_info(invoker.protos, "abspath") |
| 194 | inputs = invoker.protos |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 195 | deps = invoker.deps + invoker.gen_deps |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 196 | stamp = true |
| 197 | } |
| 198 | } |
| 199 | |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 200 | # Generates protobuf code from .proto definitions for various languages. |
| 201 | # |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 202 | # The generators to use are defined in the pw_protobuf_generators build |
| 203 | # variable. Each listed generator creates a generated code target called |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 204 | # |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 205 | # <target_name>_<generator> |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 206 | # |
| 207 | # For example, with the following definitions: |
| 208 | # |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 209 | # pw_protobuf_generators = [ "pwpb", "py" ] |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 210 | # |
| 211 | # pw_proto_library("my_protos") { |
| 212 | # sources = [ "foo.proto" ] |
| 213 | # } |
| 214 | # |
| 215 | # Two build targets will be created for the declared "my_protos" target. |
| 216 | # |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 217 | # "my_protos_pwpb" <-- C++ source_set containing generated proto code |
| 218 | # "my_protos_py" <-- Python module containing generated proto code |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 219 | # |
| 220 | # Args: |
| 221 | # sources: List of input .proto files. |
| 222 | # deps: List of other pw_proto_library dependencies. |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 223 | # inputs: Other files on which the protos depend (e.g. nanopb .options files). |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 224 | template("pw_proto_library") { |
| 225 | assert(defined(invoker.sources) && invoker.sources != [], |
Wyatt Hepler | b4b73a6 | 2020-05-27 15:17:27 -0700 | [diff] [blame] | 226 | "pw_proto_library requires .proto source files") |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 227 | |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 228 | # For each proto target, create a file which collects the base directories of |
| 229 | # all of its dependencies to list as include paths to protoc. |
| 230 | _include_metadata_target = "${target_name}_include_paths" |
| 231 | _include_metadata_file = "${target_gen_dir}/${target_name}_includes.txt" |
| 232 | generated_file(_include_metadata_target) { |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 233 | if (defined(invoker.deps)) { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 234 | # Collect metadata from the include path files of each dependency. |
| 235 | deps = process_file_template(invoker.deps, "{{source}}_include_paths") |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 236 | } else { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 237 | deps = [] |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 238 | } |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 239 | data_keys = [ "protoc_includes" ] |
| 240 | outputs = [ _include_metadata_file ] |
| 241 | |
| 242 | # Indicate this library's base directory for its dependents. |
| 243 | metadata = { |
| 244 | protoc_includes = [ rebase_path(".", root_out_dir) ] |
| 245 | } |
| 246 | } |
| 247 | |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 248 | _deps = [ ":$_include_metadata_target" ] |
| 249 | |
| 250 | if (defined(invoker.inputs)) { |
| 251 | # Toss any additional inputs into an input group dependency. |
| 252 | _input_target_name = "${target_name}_inputs" |
| 253 | pw_input_group(_input_target_name) { |
| 254 | inputs = invoker.inputs |
| 255 | } |
| 256 | _deps += [ ":$_input_target_name" ] |
| 257 | } |
| 258 | |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 259 | foreach(_gen, pw_protobuf_generators) { |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 260 | _lang_target = "${target_name}_${_gen}" |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 261 | |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 262 | if (_gen == "pwpb") { |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 263 | _gen_deps = [] |
| 264 | if (defined(invoker.deps)) { |
| 265 | _gen_deps = process_file_template(invoker.deps, "{{source}}_${_gen}") |
| 266 | } |
| 267 | |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 268 | _pw_pwpb_proto_library(_lang_target) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 269 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 270 | protos = invoker.sources |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 271 | deps = _deps |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 272 | include_file = _include_metadata_file |
| 273 | gen_deps = _gen_deps |
Alexei Frolov | bbf164c | 2019-12-16 12:51:59 -0800 | [diff] [blame] | 274 | |
| 275 | # List the pw_protobuf plugin's files as a dependency to recompile |
| 276 | # generated code if they are modified. |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 277 | protoc_deps = [ "$dir_pw_protobuf:codegen_protoc_plugin" ] |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 278 | } |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 279 | } else if (_gen == "nanopb") { |
| 280 | _pw_nanopb_proto_library(_lang_target) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 281 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 282 | protos = invoker.sources |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 283 | deps = _deps |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 284 | include_file = _include_metadata_file |
| 285 | gen_deps = _gen_deps |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 286 | } |
| 287 | } else if (_gen == "go") { |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 288 | _pw_go_proto_library(_lang_target) { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 289 | forward_variables_from(invoker, _forwarded_vars) |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 290 | protos = invoker.sources |
Alexei Frolov | 05d8ef2 | 2020-06-08 10:32:29 -0700 | [diff] [blame^] | 291 | deps = _deps |
Alexei Frolov | e19ebb8 | 2020-05-14 17:21:20 -0700 | [diff] [blame] | 292 | include_file = _include_metadata_file |
| 293 | gen_deps = _gen_deps |
Alexei Frolov | def1471 | 2019-12-23 13:03:32 -0800 | [diff] [blame] | 294 | } |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 295 | } else { |
| 296 | assert(false, |
| 297 | string_join( |
| 298 | " ", |
| 299 | [ |
Wyatt Hepler | b4b73a6 | 2020-05-27 15:17:27 -0700 | [diff] [blame] | 300 | "pw_proto_library doesn't know how to generate code for", |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 301 | "generator '$_gen'. Please add support if you require it.", |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 302 | ])) |
| 303 | } |
| 304 | } |
| 305 | |
Wyatt Hepler | b4b73a6 | 2020-05-27 15:17:27 -0700 | [diff] [blame] | 306 | # All supported pw_protobuf generators. |
| 307 | _protobuf_generators = [ |
| 308 | "pwpb", |
| 309 | "nanopb", |
| 310 | "go", |
| 311 | ] |
| 312 | |
| 313 | # Create stub versions of the proto library for other protobuf generators. |
| 314 | foreach(_gen, _protobuf_generators - pw_protobuf_generators) { |
| 315 | pw_python_script("${target_name}_${_gen}") { |
Wyatt Hepler | e0c4fdc | 2020-05-29 17:26:19 -0700 | [diff] [blame] | 316 | forward_variables_from(invoker, _forwarded_vars) |
Wyatt Hepler | b4b73a6 | 2020-05-27 15:17:27 -0700 | [diff] [blame] | 317 | script = string_join("/", |
| 318 | [ |
| 319 | dir_pw_protobuf_compiler, |
| 320 | "py", |
| 321 | "pw_protobuf_compiler", |
| 322 | "generator_not_selected.py", |
| 323 | ]) |
| 324 | args = [ |
| 325 | "--library", |
| 326 | "${target_name}_${_gen}", |
| 327 | "--generator", |
| 328 | _gen, |
| 329 | ] |
| 330 | inputs = invoker.sources |
| 331 | stamp = true |
| 332 | } |
| 333 | } |
| 334 | |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 335 | # If the user attempts to use the target directly instead of one of the |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 336 | # generator targets, run a script which prints a nice error message. |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 337 | pw_python_script(target_name) { |
| 338 | script = string_join("/", |
| 339 | [ |
| 340 | dir_pw_protobuf_compiler, |
| 341 | "py", |
| 342 | "pw_protobuf_compiler", |
| 343 | "proto_target_invalid.py", |
| 344 | ]) |
| 345 | args = [ |
| 346 | "--target", |
| 347 | target_name, |
| 348 | "--dir", |
| 349 | get_path_info(".", "abspath"), |
| 350 | "--root", |
| 351 | "//", |
Alexei Frolov | f39cd8b | 2020-04-13 17:59:20 -0700 | [diff] [blame] | 352 | ] + pw_protobuf_generators |
Alexei Frolov | 942adf0 | 2019-12-11 17:07:28 -0800 | [diff] [blame] | 353 | stamp = true |
| 354 | } |
| 355 | } |