Commit 8aa669ef authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

[protoc] Use protoc's lite java plugin and runtime

protoc the protobuf compiler now requires using a separate plugin for
compiling protos for the java lite runtime. The lite java runtime is now
also separate from the main java runtime and is distributed separately.

This cl switches java proto compilation for lite protos to this new
mode.

TBR=android_webview/BUILD.gn

Bug: 782237, 800281
Change-Id: I31c2d073bed51109dffeea133495679deef3186b
Reviewed-on: https://chromium-review.googlesource.com/c/1340522
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612720}
parent 9b0c8199
......@@ -965,7 +965,7 @@ android_library("android_webview_variations_utils_java") {
"//android_webview/proto:aw_variations_seed_proto_java",
"//base:base_java",
"//components/variations/android:variations_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
]
}
......
......@@ -3470,7 +3470,9 @@ if (enable_java_templates) {
_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_runtime =
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java"
_protoc_javalite_plugin_dir = "//third_party/protoc_javalite/"
}
_proto_path = invoker.proto_path
_template_name = target_name
......@@ -3503,6 +3505,11 @@ if (enable_java_templates) {
] + rebase_path(sources, root_build_dir)
if (_generate_nano) {
args += [ "--nano" ]
} else {
args += [
"--protoc-javalite-plugin-dir",
rebase_path(_protoc_javalite_plugin_dir, root_build_dir),
]
}
}
......
......@@ -35,6 +35,8 @@ def main(argv):
parser.add_option("--stamp", help="File to touch on success.")
parser.add_option("--nano",
help="Use to generate nano protos.", action='store_true')
parser.add_option("--protoc-javalite-plugin-dir",
help="Path to protoc java lite plugin directory.")
options, args = parser.parse_args(argv)
build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
......@@ -42,6 +44,10 @@ def main(argv):
print 'One of --java-out-dir or --srcjar must be specified.'
return 1
if not options.nano and not options.protoc_javalite_plugin_dir:
print 'One of --nano or --protoc-javalite-plugin-dir must be specified.'
return 1
with build_utils.TempDir() as temp_dir:
if options.nano:
# Specify arguments to the generator.
......@@ -49,23 +55,19 @@ def main(argv):
'store_unknown_fields=true']
out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
else:
out_arg = '--java_out=' + temp_dir
out_arg = '--javalite_out=' + temp_dir
custom_env = os.environ.copy()
if options.protoc_javalite_plugin_dir:
# if we are generating lite protos, then the lite plugin needs to be in the path when protoc
# is called. See https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md
custom_env['PATH'] = '{}:{}'.format(
os.path.abspath(options.protoc_javalite_plugin_dir), custom_env['PATH'])
# 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.')
# Generate Java files using protoc.
build_utils.CheckOutput(
[options.protoc, '--proto_path', options.proto_path, out_arg]
+ args)
+ args, env=custom_env)
if options.java_out_dir:
build_utils.DeleteDirectory(options.java_out_dir)
......
......@@ -315,6 +315,7 @@ android_library("chrome_java") {
"//third_party/android_deps:android_support_v7_mediarouter_java",
"//third_party/android_deps:android_support_v7_recyclerview_java",
"//third_party/android_deps:com_google_dagger_dagger_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/android_deps:javax_inject_javax_inject_java",
"//third_party/android_media:android_media_java",
"//third_party/android_swipe_refresh:android_swipe_refresh_java",
......@@ -330,7 +331,6 @@ android_library("chrome_java") {
"//third_party/feed:feed_lib_proto_java",
"//third_party/gif_player:gif_player_java",
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/protobuf:protobuf_lite_javalib",
"//ui/android:ui_java",
"//ui/base/mojo:mojo_java",
"//ui/gfx/geometry/mojo:mojo_java",
......@@ -700,6 +700,7 @@ android_library("chrome_test_java") {
"//third_party/android_deps:android_support_design_java",
"//third_party/android_deps:android_support_v7_appcompat_java",
"//third_party/android_deps:android_support_v7_recyclerview_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/android_tools:android_test_base_java",
......@@ -717,7 +718,6 @@ android_library("chrome_test_java") {
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/junit",
"//third_party/mockito:mockito_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//third_party/ub-uiautomator:ub_uiautomator_java",
"//ui/android:ui_java",
"//ui/android:ui_java_test_support",
......@@ -1405,7 +1405,7 @@ android_library("browser_java_test_support") {
":chrome_java",
"//base:base_java",
"//components/sync:test_support_proto_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
]
}
......
......@@ -274,10 +274,10 @@ if (is_android) {
"//base:base_java",
"//components/signin/core/browser/android:java",
"//components/sync/android:sync_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/cacheinvalidation:cacheinvalidation_javalib",
"//third_party/cacheinvalidation:cacheinvalidation_proto_java",
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/protobuf:protobuf_lite_javalib",
]
java_files = [
"android/java/src/org/chromium/components/invalidation/InvalidationClientService.java",
......
......@@ -65,8 +65,8 @@ android_library("feed_lib_java") {
"//third_party/android_deps:android_support_cardview_java",
"//third_party/android_deps:android_support_v7_appcompat_java",
"//third_party/android_deps:android_support_v7_recyclerview_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/protobuf:protobuf_lite_javalib",
]
}
......@@ -78,10 +78,10 @@ android_library("feed_conformance_test_lib_android_java") {
deps = [
":feed_lib_java",
":feed_lib_proto_java",
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/google-truth:google_truth_java",
"//third_party/guava:guava_android_java",
"//third_party/junit:junit",
"//third_party/protobuf:protobuf_lite_javalib",
]
}
......
......@@ -690,61 +690,3 @@ group("py_proto") {
data += get_target_outputs(":copy_google_protobuf")
data += get_target_outputs(":copy_google_protobuf_internal")
}
if (is_android) {
import("//build/config/android/rules.gni")
android_library("protobuf_lite_javalib") {
chromium_code = false
java_files = [
"java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java",
"java/core/src/main/java/com/google/protobuf/AbstractParser.java",
"java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java",
"java/core/src/main/java/com/google/protobuf/Android.java",
"java/core/src/main/java/com/google/protobuf/BooleanArrayList.java",
"java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java",
"java/core/src/main/java/com/google/protobuf/ByteOutput.java",
"java/core/src/main/java/com/google/protobuf/ByteString.java",
"java/core/src/main/java/com/google/protobuf/CodedInputStream.java",
"java/core/src/main/java/com/google/protobuf/CodedOutputStream.java",
"java/core/src/main/java/com/google/protobuf/DoubleArrayList.java",
"java/core/src/main/java/com/google/protobuf/ExperimentalApi.java",
"java/core/src/main/java/com/google/protobuf/ExtensionLite.java",
"java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java",
"java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java",
"java/core/src/main/java/com/google/protobuf/FieldSet.java",
"java/core/src/main/java/com/google/protobuf/FloatArrayList.java",
"java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java",
"java/core/src/main/java/com/google/protobuf/IntArrayList.java",
"java/core/src/main/java/com/google/protobuf/Internal.java",
"java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java",
"java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java",
"java/core/src/main/java/com/google/protobuf/LazyField.java",
"java/core/src/main/java/com/google/protobuf/LazyFieldLite.java",
"java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java",
"java/core/src/main/java/com/google/protobuf/LazyStringList.java",
"java/core/src/main/java/com/google/protobuf/LongArrayList.java",
"java/core/src/main/java/com/google/protobuf/MapEntryLite.java",
"java/core/src/main/java/com/google/protobuf/MapFieldLite.java",
"java/core/src/main/java/com/google/protobuf/MessageLite.java",
"java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java",
"java/core/src/main/java/com/google/protobuf/MessageLiteToString.java",
"java/core/src/main/java/com/google/protobuf/MutabilityOracle.java",
"java/core/src/main/java/com/google/protobuf/NioByteString.java",
"java/core/src/main/java/com/google/protobuf/Parser.java",
"java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java",
"java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java",
"java/core/src/main/java/com/google/protobuf/ProtocolStringList.java",
"java/core/src/main/java/com/google/protobuf/RopeByteString.java",
"java/core/src/main/java/com/google/protobuf/SmallSortedMap.java",
"java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java",
"java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java",
"java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java",
"java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java",
"java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java",
"java/core/src/main/java/com/google/protobuf/UnsafeUtil.java",
"java/core/src/main/java/com/google/protobuf/Utf8.java",
"java/core/src/main/java/com/google/protobuf/WireFormat.java",
]
}
}
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