| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Compile a protocol buffer. | 5 # Compile a protocol buffer. |
| 6 # | 6 # |
| 7 # Protobuf parameters: | 7 # Protobuf parameters: |
| 8 # | 8 # |
| 9 # proto_out_dir (optional) | 9 # proto_out_dir (optional) |
| 10 # Specifies the path suffix that output files are generated under. This | 10 # Specifies the path suffix that output files are generated under. This |
| 11 # path will be appended to the root_gen_dir. | 11 # path will be appended to the root_gen_dir. |
| 12 # | 12 # |
| 13 # Targets that depend on the proto target will be able to include the | 13 # Targets that depend on the proto target will be able to include the |
| 14 # resulting proto headers with an include like: | 14 # resulting proto headers with an include like: |
| 15 # #include "dir/for/my_proto_lib/foo.pb.h" | 15 # #include "dir/for/my_proto_lib/foo.pb.h" |
| 16 # If undefined, this defaults to matching the input directory for each | 16 # If undefined, this defaults to matching the input directory for each |
| 17 # .proto file (you should almost always use the default mode). | 17 # .proto file (you should almost always use the default mode). |
| 18 # | 18 # |
| 19 # generate_python (optional, default true) |
| 20 # Generate Python protobuf stubs. |
| 21 # |
| 22 # generate_cc (optional, default true) |
| 23 # Generate C++ protobuf stubs. |
| 24 # |
| 19 # cc_generator_options (optional) | 25 # cc_generator_options (optional) |
| 20 # List of extra flags passed to the protocol compiler. If you need to | 26 # List of extra flags passed to the protocol compiler. If you need to |
| 21 # add an EXPORT macro to a protobuf's C++ header, set the | 27 # add an EXPORT macro to a protobuf's C++ header, set the |
| 22 # 'cc_generator_options' variable with the value: | 28 # 'cc_generator_options' variable with the value: |
| 23 # 'dllexport_decl=FOO_EXPORT:' (note trailing colon). | 29 # 'dllexport_decl=FOO_EXPORT:' (note trailing colon). |
| 24 # | 30 # |
| 25 # It is likely you also need to #include a file for the above EXPORT | 31 # It is likely you also need to #include a file for the above EXPORT |
| 26 # macro to work (see cc_include) and set | 32 # macro to work (see cc_include) and set |
| 27 # component_build_force_source_set = true. | 33 # component_build_force_source_set = true. |
| 28 # | 34 # |
| 35 # generator_plugin (optional) |
| 36 # Name of plugin executable which generates custom cc stubs. |
| 37 # Plugin itself should be dependency of the invoker. |
| 38 # |
| 39 # generator_plugin_suffix (required if generator_plugin set) |
| 40 # Suffix (before extension) for generated .cc and .h files. |
| 41 # |
| 42 # generator_plugin_options (optional) |
| 43 # Extra flags passed to the plugin. See cc_generator_options. |
| 44 # |
| 29 # cc_include (optional) | 45 # cc_include (optional) |
| 30 # String listing an extra include that should be passed. | 46 # String listing an extra include that should be passed. |
| 31 # Example: cc_include = "foo/bar.h" | 47 # Example: cc_include = "foo/bar.h" |
| 32 # | 48 # |
| 33 # deps (optional) | 49 # deps (optional) |
| 34 # Additional dependencies. | 50 # Additional dependencies. |
| 35 # | 51 # |
| 36 # Parameters for compiling the generated code: | 52 # Parameters for compiling the generated code: |
| 37 # | 53 # |
| 38 # component_build_force_source_set (Default=false) | 54 # component_build_force_source_set (Default=false) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 visibility = [ ":$source_set_name" ] | 88 visibility = [ ":$source_set_name" ] |
| 73 | 89 |
| 74 script = "//tools/protoc_wrapper/protoc_wrapper.py" | 90 script = "//tools/protoc_wrapper/protoc_wrapper.py" |
| 75 | 91 |
| 76 sources = invoker.sources | 92 sources = invoker.sources |
| 77 | 93 |
| 78 # Compute the output directory, both relative to the source root (for | 94 # Compute the output directory, both relative to the source root (for |
| 79 # declaring "outputs") and relative to the build dir (for passing to the | 95 # declaring "outputs") and relative to the build dir (for passing to the |
| 80 # script). | 96 # script). |
| 81 if (defined(invoker.proto_out_dir)) { | 97 if (defined(invoker.proto_out_dir)) { |
| 82 # Put the results in the specified dir in the gen tree. | 98 proto_out_dir = invoker.proto_out_dir |
| 83 out_dir = "$root_gen_dir/" + invoker.proto_out_dir | |
| 84 rel_out_dir = rebase_path(out_dir, root_build_dir) | |
| 85 py_out_dir = "$root_out_dir/pyproto/" + invoker.proto_out_dir | |
| 86 } else { | 99 } else { |
| 87 # Use the gen directory corresponding to the source file for C++ sources. | 100 proto_out_dir = "{{source_root_relative_dir}}" |
| 88 # This expansion will be done differently in the outputs and the args, so | |
| 89 # we don't need to worry about rebasing as above. Always put Python | |
| 90 # sources in "pyproto". | |
| 91 out_dir = "{{source_gen_dir}}" | |
| 92 rel_out_dir = "{{source_gen_dir}}" | |
| 93 py_out_dir = "$root_out_dir/pyproto/{{source_root_relative_dir}}" | |
| 94 } | 101 } |
| 95 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir) | 102 out_dir = "$root_gen_dir/" + proto_out_dir |
| 103 rel_out_dir = rebase_path(out_dir, root_build_dir) |
| 96 | 104 |
| 97 outputs = [ | 105 outputs = [] |
| 98 "$py_out_dir/{{source_name_part}}_pb2.py", | |
| 99 "$out_dir/{{source_name_part}}.pb.cc", | |
| 100 "$out_dir/{{source_name_part}}.pb.h", | |
| 101 ] | |
| 102 | 106 |
| 103 args = [] | 107 args = [] |
| 104 if (defined(invoker.cc_include)) { | 108 if (defined(invoker.cc_include)) { |
| 105 args += [ | 109 args += [ |
| 106 "--include", | 110 "--include", |
| 107 invoker.cc_include, | 111 invoker.cc_include, |
| 112 "--protobuf", |
| 113 "$rel_out_dir/{{source_name_part}}.pb.h", |
| 108 ] | 114 ] |
| 109 } | 115 } |
| 110 | 116 |
| 111 args += [ | 117 args += [ |
| 112 "--protobuf", | |
| 113 "$rel_out_dir/{{source_name_part}}.pb.h", | |
| 114 "--proto-in-dir", | 118 "--proto-in-dir", |
| 115 "{{source_dir}}", | 119 "{{source_dir}}", |
| 116 "--proto-in-file", | 120 "--proto-in-file", |
| 117 "{{source_file_part}}", | 121 "{{source_file_part}}", |
| 118 | 122 |
| 119 # TODO(brettw) support system protobuf compiler. | 123 # TODO(brettw) support system protobuf compiler. |
| 120 "--use-system-protobuf=0", | 124 "--use-system-protobuf=0", |
| 121 ] | 125 ] |
| 122 | 126 |
| 123 protoc_label = "//third_party/protobuf:protoc($host_toolchain)" | 127 protoc_label = "//third_party/protobuf:protoc($host_toolchain)" |
| 124 args += [ | 128 args += [ |
| 125 "--", | 129 "--", |
| 126 | 130 |
| 127 # Prepend with "./" so this will never pick up the system one (normally | 131 # Prepend with "./" so this will never pick up the system one (normally |
| 128 # when not cross-compiling, protoc's output directory will be the same | 132 # when not cross-compiling, protoc's output directory will be the same |
| 129 # as the build dir, so the relative location will be empty). | 133 # as the build dir, so the relative location will be empty). |
| 130 "./" + | 134 "./" + |
| 131 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc", | 135 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc", |
| 132 root_build_dir), | 136 root_build_dir), |
| 133 ] | 137 ] |
| 134 | 138 |
| 135 # If passed cc_generator_options should end in a colon, which will separate | 139 if (!defined(invoker.generate_python) || invoker.generate_python) { |
| 136 # it from the directory when we concatenate them. The proto compiler | 140 py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir |
| 137 # understands this syntax. | 141 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir) |
| 138 if (defined(invoker.cc_generator_options)) { | 142 |
| 139 cc_generator_options = invoker.cc_generator_options | 143 outputs += [ "$py_out_dir/{{source_name_part}}_pb2.py" ] |
| 140 } else { | 144 args += [ |
| 141 cc_generator_options = "" | 145 "--python_out", |
| 146 rel_py_out_dir, |
| 147 ] |
| 142 } | 148 } |
| 143 args += [ | 149 |
| 144 # cc_generator_options is supposed to end in a colon if it's nonempty. | 150 if (!defined(invoker.generate_cc) || invoker.generate_cc) { |
| 145 "--cpp_out", | 151 # If passed cc_generator_options should end in a colon, which will |
| 146 "$cc_generator_options$rel_out_dir", | 152 # separate it from the directory when we concatenate them. The proto |
| 147 "--python_out", | 153 # compiler understands this syntax. |
| 148 rel_py_out_dir, | 154 if (defined(invoker.cc_generator_options)) { |
| 149 ] | 155 cc_generator_options = invoker.cc_generator_options |
| 156 } else { |
| 157 cc_generator_options = "" |
| 158 } |
| 159 outputs += [ |
| 160 "$out_dir/{{source_name_part}}.pb.cc", |
| 161 "$out_dir/{{source_name_part}}.pb.h", |
| 162 ] |
| 163 args += [ |
| 164 "--cpp_out", |
| 165 "$cc_generator_options$rel_out_dir", # Separated by colon. |
| 166 ] |
| 167 } |
| 168 |
| 169 if (defined(invoker.generator_plugin)) { |
| 170 generator_plugin = invoker.generator_plugin |
| 171 generator_plugin_suffix = invoker.generator_plugin_suffix |
| 172 if (defined(invoker.generator_plugin_options)) { |
| 173 generator_plugin_options = invoker.generator_plugin_options |
| 174 } else { |
| 175 generator_plugin_options = "" |
| 176 } |
| 177 outputs += [ |
| 178 "$out_dir/{{source_name_part}}$generator_plugin_suffix.cc", |
| 179 "$out_dir/{{source_name_part}}$generator_plugin_suffix.h", |
| 180 ] |
| 181 args += [ |
| 182 "--plugin", |
| 183 "protoc-gen-plugin=./$generator_plugin", |
| 184 "--plugin_out", |
| 185 "$generator_plugin_options$rel_out_dir", # Separated by colon. |
| 186 ] |
| 187 } |
| 150 | 188 |
| 151 deps = [ | 189 deps = [ |
| 152 protoc_label, | 190 protoc_label, |
| 153 ] | 191 ] |
| 154 | 192 |
| 155 # The deps may have steps that have to run before runnign protobuf. | 193 # The deps may have steps that have to run before running protobuf. |
| 156 if (defined(invoker.deps)) { | 194 if (defined(invoker.deps)) { |
| 157 deps += invoker.deps | 195 deps += invoker.deps |
| 158 } | 196 } |
| 159 } | 197 } |
| 160 | 198 |
| 161 if (defined(invoker.component_build_force_source_set) && | 199 if (defined(invoker.component_build_force_source_set) && |
| 162 invoker.component_build_force_source_set && | 200 invoker.component_build_force_source_set && |
| 163 is_component_build) { | 201 is_component_build) { |
| 164 link_target_type = "source_set" | 202 link_target_type = "source_set" |
| 165 } else { | 203 } else { |
| 166 link_target_type = "static_library" | 204 link_target_type = "static_library" |
| 167 } | 205 } |
| 168 target(link_target_type, target_name) { | 206 target(link_target_type, target_name) { |
| 169 forward_variables_from(invoker, | 207 forward_variables_from(invoker, |
| 170 [ | 208 [ |
| 171 "visibility", | 209 "visibility", |
| 172 "defines", | 210 "defines", |
| 173 ]) | 211 ]) |
| 174 | 212 |
| 175 sources = get_target_outputs(":$action_name") | 213 sources = get_target_outputs(":$action_name") |
| 176 | 214 |
| 177 if (defined(invoker.extra_configs)) { | 215 if (defined(invoker.extra_configs)) { |
| 178 configs += invoker.extra_configs | 216 configs += invoker.extra_configs |
| 179 } | 217 } |
| 180 | 218 |
| 181 public_configs = [ "//third_party/protobuf:using_proto" ] | 219 public_configs = [ "//third_party/protobuf:using_proto" ] |
| 182 | 220 |
| 183 public_deps = [ | 221 # If using built-in cc generator the resulting headers reference headers |
| 184 # The generated headers reference headers within protobuf_lite, so | 222 # within protobuf_lite, hence dependencies require those headers too. |
| 185 # dependencies must be able to find those headers too. | 223 # In case of generator plugin such issues should be resolved by invoker. |
| 186 "//third_party/protobuf:protobuf_lite", | 224 if (!defined(invoker.generate_cc) || invoker.generate_cc) { |
| 187 ] | 225 public_deps = [ |
| 226 "//third_party/protobuf:protobuf_lite", |
| 227 ] |
| 228 } |
| 188 deps = [ | 229 deps = [ |
| 189 ":$action_name", | 230 ":$action_name", |
| 190 ] | 231 ] |
| 191 | 232 |
| 192 # This will link any libraries in the deps (the use of invoker.deps in the | 233 # This will link any libraries in the deps (the use of invoker.deps in the |
| 193 # action won't link it). | 234 # action won't link it). |
| 194 if (defined(invoker.deps)) { | 235 if (defined(invoker.deps)) { |
| 195 deps += invoker.deps | 236 deps += invoker.deps |
| 196 } | 237 } |
| 197 } | 238 } |
| 198 } | 239 } |
| OLD | NEW |