summaryrefslogtreecommitdiff
path: root/chromium/build/protoc_java.py
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@theqtcompany.com>2014-12-05 15:04:29 +0100
committerAndras Becsi <andras.becsi@theqtcompany.com>2014-12-09 10:49:28 +0100
commitaf6588f8d723931a298c995fa97259bb7f7deb55 (patch)
tree060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/build/protoc_java.py
parent2fff84d821cc7b1c785f6404e0f8091333283e74 (diff)
downloadqtwebengine-chromium-af6588f8d723931a298c995fa97259bb7f7deb55.tar.gz
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/build/protoc_java.py')
-rwxr-xr-xchromium/build/protoc_java.py70
1 files changed, 41 insertions, 29 deletions
diff --git a/chromium/build/protoc_java.py b/chromium/build/protoc_java.py
index 42e204464ac..470667c1f4b 100755
--- a/chromium/build/protoc_java.py
+++ b/chromium/build/protoc_java.py
@@ -3,54 +3,66 @@
# 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
-
-Usage:
- protoc_java.py {protoc} {proto_path} {java_out} {stamp_file} {proto_files}
+"""Generate java source files from protobuf files.
This is a helper file for the genproto_java action in protoc_java.gypi.
It performs the following steps:
1. Deletes all old sources (ensures deleted classes are not part of new jars).
2. Creates source directory.
-3. Generates Java files using protoc.
+3. Generates Java files using protoc (output into either --java-out-dir or
+ --srcjar).
4. Creates a new stamp file.
"""
import os
+import optparse
import shutil
import subprocess
import sys
-def main(argv):
- if len(argv) < 5:
- usage()
- return 1
-
- protoc_path, proto_path, java_out, stamp_file = argv[1:5]
- proto_files = argv[5:]
+sys.path.append(os.path.join(os.path.dirname(__file__), "android", "gyp"))
+from util import build_utils
- # Delete all old sources
- if os.path.exists(java_out):
- shutil.rmtree(java_out)
+def main(argv):
+ parser = optparse.OptionParser()
+ build_utils.AddDepfileOption(parser)
+ parser.add_option("--protoc", help="Path to protoc binary.")
+ parser.add_option("--proto-path", help="Path to proto directory.")
+ parser.add_option("--java-out-dir",
+ 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.")
+ options, args = parser.parse_args(argv)
- # Create source directory
- os.makedirs(java_out)
+ build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
+ if not options.java_out_dir and not options.srcjar:
+ print 'One of --java-out-dir or --srcjar must be specified.'
+ return 1
- # Generate Java files using protoc
- ret = subprocess.call(
- [protoc_path, '--proto_path', proto_path, '--java_out', java_out]
- + proto_files)
+ with build_utils.TempDir() as temp_dir:
+ # 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]
+ + args)
- if ret == 0:
- # Create a new stamp file
- with file(stamp_file, 'a'):
- os.utime(stamp_file, None)
+ if options.java_out_dir:
+ build_utils.DeleteDirectory(options.java_out_dir)
+ shutil.copytree(temp_dir, options.java_out_dir)
+ else:
+ build_utils.ZipDir(options.srcjar, temp_dir)
- return ret
+ if options.depfile:
+ build_utils.WriteDepfile(
+ options.depfile,
+ args + [options.protoc] + build_utils.GetPythonDependencies())
-def usage():
- print(__doc__);
+ if options.stamp:
+ build_utils.Touch(options.stamp)
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main(sys.argv[1:]))