summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2014-09-03 17:28:38 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-04 00:34:47 +0000
commit38f28ba65426989765f8d070ef5f64b5fbce23fa (patch)
treea84c79698b71dd20a83b9320afde8f8505c0ece4
parent8ea27e621946a33a7337ef84c2307c3dfa0eb4db (diff)
downloadchromium_src-38f28ba65426989765f8d070ef5f64b5fbce23fa.zip
chromium_src-38f28ba65426989765f8d070ef5f64b5fbce23fa.tar.gz
chromium_src-38f28ba65426989765f8d070ef5f64b5fbce23fa.tar.bz2
Add support for Java nano protocol buffers for Android (take 2).
This CL adds a new dependency on the protocol buffer compiler from the android source tree, since this compiler supports generating Java files using the nano runtime. The initial version of this dependency is 2.2.0a, but checked out as what the Android 4.4.4 Release 2.0.1 tag points to. This CL adds a new protoc binary (for compiling protos) that supports this, and also adds a Java library with the runtime. To simplify use of this, it also updates build/protoc_java.gypi to support generating nano protos by specifying an optional proto_runtime argument. The argument defaults to 'lite' which does the same thing as before this change, and setting it to 'nano' generates the new style Java files. The plan is to quickly deprecate the 'lite' runtime for Java, since it is too big and uses too many methods. TBR=darin@chromium.org,cjhopman@chromium.org BUG=377891,410067 Review URL: https://codereview.chromium.org/532303003 Cr-Commit-Position: refs/heads/master@{#293236}
-rw-r--r--.gitignore1
-rw-r--r--DEPS3
-rw-r--r--build/protoc_java.gypi30
-rwxr-xr-xbuild/protoc_java.py34
-rw-r--r--third_party/android_protobuf/OWNERS2
-rw-r--r--third_party/android_protobuf/README.chromium29
-rw-r--r--third_party/android_protobuf/android_protobuf.gyp137
7 files changed, 220 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 9d49fe6..2144ec1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -215,6 +215,7 @@ v8.log
/third_party/adobe/flash/binaries
/third_party/adobe/flash/symbols
/third_party/amd/
+/third_party/android_protobuf/src
/third_party/android_tools/
/third_party/android_tools_internal/
/third_party/angle
diff --git a/DEPS b/DEPS
index 6eb9201..f786a16 100644
--- a/DEPS
+++ b/DEPS
@@ -465,6 +465,9 @@ deps_os = {
Var('chromium_git') + '/external/fontconfig.git' + '@' + 'f16c3118e25546c1b749f9823c51827a60aeb5c1',
},
'android': {
+ 'src/third_party/android_protobuf/src':
+ Var('chromium_git') + '/external/android_protobuf.git' + '@' + '48ee66d295979372ed0234cefda42385daae8312',
+
'src/third_party/android_tools':
Var('chromium_git') + '/android_tools.git' + '@' + '31869996507de16812bb53a3d0aaa15cd6194c16',
diff --git a/build/protoc_java.gypi b/build/protoc_java.gypi
index a99ec6a..853760c 100644
--- a/build/protoc_java.gypi
+++ b/build/protoc_java.gypi
@@ -23,6 +23,9 @@
# The 'proto_in_dir' variable must be the relative path to the
# directory containing the .proto files. If left out, it defaults to '.'.
#
+# You can optionally set a variable 'proto_runtime' to either 'lite' or 'nano'.
+# The default runtime is 'lite'.
+#
# The 'output_java_files' variable specifies a list of output files that will
# be generated. It is based on the package and java_outer_classname fields in
# the proto. All the values must be prefixed with >(java_out_dir), since that
@@ -38,7 +41,7 @@
{
'variables': {
- 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
+ 'proto_runtime%': 'lite',
'java_out_dir': '<(PRODUCT_DIR)/java_proto/<(_target_name)/src',
'proto_in_dir%': '.',
'stamp_file': '<(java_out_dir).stamp',
@@ -68,15 +71,32 @@
'<(protoc)',
'<(proto_in_dir)',
'<(java_out_dir)',
+ '<(proto_runtime)',
'<(stamp_file)',
'<@(_sources)',
],
- 'message': 'Generating Java code from <(proto_in_dir)',
+ 'message': 'Generating <(proto_runtime) Java code from protobuf files in <(proto_in_dir)',
},
],
- 'dependencies': [
- '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
- '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite_javalib',
+ 'conditions': [
+ ['proto_runtime=="lite"', {
+ 'variables': {
+ 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
+ },
+ 'dependencies': [
+ '<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host',
+ '<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite_javalib',
+ ],
+ }],
+ ['proto_runtime=="nano"', {
+ 'variables': {
+ 'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)android_protoc<(EXECUTABLE_SUFFIX)',
+ },
+ 'dependencies': [
+ '<(DEPTH)/third_party/android_protobuf/android_protobuf.gyp:android_protoc#host',
+ '<(DEPTH)/third_party/android_protobuf/android_protobuf.gyp:protobuf_nano_javalib',
+ ],
+ }],
],
'includes': [ 'java.gypi' ],
}
diff --git a/build/protoc_java.py b/build/protoc_java.py
index 42e2044..3ccbaa7 100755
--- a/build/protoc_java.py
+++ b/build/protoc_java.py
@@ -3,10 +3,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Generate java source files from protobufs
+"""Generate java source files from protobuf files.
Usage:
- protoc_java.py {protoc} {proto_path} {java_out} {stamp_file} {proto_files}
+ protoc_java.py {protoc} {proto_path} {java_out} {proto_runtime} \
+ {stamp_file} {proto_files}
This is a helper file for the genproto_java action in protoc_java.gypi.
@@ -15,6 +16,8 @@ It performs the following steps:
2. Creates source directory.
3. Generates Java files using protoc.
4. Creates a new stamp file.
+
+proto_runtime must be one of 'nano' and 'lite'.
"""
import os
@@ -23,27 +26,36 @@ import subprocess
import sys
def main(argv):
- if len(argv) < 5:
+ if len(argv) < 6:
usage()
return 1
- protoc_path, proto_path, java_out, stamp_file = argv[1:5]
- proto_files = argv[5:]
+ protoc_path, proto_path, java_out, proto_runtime, stamp_file = argv[1:6]
+ proto_files = argv[6:]
- # Delete all old sources
+ # Delete all old sources.
if os.path.exists(java_out):
shutil.rmtree(java_out)
- # Create source directory
+ # Create source directory.
os.makedirs(java_out)
- # Generate Java files using protoc
+ # Figure out which runtime to use.
+ if proto_runtime == 'nano':
+ out_arg = '--javanano_out=optional_field_style=reftypes,' + \
+ 'store_unknown_fields=true:' + java_out
+ elif proto_runtime == 'lite':
+ out_arg = '--java_out=' + java_out
+ else:
+ usage()
+ return 1
+
+ # Generate Java files using protoc.
ret = subprocess.call(
- [protoc_path, '--proto_path', proto_path, '--java_out', java_out]
- + proto_files)
+ [protoc_path, '--proto_path', proto_path, out_arg] + proto_files)
if ret == 0:
- # Create a new stamp file
+ # Create a new stamp file.
with file(stamp_file, 'a'):
os.utime(stamp_file, None)
diff --git a/third_party/android_protobuf/OWNERS b/third_party/android_protobuf/OWNERS
new file mode 100644
index 0000000..a612398
--- /dev/null
+++ b/third_party/android_protobuf/OWNERS
@@ -0,0 +1,2 @@
+cjhopman@chromium.org
+nyquist@chromium.org
diff --git a/third_party/android_protobuf/README.chromium b/third_party/android_protobuf/README.chromium
new file mode 100644
index 0000000..fec1d3a
--- /dev/null
+++ b/third_party/android_protobuf/README.chromium
@@ -0,0 +1,29 @@
+Name: Protocol Buffers - Google's data interchange format
+Short Name: protobuf
+URL: https://android.googlesource.com/platform/external/protobuf.git
+Version: 2.2.0a
+Revision: Android 4.4.4 Release 2.0.1
+License: BSD
+License File: src/COPYING.txt
+Security Critical: no
+
+Name:
+Shortname: protobuf
+URL: https://android.googlesource.com/platform/external/protobuf.git
+License: Google BSD like
+License File: src/COPYING
+Security Critical: no
+
+Description:
+Android protobuf library contains the nano version of the Java protobuf library,
+which generates Java-files with fewer methods than the protobuf lite compiler,
+which is needed for big Java projects since Android has a maximum number of
+methods per application.
+
+The 'android_protoc' target file list is taken from COMPILER_SRC_FILES in
+src/Android.mk.
+
+See //third_party/protobuf for the C++ version of protobuf.
+
+Local Modifications:
+None.
diff --git a/third_party/android_protobuf/android_protobuf.gyp b/third_party/android_protobuf/android_protobuf.gyp
new file mode 100644
index 0000000..65c7656
--- /dev/null
+++ b/third_party/android_protobuf/android_protobuf.gyp
@@ -0,0 +1,137 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'conditions': [
+ ['OS=="android"', {
+ 'targets': [
+ {
+ 'target_name': 'protobuf_nano_javalib',
+ 'type' : 'none',
+ 'variables': {
+ # Using empty dir and additionalk_src_dirs since the nano package
+ # does not have a src/ subfolder.
+ 'java_in_dir': '../../build/android/empty',
+ 'additional_src_dirs': [ 'src/java/src/main/java/com/google/protobuf/nano' ],
+ },
+ 'includes': [ '../../build/java.gypi' ],
+ },
+ {
+ # This proto compiler supports the nano profile, but should only be used for Android.
+ 'target_name': 'android_protoc',
+ 'type': 'executable',
+ 'variables': {
+ 'chromium_code': 0,
+ },
+ 'toolsets': [ 'host' ],
+ 'sources': [
+ 'src/src/google/protobuf/descriptor.cc',
+ 'src/src/google/protobuf/descriptor.pb.cc',
+ 'src/src/google/protobuf/descriptor_database.cc',
+ 'src/src/google/protobuf/dynamic_message.cc',
+ 'src/src/google/protobuf/extension_set.cc',
+ 'src/src/google/protobuf/extension_set_heavy.cc',
+ 'src/src/google/protobuf/generated_message_reflection.cc',
+ 'src/src/google/protobuf/generated_message_util.cc',
+ 'src/src/google/protobuf/message.cc',
+ 'src/src/google/protobuf/message_lite.cc',
+ 'src/src/google/protobuf/reflection_ops.cc',
+ 'src/src/google/protobuf/repeated_field.cc',
+ 'src/src/google/protobuf/service.cc',
+ 'src/src/google/protobuf/text_format.cc',
+ 'src/src/google/protobuf/unknown_field_set.cc',
+ 'src/src/google/protobuf/wire_format.cc',
+ 'src/src/google/protobuf/wire_format_lite.cc',
+ 'src/src/google/protobuf/compiler/code_generator.cc',
+ 'src/src/google/protobuf/compiler/command_line_interface.cc',
+ 'src/src/google/protobuf/compiler/importer.cc',
+ 'src/src/google/protobuf/compiler/main.cc',
+ 'src/src/google/protobuf/compiler/parser.cc',
+ 'src/src/google/protobuf/compiler/plugin.cc',
+ 'src/src/google/protobuf/compiler/plugin.pb.cc',
+ 'src/src/google/protobuf/compiler/subprocess.cc',
+ 'src/src/google/protobuf/compiler/zip_writer.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_enum.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_enum_field.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_extension.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_field.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_file.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_generator.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_helpers.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_message.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_message_field.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_service.cc',
+ 'src/src/google/protobuf/compiler/cpp/cpp_string_field.cc',
+ 'src/src/google/protobuf/compiler/java/java_enum.cc',
+ 'src/src/google/protobuf/compiler/java/java_enum_field.cc',
+ 'src/src/google/protobuf/compiler/java/java_extension.cc',
+ 'src/src/google/protobuf/compiler/java/java_field.cc',
+ 'src/src/google/protobuf/compiler/java/java_file.cc',
+ 'src/src/google/protobuf/compiler/java/java_generator.cc',
+ 'src/src/google/protobuf/compiler/java/java_helpers.cc',
+ 'src/src/google/protobuf/compiler/java/java_message.cc',
+ 'src/src/google/protobuf/compiler/java/java_message_field.cc',
+ 'src/src/google/protobuf/compiler/java/java_primitive_field.cc',
+ 'src/src/google/protobuf/compiler/java/java_service.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_enum.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_enum_field.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_field.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_file.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_generator.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_helpers.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_message.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_message_field.cc',
+ 'src/src/google/protobuf/compiler/javamicro/javamicro_primitive_field.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_enum.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_enum_field.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_extension.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_field.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_file.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_generator.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_helpers.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_message.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_message_field.cc',
+ 'src/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc',
+ 'src/src/google/protobuf/compiler/python/python_generator.cc',
+ 'src/src/google/protobuf/io/coded_stream.cc',
+ 'src/src/google/protobuf/io/gzip_stream.cc',
+ 'src/src/google/protobuf/io/printer.cc',
+ 'src/src/google/protobuf/io/tokenizer.cc',
+ 'src/src/google/protobuf/io/zero_copy_stream.cc',
+ 'src/src/google/protobuf/io/zero_copy_stream_impl.cc',
+ 'src/src/google/protobuf/io/zero_copy_stream_impl_lite.cc',
+ 'src/src/google/protobuf/stubs/common.cc',
+ 'src/src/google/protobuf/stubs/hash.cc',
+ 'src/src/google/protobuf/stubs/once.cc',
+ 'src/src/google/protobuf/stubs/structurally_valid.cc',
+ 'src/src/google/protobuf/stubs/strutil.cc',
+ 'src/src/google/protobuf/stubs/substitute.cc',
+ ],
+ 'include_dirs': [
+ 'src/android',
+ 'src/src',
+ ],
+ 'conditions': [
+ ['clang==1', {
+ 'cflags': [
+ '-Wno-null-conversion',
+ '-Wno-tautological-undefined-compare',
+ ],
+ }],
+ ],
+ 'defines': [
+ # This macro must be defined to suppress the use
+ # of dynamic_cast<>, which requires RTTI.
+ 'GOOGLE_PROTOBUF_NO_RTTI',
+ 'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER',
+ ],
+ 'dependencies': [
+ '../zlib/zlib.gyp:zlib',
+ ],
+ },
+ ],
+ }],
+ ],
+}