Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/protobuf/proto_library.gni

Issue 2082693002: Plugin support for protobuf compiler (protoc) targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more flexible targets and revert of protoc_wrapper Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« build/protoc.gypi ('K') | « build/protoc.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Custom plugin executable name.
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 I think this is s/executable/target/
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 22 matching lines...) Expand all
60 75
61 action_name = "${target_name}_gen" 76 action_name = "${target_name}_gen"
62 source_set_name = target_name 77 source_set_name = target_name
63 action_foreach(action_name) { 78 action_foreach(action_name) {
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
85 if (defined(invoker.generate_python)) {
86 generate_python = invoker.generate_python
87 } else {
88 generate_python = true
89 }
90
91 if (defined(invoker.generate_cc)) {
92 generate_cc = invoker.generate_cc
93 } else {
94 generate_cc = true
95 }
96
97 if (defined(invoker.generator_plugin)) {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 not sure you need this (See below)
98 generator_plugin = invoker.generator_plugin
99 } else {
100 generator_plugin = ""
101 }
102
70 # Compute the output directory, both relative to the source root (for 103 # Compute the output directory, both relative to the source root (for
71 # declaring "outputs") and relative to the build dir (for passing to the 104 # declaring "outputs") and relative to the build dir (for passing to the
72 # script). 105 # script).
73 if (defined(invoker.proto_out_dir)) { 106 if (defined(invoker.proto_out_dir)) {
74 # Put the results in the specified dir in the gen tree. 107 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 { 108 } else {
79 # Use the gen directory corresponding to the source file for C++ sources. 109 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 } 110 }
87 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir) 111 out_dir = "$root_gen_dir/" + proto_out_dir
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 It seems this is changing the assignment of out_di
kraynov 2016/06/21 14:40:49 It is intended. These string will be the same. Bas
112 rel_out_dir = rebase_path(out_dir, root_build_dir)
88 113
89 outputs = [ 114 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 115
95 args = [] 116 args = []
96 if (defined(invoker.cc_include)) { 117 if (defined(invoker.cc_include)) {
97 args += [ 118 args += [
98 "--include", 119 "--include",
99 invoker.cc_include, 120 invoker.cc_include,
121 "--protobuf",
122 "$rel_out_dir/{{source_name_part}}.pb.h",
100 ] 123 ]
101 } 124 }
102 125
103 args += [ 126 args += [
104 "--protobuf",
105 "$rel_out_dir/{{source_name_part}}.pb.h",
106 "--proto-in-dir", 127 "--proto-in-dir",
107 "{{source_dir}}", 128 "{{source_dir}}",
108 "--proto-in-file", 129 "--proto-in-file",
109 "{{source_file_part}}", 130 "{{source_file_part}}",
110 131
111 # TODO(brettw) support system protobuf compiler. 132 # TODO(brettw) support system protobuf compiler.
112 "--use-system-protobuf=0", 133 "--use-system-protobuf=0",
113 ] 134 ]
114 135
115 protoc_label = "//third_party/protobuf:protoc($host_toolchain)" 136 protoc_label = "//third_party/protobuf:protoc($host_toolchain)"
116 args += [ 137 args += [
117 "--", 138 "--",
118 139
119 # Prepend with "./" so this will never pick up the system one (normally 140 # 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 141 # when not cross-compiling, protoc's output directory will be the same
121 # as the build dir, so the relative location will be empty). 142 # as the build dir, so the relative location will be empty).
122 "./" + 143 "./" +
123 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc", 144 rebase_path(get_label_info(protoc_label, "root_out_dir") + "/protoc",
124 root_build_dir), 145 root_build_dir),
125 ] 146 ]
126 147
127 # If passed cc_generator_options should end in a colon, which will separate 148 if (generate_python) {
128 # it from the directory when we concatenate them. The proto compiler 149 py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir
129 # understands this syntax. 150 rel_py_out_dir = rebase_path(py_out_dir, root_build_dir)
130 if (defined(invoker.cc_generator_options)) { 151
131 cc_generator_options = invoker.cc_generator_options 152 outputs += [ "$py_out_dir/{{source_name_part}}_pb2.py" ]
132 } else { 153 args += [
133 cc_generator_options = "" 154 "--python_out",
155 rel_py_out_dir,
156 ]
134 } 157 }
135 args += [ 158
136 # cc_generator_options is supposed to end in a colon if it's nonempty. 159 if (generate_cc) {
137 "--cpp_out", 160 if (defined(invoker.cc_generator_options)) {
138 "$cc_generator_options$rel_out_dir", 161 cc_generator_options = invoker.cc_generator_options
139 "--python_out", 162 } else {
140 rel_py_out_dir, 163 cc_generator_options = ""
141 ] 164 }
165 outputs += [
166 "$out_dir/{{source_name_part}}.pb.cc",
167 "$out_dir/{{source_name_part}}.pb.h",
168 ]
169 args += [
170 "--cpp_out",
171 "$cc_generator_options$rel_out_dir", # Separated by colon.
172 ]
173 }
174
175 if (generator_plugin != "") {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 Why this is not if (defined(invoker.generator_plu
176 if (defined(invoker.generator_plugin_options)) {
177 generator_plugin_options = invoker.generator_plugin_options
178 } else {
179 generator_plugin_options = ""
180 }
181 generator_plugin_suffix = invoker.generator_plugin_suffix
182 outputs += [
183 "$out_dir/{{source_name_part}}$generator_plugin_suffix.cc",
184 "$out_dir/{{source_name_part}}$generator_plugin_suffix.h",
185 ]
186 args += [
187 "--plugin",
188 "protoc-gen-plugin=./$generator_plugin",
189 "--plugin_out",
190 "$generator_plugin_options$rel_out_dir", # Separated by colon.
191 ]
192 }
142 193
143 deps = [ 194 deps = [
144 protoc_label, 195 protoc_label,
145 ] 196 ]
146 197
147 # The deps may have steps that have to run before runnign protobuf. 198 # The deps may have steps that have to run before running protobuf.
148 if (defined(invoker.deps)) { 199 if (defined(invoker.deps)) {
149 deps += invoker.deps 200 deps += invoker.deps
150 } 201 }
151 } 202 }
152 203
153 source_set(target_name) { 204 source_set(target_name) {
154 forward_variables_from(invoker, 205 forward_variables_from(invoker,
155 [ 206 [
156 "visibility", 207 "visibility",
157 "defines", 208 "defines",
158 ]) 209 ])
159 210
160 sources = get_target_outputs(":$action_name") 211 sources = get_target_outputs(":$action_name")
161 212
162 if (defined(invoker.extra_configs)) { 213 if (defined(invoker.extra_configs)) {
163 configs += invoker.extra_configs 214 configs += invoker.extra_configs
164 } 215 }
165 216
166 public_configs = [ "//third_party/protobuf:using_proto" ] 217 public_configs = [ "//third_party/protobuf:using_proto" ]
167 218
168 public_deps = [ 219 # If using built-in cc generator the resulting headers reference headers
169 # The generated headers reference headers within protobuf_lite, so 220 # within protobuf_lite, hence dependencies require those headers too.
170 # dependencies must be able to find those headers too. 221 # In case of generator plugin such issues should be resolved by invoker.
171 "//third_party/protobuf:protobuf_lite", 222 if (!defined(invoker.generator_plugin)) {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 I think this should be really: if (generate_cc)
172 ] 223 public_deps = [
224 "//third_party/protobuf:protobuf_lite",
225 ]
226 }
173 deps = [ 227 deps = [
174 ":$action_name", 228 ":$action_name",
175 ] 229 ]
176 230
177 # This will link any libraries in the deps (the use of invoker.deps in the 231 # This will link any libraries in the deps (the use of invoker.deps in the
178 # action won't link it). 232 # action won't link it).
179 if (defined(invoker.deps)) { 233 if (defined(invoker.deps)) {
180 deps += invoker.deps 234 deps += invoker.deps
181 } 235 }
182 } 236 }
183 } 237 }
OLDNEW
« build/protoc.gypi ('K') | « build/protoc.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698