Commit ec3645ef authored by kraynov's avatar kraynov Committed by Commit bot

Remove workaround from GN proto_library.

Added support for script protobuf compiler plugins.
Removed |json_converter| option workaround.

BUG=637292

Review-Url: https://codereview.chromium.org/2343833002
Cr-Commit-Position: refs/heads/master@{#419139}
parent b0d27dba
...@@ -15,6 +15,7 @@ group("proto") { ...@@ -15,6 +15,7 @@ group("proto") {
protoc_plugin_files = [ protoc_plugin_files = [
"protoc_plugins/json_values_converter.bat", "protoc_plugins/json_values_converter.bat",
"protoc_plugins/json_values_converter.py",
"protoc_plugins/util/__init__.py", "protoc_plugins/util/__init__.py",
"protoc_plugins/util/plugin_protos.py", "protoc_plugins/util/plugin_protos.py",
"protoc_plugins/util/types.py", "protoc_plugins/util/types.py",
...@@ -22,9 +23,9 @@ protoc_plugin_files = [ ...@@ -22,9 +23,9 @@ protoc_plugin_files = [
] ]
if (is_win) { if (is_win) {
json_converter = "protoc_plugins/json_values_converter.bat" json_converter_plugin_script = "protoc_plugins/json_values_converter.bat"
} else { } else {
json_converter = "protoc_plugins/json_values_converter.py" json_converter_plugin_script = "protoc_plugins/json_values_converter.py"
} }
proto_library("dom_distiller_proto") { proto_library("dom_distiller_proto") {
...@@ -33,10 +34,11 @@ proto_library("dom_distiller_proto") { ...@@ -33,10 +34,11 @@ proto_library("dom_distiller_proto") {
"dist/proto/dom_distiller.proto", "dist/proto/dom_distiller.proto",
] ]
proto_out_dir = "third_party/dom_distiller_js" proto_out_dir = "third_party/dom_distiller_js"
json_converter = json_converter
# Depends on protoc_plugins properly generator_plugin_script = json_converter_plugin_script
inputs = protoc_plugin_files generator_plugin_script_deps = protoc_plugin_files
generator_plugin_suffixes = [ "_json_converter.h" ]
generator_plugin_options = "output_dir=:"
} }
# The purpose of json_values_converter_test_proto is to test the # The purpose of json_values_converter_test_proto is to test the
...@@ -47,10 +49,11 @@ proto_library("json_values_converter_test_proto") { ...@@ -47,10 +49,11 @@ proto_library("json_values_converter_test_proto") {
"test_sample.proto", "test_sample.proto",
] ]
proto_out_dir = "third_party/dom_distiller_js" proto_out_dir = "third_party/dom_distiller_js"
json_converter = json_converter
# Depends on protoc_plugins properly generator_plugin_script = json_converter_plugin_script
inputs = protoc_plugin_files generator_plugin_script_deps = protoc_plugin_files
generator_plugin_suffixes = [ "_json_converter.h" ]
generator_plugin_options = "output_dir=:"
} }
action("json_values_converter_tests") { action("json_values_converter_tests") {
......
...@@ -43,8 +43,15 @@ ...@@ -43,8 +43,15 @@
# GN label for plugin executable which generates custom cc stubs. # GN label for plugin executable which generates custom cc stubs.
# Don't specify a toolchain, host toolchain is assumed. # Don't specify a toolchain, host toolchain is assumed.
# #
# generator_plugin_suffix (required if |generator_plugin_label| set) # generator_plugin_script (optional)
# Suffix (before extension) for generated .cc and .h files. # Path to plugin script. Mutually exclusive with |generator_plugin_label|.
#
# generator_plugin_script_deps (optional)
# List of additional files required for generator plugin script.
#
# generator_plugin_suffix[es] (required if using a plugin)
# Suffix (before extension) for generated .cc and .h files
# or list of suffixes for all files (with extensions).
# #
# generator_plugin_options (optional) # generator_plugin_options (optional)
# Extra flags passed to the plugin. See cc_generator_options. # Extra flags passed to the plugin. See cc_generator_options.
...@@ -99,43 +106,34 @@ template("proto_library") { ...@@ -99,43 +106,34 @@ template("proto_library") {
} }
if (defined(invoker.generator_plugin_label)) { if (defined(invoker.generator_plugin_label)) {
generator_plugin_label = invoker.generator_plugin_label
generator_plugin_suffix = invoker.generator_plugin_suffix
generate_with_plugin = true
# Straightforward way to get the name of executable doesn't work because # Straightforward way to get the name of executable doesn't work because
# |root_out_dir| and |root_build_dir| may differ in cross-compilation and # |root_out_dir| and |root_build_dir| may differ in cross-compilation and
# also Windows executables have .exe at the end. # also Windows executables have .exe at the end.
plugin_host_label = generator_plugin_label + "($host_toolchain)" plugin_host_label = invoker.generator_plugin_label + "($host_toolchain)"
plugin_path = get_label_info(plugin_host_label, "root_out_dir") + "/" + plugin_path = get_label_info(plugin_host_label, "root_out_dir") + "/" +
get_label_info(plugin_host_label, "name") get_label_info(plugin_host_label, "name")
if (host_os == "win") { if (host_os == "win") {
plugin_path += ".exe" plugin_path += ".exe"
} }
plugin_path = rebase_path(plugin_path, root_build_dir) generate_with_plugin = true
} else if (defined(invoker.generator_plugin_script)) {
plugin_path = invoker.generator_plugin_script
generate_with_plugin = true
} else { } else {
generate_with_plugin = false generate_with_plugin = false
} }
# TODO(kraynov): Remove (in the next CL) merge conflict temporary workaround. if (generate_with_plugin) {
# This option along with |inputs| would be replaced by the following pattern: if (defined(invoker.generator_plugin_suffix)) {
# source_set("some_python_plugin") { generator_plugin_suffixes = [
# sources = [ "${invoker.generator_plugin_suffix}.h",
# "bar.py", "${invoker.generator_plugin_suffix}.cc",
# ... ]
# ] } else {
# } generator_plugin_suffixes = invoker.generator_plugin_suffixes
# proto_library("some_proto_lib") { }
# generator_plugin_label = ":some_python_plugin" plugin_path = rebase_path(plugin_path, root_build_dir)
# generator_plugin_suffix = ".pb.foo"
# generator_plugin_script = "bar.py"
# }
if (defined(invoker.json_converter)) {
generator_plugin_suffix = "_json_converter"
plugin_path = rebase_path(invoker.json_converter)
invoker.generator_plugin_options = "output_dir=:"
generate_with_plugin = true
} }
if (defined(invoker.proto_in_dir)) { if (defined(invoker.proto_in_dir)) {
...@@ -201,14 +199,8 @@ template("proto_library") { ...@@ -201,14 +199,8 @@ template("proto_library") {
protogens += [ "$py_out_dir/${proto_path}_pb2.py" ] protogens += [ "$py_out_dir/${proto_path}_pb2.py" ]
} }
if (generate_with_plugin) { if (generate_with_plugin) {
# TODO(kraynov): Remove merge conflict temporary workaround. foreach(suffix, generator_plugin_suffixes) {
if (defined(invoker.json_converter)) { protogens += [ "$cc_out_dir/${proto_path}${suffix}" ]
protogens += [ "$cc_out_dir/${proto_path}$generator_plugin_suffix.h" ]
} else {
protogens += [
"$cc_out_dir/${proto_path}$generator_plugin_suffix.h",
"$cc_out_dir/${proto_path}$generator_plugin_suffix.cc",
]
} }
} }
} }
...@@ -224,8 +216,13 @@ template("proto_library") { ...@@ -224,8 +216,13 @@ template("proto_library") {
outputs = get_path_info(protogens, "abspath") outputs = get_path_info(protogens, "abspath")
args = protos args = protos
if (defined(invoker.inputs)) { if (defined(invoker.generator_plugin_script)) {
inputs = invoker.inputs inputs = [
invoker.generator_plugin_script,
]
}
if (defined(invoker.generator_plugin_script_deps)) {
inputs += invoker.generator_plugin_script_deps
} }
protoc_label = "//third_party/protobuf:protoc($host_toolchain)" protoc_label = "//third_party/protobuf:protoc($host_toolchain)"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment