[protobuf] Switch the default java protobuf generator from nano to lite

This CL takes the (almost) last step in converting java code from
protobuf nano to lite. The only remaining code with nano is
//third_party/cacheinvalidation which is deprecated and should be
replaced later this year.

We still need to keep the generate_lite variable in rules.gni because
it is used in the internal repo. After this CL, I will
 - remove instances of generate_lite from the internal repo and finally
 - remove generate_lite from rules.gni.

Bug: 782237
Change-Id: I65f144c59d84e8c75fe3152543c6e1941e52a3dd
Reviewed-on: https://chromium-review.googlesource.com/998033
Reviewed-by: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: agrieve <agrieve@chromium.org>
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#549129}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: dc072552bd919ccdbacdd8f0ca4373791712f10b
This commit is contained in:
Jan Krcal 2018-04-09 08:52:16 +00:00 коммит произвёл Commit Bot
Родитель 6ae4520a1a
Коммит 969a53e102
2 изменённых файлов: 29 добавлений и 22 удалений

Просмотреть файл

@ -2998,35 +2998,39 @@ if (enable_java_templates) {
# proto_path (required)
# Root directory of .proto files.
#
# generate_lite (optional, default false)
# Whether to generate lite protos. If false, this will use the nano proto generator.
# generate_nano (optional, default false)
# Whether to generate nano protos. If false, this will use the lite proto generator.
# Nano protos are deprecated, so please use lite new proto libraries.
#
# generate_lite (optional, default true)
# Whether to generate lite protos. If false, this will use the nano proto generator.
# This variable is deprecated and cannot be used at the same time as generate_nano.
#
# Example:
# proto_java_library("foo_proto_java") {
# proto_path = "src/foo"
# sources = [ "$proto_path/foo.proto" ]
# generate_lite = true
# }
template("proto_java_library") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ])
_generate_lite =
defined(invoker.generate_lite) && invoker.generate_lite == true
_generate_nano =
(defined(invoker.generate_nano) && invoker.generate_nano == true) ||
(defined(invoker.generate_lite) && invoker.generate_lite == false)
if (_generate_lite) {
# Use the regular proto library to generate lite protos.
_protoc_dep = "//third_party/protobuf:protoc($host_toolchain)"
_protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
_protoc_bin = "$_protoc_out_dir/protoc"
_proto_runtime = "//third_party/protobuf:protobuf_lite_javalib"
} else {
if (_generate_nano) {
# Use the legacy Android nano proto generator.
_protoc_dep =
"//third_party/android_protobuf:android_protoc($host_toolchain)"
_protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
_protoc_bin = "$_protoc_out_dir/android_protoc"
_proto_runtime = "//third_party/android_protobuf:protobuf_nano_javalib"
} else {
# Use the regular proto library to generate lite protos.
_protoc_dep = "//third_party/protobuf:protoc($host_toolchain)"
_protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
_protoc_bin = "$_protoc_out_dir/protoc"
_proto_runtime = "//third_party/protobuf:protobuf_lite_javalib"
}
_proto_path = invoker.proto_path
_template_name = target_name
@ -3057,8 +3061,8 @@ if (enable_java_templates) {
"--srcjar",
rebase_path(_srcjar_path, root_build_dir),
] + rebase_path(sources, root_build_dir)
if (_generate_lite) {
args += [ "--lite" ]
if (_generate_nano) {
args += [ "--nano" ]
}
}

Просмотреть файл

@ -33,8 +33,8 @@ def main(argv):
help="Path to output directory for java files.")
parser.add_option("--srcjar", help="Path to output srcjar.")
parser.add_option("--stamp", help="File to touch on success.")
parser.add_option("--lite",
help="Use to generate lite protos.", action='store_true')
parser.add_option("--nano",
help="Use to generate nano protos.", action='store_true')
options, args = parser.parse_args(argv)
build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
@ -43,22 +43,25 @@ def main(argv):
return 1
with build_utils.TempDir() as temp_dir:
if options.lite:
if options.nano:
# Specify arguments to the generator.
generator_args = ['optional_field_style=reftypes',
'store_unknown_fields=true']
out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
else:
out_arg = '--java_out=' + temp_dir
# Check if all proto files (which are listed in the args) are opting to
# use the lite runtime, otherwise we'd have to include the much heavier
# regular proto runtime in Chrome.
# TODO(jkrcal): Replace this check by '--java_lite_out=' for the out_arg
# above once this works on the master branch of the protobuf library,
# expected in version 4.0 (see https://crbug.com/800281).
for proto_file in args:
if not 'LITE_RUNTIME' in open(proto_file).read():
raise Exception(
'Chrome only supports lite protos. Please add "optimize_for = '
'LITE_RUNTIME" to your proto file to enable the lite runtime.')
else:
# Specify arguments to the generator.
generator_args = ['optional_field_style=reftypes',
'store_unknown_fields=true']
out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
# Generate Java files using protoc.
build_utils.CheckOutput(
[options.protoc, '--proto_path', options.proto_path, out_arg]