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

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: comments Created 4 years, 5 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
« no previous file with comments | « 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 # Target name of plugin which generates custom cc stubs.
xyzzyz 2016/06/22 17:29:30 What exactly is "target name" here? By looking at
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
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 passed cc_generator_options should end in a colon, which will
138 "$cc_generator_options$rel_out_dir", 143 # separate it from the directory when we concatenate them. The proto
139 "--python_out", 144 # compiler understands this syntax.
140 rel_py_out_dir, 145 if (defined(invoker.cc_generator_options)) {
141 ] 146 cc_generator_options = invoker.cc_generator_options
147 } else {
148 cc_generator_options = ""
149 }
150 outputs += [
151 "$out_dir/{{source_name_part}}.pb.cc",
152 "$out_dir/{{source_name_part}}.pb.h",
153 ]
154 args += [
155 "--cpp_out",
156 "$cc_generator_options$rel_out_dir", # Separated by colon.
157 ]
158 }
159
160 if (defined(invoker.generator_plugin)) {
161 generator_plugin = invoker.generator_plugin
162 generator_plugin_suffix = invoker.generator_plugin_suffix
163 if (defined(invoker.generator_plugin_options)) {
164 generator_plugin_options = invoker.generator_plugin_options
165 } else {
166 generator_plugin_options = ""
167 }
168 outputs += [
169 "$out_dir/{{source_name_part}}$generator_plugin_suffix.cc",
170 "$out_dir/{{source_name_part}}$generator_plugin_suffix.h",
171 ]
172 args += [
173 "--plugin",
174 "protoc-gen-plugin=./$generator_plugin",
175 "--plugin_out",
176 "$generator_plugin_options$rel_out_dir", # Separated by colon.
177 ]
178 }
142 179
143 deps = [ 180 deps = [
144 protoc_label, 181 protoc_label,
145 ] 182 ]
146 183
147 # The deps may have steps that have to run before runnign protobuf. 184 # The deps may have steps that have to run before running protobuf.
148 if (defined(invoker.deps)) { 185 if (defined(invoker.deps)) {
149 deps += invoker.deps 186 deps += invoker.deps
150 } 187 }
151 } 188 }
152 189
153 source_set(target_name) { 190 source_set(target_name) {
154 forward_variables_from(invoker, 191 forward_variables_from(invoker,
155 [ 192 [
156 "visibility", 193 "visibility",
157 "defines", 194 "defines",
158 ]) 195 ])
159 196
160 sources = get_target_outputs(":$action_name") 197 sources = get_target_outputs(":$action_name")
161 198
162 if (defined(invoker.extra_configs)) { 199 if (defined(invoker.extra_configs)) {
163 configs += invoker.extra_configs 200 configs += invoker.extra_configs
164 } 201 }
165 202
166 public_configs = [ "//third_party/protobuf:using_proto" ] 203 public_configs = [ "//third_party/protobuf:using_proto" ]
167 204
168 public_deps = [ 205 # If using built-in cc generator the resulting headers reference headers
169 # The generated headers reference headers within protobuf_lite, so 206 # within protobuf_lite, hence dependencies require those headers too.
170 # dependencies must be able to find those headers too. 207 # In case of generator plugin such issues should be resolved by invoker.
171 "//third_party/protobuf:protobuf_lite", 208 if (!defined(invoker.generate_cc) || invoker.generate_cc) {
172 ] 209 public_deps = [
210 "//third_party/protobuf:protobuf_lite",
211 ]
212 }
173 deps = [ 213 deps = [
174 ":$action_name", 214 ":$action_name",
175 ] 215 ]
176 216
177 # This will link any libraries in the deps (the use of invoker.deps in the 217 # This will link any libraries in the deps (the use of invoker.deps in the
178 # action won't link it). 218 # action won't link it).
179 if (defined(invoker.deps)) { 219 if (defined(invoker.deps)) {
180 deps += invoker.deps 220 deps += invoker.deps
181 } 221 }
182 } 222 }
183 } 223 }
OLDNEW
« no previous file with comments | « build/protoc.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698