Chromium Code Reviews| Index: build/protoc_java.py |
| diff --git a/build/protoc_java.py b/build/protoc_java.py |
| index 940fd80acf0f7185d757bd91f5314e5deb2c4c95..3dc730421473f9f624cd30c1f6484adff9436db5 100755 |
| --- a/build/protoc_java.py |
| +++ b/build/protoc_java.py |
| @@ -6,7 +6,7 @@ |
| """Generate java source files from protobuf files. |
| Usage: |
| - protoc_java.py {protoc} {proto_path} {java_out} {stamp_file} {proto_files} |
| + protoc_java.py --protoc={protoc} --proto-dir={proto_path} {proto_files} |
|
nyquist
2014/09/22 21:25:16
I think you mean proto-path instead of proto-dir.
cjhopman
2014/09/26 23:39:10
Now that we are using an OptionParser I don't thin
|
| This is a helper file for the genproto_java action in protoc_java.gypi. |
| @@ -18,43 +18,53 @@ It performs the following steps: |
| """ |
| 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) |
| - |
| - # Create source directory. |
| - os.makedirs(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) |
| - # Specify arguments to the generator. |
| - generator_args = ['optional_field_style=reftypes', |
| - 'store_unknown_fields=true'] |
| - out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + 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, out_arg] + 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: |
|
nyquist
2014/09/22 21:25:16
Should depfile be specified as a parser option?
cjhopman
2014/09/26 23:39:10
It's added by AddDepfileOption above
|
| + 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:])) |