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

Unified 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 side-by-side diff with in-line comments
Download patch
« build/protoc.gypi ('K') | « build/protoc.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/protobuf/proto_library.gni
diff --git a/third_party/protobuf/proto_library.gni b/third_party/protobuf/proto_library.gni
index df9d657bf46aa0366f9681f45db30cc5db87fb42..3bf6df9aaf8c2a0b1299a02f3816140b557552bc 100644
--- a/third_party/protobuf/proto_library.gni
+++ b/third_party/protobuf/proto_library.gni
@@ -16,6 +16,12 @@
# If undefined, this defaults to matching the input directory for each
# .proto file (you should almost always use the default mode).
#
+# generate_python (optional, default true)
+# Generate Python protobuf stubs.
+#
+# generate_cc (optional, default true)
+# Generate C++ protobuf stubs.
+#
# cc_generator_options (optional)
# List of extra flags passed to the protocol compiler. If you need to
# add an EXPORT macro to a protobuf's C++ header, set the
@@ -25,6 +31,15 @@
# It is likely you also need to #include a file for the above EXPORT
# macro to work. See cc_include.
#
+# generator_plugin (optional)
+# Custom plugin executable name.
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 I think this is s/executable/target/
+#
+# generator_plugin_suffix (required if generator_plugin set)
+# Suffix (before extension) for generated .cc and .h files.
+#
+# generator_plugin_options (optional)
+# Extra flags passed to the plugin. See cc_generator_options.
+#
# cc_include (optional)
# String listing an extra include that should be passed.
# Example: cc_include = "foo/bar.h"
@@ -67,42 +82,48 @@ template("proto_library") {
sources = invoker.sources
+ if (defined(invoker.generate_python)) {
+ generate_python = invoker.generate_python
+ } else {
+ generate_python = true
+ }
+
+ if (defined(invoker.generate_cc)) {
+ generate_cc = invoker.generate_cc
+ } else {
+ generate_cc = true
+ }
+
+ if (defined(invoker.generator_plugin)) {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 not sure you need this (See below)
+ generator_plugin = invoker.generator_plugin
+ } else {
+ generator_plugin = ""
+ }
+
# Compute the output directory, both relative to the source root (for
# declaring "outputs") and relative to the build dir (for passing to the
# script).
if (defined(invoker.proto_out_dir)) {
- # Put the results in the specified dir in the gen tree.
- out_dir = "$root_gen_dir/" + invoker.proto_out_dir
- rel_out_dir = rebase_path(out_dir, root_build_dir)
- py_out_dir = "$root_out_dir/pyproto/" + invoker.proto_out_dir
+ proto_out_dir = invoker.proto_out_dir
} else {
- # Use the gen directory corresponding to the source file for C++ sources.
- # This expansion will be done differently in the outputs and the args, so
- # we don't need to worry about rebasing as above. Always put Python
- # sources in "pyproto".
- out_dir = "{{source_gen_dir}}"
- rel_out_dir = "{{source_gen_dir}}"
- py_out_dir = "$root_out_dir/pyproto/{{source_root_relative_dir}}"
+ proto_out_dir = "{{source_root_relative_dir}}"
}
- rel_py_out_dir = rebase_path(py_out_dir, root_build_dir)
+ 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
+ rel_out_dir = rebase_path(out_dir, root_build_dir)
- outputs = [
- "$py_out_dir/{{source_name_part}}_pb2.py",
- "$out_dir/{{source_name_part}}.pb.cc",
- "$out_dir/{{source_name_part}}.pb.h",
- ]
+ outputs = []
args = []
if (defined(invoker.cc_include)) {
args += [
"--include",
invoker.cc_include,
+ "--protobuf",
+ "$rel_out_dir/{{source_name_part}}.pb.h",
]
}
args += [
- "--protobuf",
- "$rel_out_dir/{{source_name_part}}.pb.h",
"--proto-in-dir",
"{{source_dir}}",
"--proto-in-file",
@@ -124,27 +145,57 @@ template("proto_library") {
root_build_dir),
]
- # If passed cc_generator_options should end in a colon, which will separate
- # it from the directory when we concatenate them. The proto compiler
- # understands this syntax.
- if (defined(invoker.cc_generator_options)) {
- cc_generator_options = invoker.cc_generator_options
- } else {
- cc_generator_options = ""
+ if (generate_python) {
+ py_out_dir = "$root_out_dir/pyproto/" + proto_out_dir
+ rel_py_out_dir = rebase_path(py_out_dir, root_build_dir)
+
+ outputs += [ "$py_out_dir/{{source_name_part}}_pb2.py" ]
+ args += [
+ "--python_out",
+ rel_py_out_dir,
+ ]
+ }
+
+ if (generate_cc) {
+ if (defined(invoker.cc_generator_options)) {
+ cc_generator_options = invoker.cc_generator_options
+ } else {
+ cc_generator_options = ""
+ }
+ outputs += [
+ "$out_dir/{{source_name_part}}.pb.cc",
+ "$out_dir/{{source_name_part}}.pb.h",
+ ]
+ args += [
+ "--cpp_out",
+ "$cc_generator_options$rel_out_dir", # Separated by colon.
+ ]
+ }
+
+ if (generator_plugin != "") {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 Why this is not if (defined(invoker.generator_plu
+ if (defined(invoker.generator_plugin_options)) {
+ generator_plugin_options = invoker.generator_plugin_options
+ } else {
+ generator_plugin_options = ""
+ }
+ generator_plugin_suffix = invoker.generator_plugin_suffix
+ outputs += [
+ "$out_dir/{{source_name_part}}$generator_plugin_suffix.cc",
+ "$out_dir/{{source_name_part}}$generator_plugin_suffix.h",
+ ]
+ args += [
+ "--plugin",
+ "protoc-gen-plugin=./$generator_plugin",
+ "--plugin_out",
+ "$generator_plugin_options$rel_out_dir", # Separated by colon.
+ ]
}
- args += [
- # cc_generator_options is supposed to end in a colon if it's nonempty.
- "--cpp_out",
- "$cc_generator_options$rel_out_dir",
- "--python_out",
- rel_py_out_dir,
- ]
deps = [
protoc_label,
]
- # The deps may have steps that have to run before runnign protobuf.
+ # The deps may have steps that have to run before running protobuf.
if (defined(invoker.deps)) {
deps += invoker.deps
}
@@ -165,11 +216,14 @@ template("proto_library") {
public_configs = [ "//third_party/protobuf:using_proto" ]
- public_deps = [
- # The generated headers reference headers within protobuf_lite, so
- # dependencies must be able to find those headers too.
- "//third_party/protobuf:protobuf_lite",
- ]
+ # If using built-in cc generator the resulting headers reference headers
+ # within protobuf_lite, hence dependencies require those headers too.
+ # In case of generator plugin such issues should be resolved by invoker.
+ if (!defined(invoker.generator_plugin)) {
Primiano Tucci (use gerrit) 2016/06/21 14:15:09 I think this should be really: if (generate_cc)
+ public_deps = [
+ "//third_party/protobuf:protobuf_lite",
+ ]
+ }
deps = [
":$action_name",
]
« 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