diff options
author | nyquist <nyquist@chromium.org> | 2014-09-03 17:28:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-04 00:34:47 +0000 |
commit | 38f28ba65426989765f8d070ef5f64b5fbce23fa (patch) | |
tree | a84c79698b71dd20a83b9320afde8f8505c0ece4 /build/protoc_java.py | |
parent | 8ea27e621946a33a7337ef84c2307c3dfa0eb4db (diff) | |
download | chromium_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}
Diffstat (limited to 'build/protoc_java.py')
-rwxr-xr-x | build/protoc_java.py | 34 |
1 files changed, 23 insertions, 11 deletions
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) |