Chromium Code Reviews| 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. | 32 # macro to work. See cc_include. |
| 27 # | 33 # |
| 34 # generator_plugin (optional) | |
|
xyzzyz
2016/06/21 20:29:44
Same as in gypi (cc_generator_plugin and same for
| |
| 35 # Custom plugin target name. | |
| 36 # | |
| 37 # generator_plugin_suffix (required if generator_plugin set) | |
| 38 # Suffix (before extension) for generated .cc and .h files. | |
| 39 # | |
| 40 # generator_plugin_options (optional) | |
| 41 # Extra flags passed to the plugin. See cc_generator_options. | |
| 42 # | |
| 28 # cc_include (optional) | 43 # cc_include (optional) |
| 29 # String listing an extra include that should be passed. | 44 # String listing an extra include that should be passed. |
| 30 # Example: cc_include = "foo/bar.h" | 45 # Example: cc_include = "foo/bar.h" |
| 31 # | 46 # |
| 32 # deps (optional) | 47 # deps (optional) |
| 33 # Additional dependencies. | 48 # Additional dependencies. |
| 34 # | 49 # |
| 35 # Parameters for compiling the generated code: | 50 # Parameters for compiling the generated code: |
| 36 # | 51 # |
| 37 # defines (optional) | 52 # defines (optional) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 64 visibility = [ ":$source_set_name" ] | 79 visibility = [ ":$source_set_name" ] |
| 65 | 80 |
| 66 script = "//tools/protoc_wrapper/protoc_wrapper.py" | 81 script = "//tools/protoc_wrapper/protoc_wrapper.py" |
| 67 | 82 |
| 68 sources = invoker.sources | 83 sources = invoker.sources |
| 69 | 84 |
| 70 # Compute the output directory, both relative to the source root (for | 85 # Compute the output directory, both relative to the source root (for |
| 71 # declaring "outputs") and relative to the build dir (for passing to the | 86 # declaring "outputs") and relative to the build dir (for passing to the |
| 72 # script). | 87 # script). |
| 73 if (defined(invoker.proto_out_dir)) { | 88 if (defined(invoker.proto_out_dir)) { |
| 74 # Put the results in the specified dir in the gen tree. | 89 proto_out_dir = invoker.proto_out_dir |
| 75 out_dir = "$root_gen_dir/" + invoker.proto_out_dir | |
| 76 rel_out_dir = rebase_path(out_dir, root_build_dir) | |
| 77 py_out_dir = "$root_out_dir/pyproto/" + invoker.proto_out_dir | |
| 78 } else { | 90 } else { |
| 79 # Use the gen directory corresponding to the source file for C++ sources. | 91 proto_out_dir = "{{source_root_relative_dir}}" |
| 80 # This expansion will be done differently in the outputs and the args, so | |
| 81 # we don't need to worry about rebasing as above. Always put Python | |
| 82 # sources in "pyproto". | |
| 83 out_dir = "{{source_gen_dir}}" | |
| 84 rel_out_dir = "{{source_gen_dir}}" | |
| 85 py_out_dir = "$root_out_dir/pyproto/{{source_root_relative_dir}}" | |
| 86 } | 92 } |
| 87 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir) | 93 out_dir = "$root_gen_dir/" + proto_out_dir |
| 94 rel_out_dir = rebase_path(out_dir, root_build_dir) | |
| 88 | 95 |
| 89 outputs = [ | 96 outputs = [] |
| 90 "$py_out_dir/{{source_name_part}}_pb2.py", | |
| 91 "$out_dir/{{source_name_part}}.pb.cc", | |
| 92 "$out_dir/{{source_name_part}}.pb.h", | |
| 93 ] | |
| 94 | 97 |
| 95 args = [] | 98 args = [] |
| 96 if (defined(invoker.cc_include)) { | 99 if (defined(invoker.cc_include)) { |
| 97 args += [ | 100 args += [ |
| 98 "--include", | 101 "--include", |
| 99 invoker.cc_include, | 102 invoker.cc_include, |
| 103 "--protobuf", | |
| 104 "$rel_out_dir/{{source_name_part}}.pb.h", | |
| 100 ] | 105 ] |
| 101 } | 106 } |
| 102 | 107 |
| 103 args += [ | 108 args += [ |
| 104 "--protobuf", | |
| 105 "$rel_out_dir/{{source_name_part}}.pb.h", | |
| 106 "--proto-in-dir", | 109 "--proto-in-dir", |
| 107 "{{source_dir}}", | 110 "{{source_dir}}", |
| 108 "--proto-in-file", | 111 "--proto-in-file", |
| 109 "{{source_file_part}}", | 112 "{{source_file_part}}", |
| 110 | 113 |
| 111 # TODO(brettw) support system protobuf compiler. | 114 # TODO(brettw) support system protobuf compiler. |
| 112 "--use-system-protobuf=0", | 115 "--use-system-protobuf=0", |
| 113 ] | 116 ] |
| 114 | 117 |
| 115 protoc_label = "//third_party/protobuf:protoc($host_toolchain)" | 118 protoc_label = "//third_party/protobuf:protoc($host_toolchain)" |
| 116 args += [ | 119 args += [ |
| 117 "--", | 120 "--", |
| 118 | 121 |
| 119 # Prepend with "./" so this will never pick up the system one (normally | 122 # Prepend with "./" so this will never pick up the system one (normally |
| 120 # when not cross-compiling, protoc's output directory will be the same | 123 # when not cross-compiling, protoc's output directory will be the same |
| 121 # as the build dir, so the relative location will be empty). | 124 # as the build dir, so the relative location will be empty). |
| 122 "./" + | 125 "./" + |
| 123 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc", | 126 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc", |
| 124 root_build_dir), | 127 root_build_dir), |
| 125 ] | 128 ] |
| 126 | 129 |
| 127 # If passed cc_generator_options should end in a colon, which will separate | 130 if (!defined(invoker.generate_python) || invoker.generate_python) { |
| 128 # it from the directory when we concatenate them. The proto compiler | 131 py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir |
| 129 # understands this syntax. | 132 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir) |
| 130 if (defined(invoker.cc_generator_options)) { | 133 |
| 131 cc_generator_options = invoker.cc_generator_options | 134 outputs += [ "$py_out_dir/{{source_name_part}}_pb2.py" ] |
| 132 } else { | 135 args += [ |
| 133 cc_generator_options = "" | 136 "--python_out", |
| 137 rel_py_out_dir, | |
| 138 ] | |
| 134 } | 139 } |
| 135 args += [ | 140 |
| 136 # cc_generator_options is supposed to end in a colon if it's nonempty. | 141 if (!defined(invoker.generate_cc) || invoker.generate_cc) { |
| 137 "--cpp_out", | 142 if (defined(invoker.cc_generator_options)) { |
| 138 "$cc_generator_options$rel_out_dir", | 143 cc_generator_options = invoker.cc_generator_options |
| 139 "--python_out", | 144 } else { |
| 140 rel_py_out_dir, | 145 cc_generator_options = "" |
| 141 ] | 146 } |
| 147 outputs += [ | |
| 148 "$out_dir/{{source_name_part}}.pb.cc", | |
| 149 "$out_dir/{{source_name_part}}.pb.h", | |
| 150 ] | |
| 151 args += [ | |
| 152 "--cpp_out", | |
| 153 "$cc_generator_options$rel_out_dir", # Separated by colon. | |
|
xyzzyz
2016/06/21 20:29:44
Could you keep the original comment about colon? I
| |
| 154 ] | |
| 155 } | |
| 156 | |
| 157 if (defined(invoker.generator_plugin)) { | |
| 158 generator_plugin = invoker.generator_plugin | |
| 159 generator_plugin_suffix = invoker.generator_plugin_suffix | |
| 160 if (defined(invoker.generator_plugin_options)) { | |
| 161 generator_plugin_options = invoker.generator_plugin_options | |
| 162 } else { | |
| 163 generator_plugin_options = "" | |
| 164 } | |
| 165 outputs += [ | |
| 166 "$out_dir/{{source_name_part}}$generator_plugin_suffix.cc", | |
| 167 "$out_dir/{{source_name_part}}$generator_plugin_suffix.h", | |
| 168 ] | |
| 169 args += [ | |
| 170 "--plugin", | |
| 171 "protoc-gen-plugin=./$generator_plugin", | |
| 172 "--plugin_out", | |
| 173 "$generator_plugin_options$rel_out_dir", # Separated by colon. | |
| 174 ] | |
| 175 } | |
| 142 | 176 |
| 143 deps = [ | 177 deps = [ |
| 144 protoc_label, | 178 protoc_label, |
| 145 ] | 179 ] |
| 146 | 180 |
| 147 # The deps may have steps that have to run before runnign protobuf. | 181 # The deps may have steps that have to run before running protobuf. |
| 148 if (defined(invoker.deps)) { | 182 if (defined(invoker.deps)) { |
| 149 deps += invoker.deps | 183 deps += invoker.deps |
| 150 } | 184 } |
| 151 } | 185 } |
| 152 | 186 |
| 153 source_set(target_name) { | 187 source_set(target_name) { |
| 154 forward_variables_from(invoker, | 188 forward_variables_from(invoker, |
| 155 [ | 189 [ |
| 156 "visibility", | 190 "visibility", |
| 157 "defines", | 191 "defines", |
| 158 ]) | 192 ]) |
| 159 | 193 |
| 160 sources = get_target_outputs(":$action_name") | 194 sources = get_target_outputs(":$action_name") |
| 161 | 195 |
| 162 if (defined(invoker.extra_configs)) { | 196 if (defined(invoker.extra_configs)) { |
| 163 configs += invoker.extra_configs | 197 configs += invoker.extra_configs |
| 164 } | 198 } |
| 165 | 199 |
| 166 public_configs = [ "//third_party/protobuf:using_proto" ] | 200 public_configs = [ "//third_party/protobuf:using_proto" ] |
| 167 | 201 |
| 168 public_deps = [ | 202 # If using built-in cc generator the resulting headers reference headers |
| 169 # The generated headers reference headers within protobuf_lite, so | 203 # within protobuf_lite, hence dependencies require those headers too. |
| 170 # dependencies must be able to find those headers too. | 204 # In case of generator plugin such issues should be resolved by invoker. |
| 171 "//third_party/protobuf:protobuf_lite", | 205 if (!defined(invoker.generate_cc) || invoker.generate_cc) { |
| 172 ] | 206 public_deps = [ |
| 207 "//third_party/protobuf:protobuf_lite", | |
| 208 ] | |
| 209 } | |
| 173 deps = [ | 210 deps = [ |
| 174 ":$action_name", | 211 ":$action_name", |
| 175 ] | 212 ] |
| 176 | 213 |
| 177 # This will link any libraries in the deps (the use of invoker.deps in the | 214 # This will link any libraries in the deps (the use of invoker.deps in the |
| 178 # action won't link it). | 215 # action won't link it). |
| 179 if (defined(invoker.deps)) { | 216 if (defined(invoker.deps)) { |
| 180 deps += invoker.deps | 217 deps += invoker.deps |
| 181 } | 218 } |
| 182 } | 219 } |
| 183 } | 220 } |
| OLD | NEW |