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