Commit a076bf3d authored by nyquist's avatar nyquist Committed by Commit bot

Add support for Java nano protocol buffers for Android.

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.

BUG=377891

Review URL: https://codereview.chromium.org/511283003

Cr-Commit-Position: refs/heads/master@{#292965}
parent 31113096
...@@ -215,6 +215,7 @@ v8.log ...@@ -215,6 +215,7 @@ v8.log
/third_party/adobe/flash/binaries /third_party/adobe/flash/binaries
/third_party/adobe/flash/symbols /third_party/adobe/flash/symbols
/third_party/amd/ /third_party/amd/
/third_party/android_protobuf/src
/third_party/android_tools/ /third_party/android_tools/
/third_party/android_tools_internal/ /third_party/android_tools_internal/
/third_party/angle /third_party/angle
......
...@@ -465,6 +465,9 @@ deps_os = { ...@@ -465,6 +465,9 @@ deps_os = {
Var('chromium_git') + '/external/fontconfig.git' + '@' + 'f16c3118e25546c1b749f9823c51827a60aeb5c1', Var('chromium_git') + '/external/fontconfig.git' + '@' + 'f16c3118e25546c1b749f9823c51827a60aeb5c1',
}, },
'android': { 'android': {
'src/third_party/android_protobuf/src':
'https://android.googlesource.com/platform/external/protobuf.git' + '@' + '48ee66d295979372ed0234cefda42385daae8312',
'src/third_party/android_tools': 'src/third_party/android_tools':
Var('chromium_git') + '/android_tools.git' + '@' + '31869996507de16812bb53a3d0aaa15cd6194c16', Var('chromium_git') + '/android_tools.git' + '@' + '31869996507de16812bb53a3d0aaa15cd6194c16',
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
# The 'proto_in_dir' variable must be the relative path to the # The 'proto_in_dir' variable must be the relative path to the
# directory containing the .proto files. If left out, it defaults to '.'. # 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 # 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 # 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 # the proto. All the values must be prefixed with >(java_out_dir), since that
...@@ -38,7 +41,7 @@ ...@@ -38,7 +41,7 @@
{ {
'variables': { 'variables': {
'protoc': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)', 'proto_runtime%': 'lite',
'java_out_dir': '<(PRODUCT_DIR)/java_proto/<(_target_name)/src', 'java_out_dir': '<(PRODUCT_DIR)/java_proto/<(_target_name)/src',
'proto_in_dir%': '.', 'proto_in_dir%': '.',
'stamp_file': '<(java_out_dir).stamp', 'stamp_file': '<(java_out_dir).stamp',
...@@ -68,15 +71,32 @@ ...@@ -68,15 +71,32 @@
'<(protoc)', '<(protoc)',
'<(proto_in_dir)', '<(proto_in_dir)',
'<(java_out_dir)', '<(java_out_dir)',
'<(proto_runtime)',
'<(stamp_file)', '<(stamp_file)',
'<@(_sources)', '<@(_sources)',
], ],
'message': 'Generating Java code from <(proto_in_dir)', 'message': 'Generating <(proto_runtime) Java code from protobuf files in <(proto_in_dir)',
}, },
], ],
'dependencies': [ 'conditions': [
'<(DEPTH)/third_party/protobuf/protobuf.gyp:protoc#host', ['proto_runtime=="lite"', {
'<(DEPTH)/third_party/protobuf/protobuf.gyp:protobuf_lite_javalib', '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' ], 'includes': [ 'java.gypi' ],
} }
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Generate java source files from protobufs """Generate java source files from protobuf files.
Usage: 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. This is a helper file for the genproto_java action in protoc_java.gypi.
...@@ -15,6 +16,8 @@ It performs the following steps: ...@@ -15,6 +16,8 @@ It performs the following steps:
2. Creates source directory. 2. Creates source directory.
3. Generates Java files using protoc. 3. Generates Java files using protoc.
4. Creates a new stamp file. 4. Creates a new stamp file.
proto_runtime must be one of 'nano' and 'lite'.
""" """
import os import os
...@@ -23,27 +26,36 @@ import subprocess ...@@ -23,27 +26,36 @@ import subprocess
import sys import sys
def main(argv): def main(argv):
if len(argv) < 5: if len(argv) < 6:
usage() usage()
return 1 return 1
protoc_path, proto_path, java_out, stamp_file = argv[1:5] protoc_path, proto_path, java_out, proto_runtime, stamp_file = argv[1:6]
proto_files = argv[5:] proto_files = argv[6:]
# Delete all old sources # Delete all old sources.
if os.path.exists(java_out): if os.path.exists(java_out):
shutil.rmtree(java_out) shutil.rmtree(java_out)
# Create source directory # Create source directory.
os.makedirs(java_out) 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( ret = subprocess.call(
[protoc_path, '--proto_path', proto_path, '--java_out', java_out] [protoc_path, '--proto_path', proto_path, out_arg] + proto_files)
+ proto_files)
if ret == 0: if ret == 0:
# Create a new stamp file # Create a new stamp file.
with file(stamp_file, 'a'): with file(stamp_file, 'a'):
os.utime(stamp_file, None) os.utime(stamp_file, None)
......
cjhopman@chromium.org
nyquist@chromium.org
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.
# 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',
],
},
],
}],
],
}
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