| OLD | NEW | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 """Generate java source files from protobufs | 6 """Generate java source files from protobuf files. | 
| 7 | 7 | 
| 8 Usage: | 8 Usage: | 
| 9     protoc_java.py {protoc} {proto_path} {java_out} {stamp_file} {proto_files} | 9     protoc_java.py {protoc} {proto_path} {java_out} {proto_runtime} \ | 
|  | 10         {stamp_file} {proto_files} | 
| 10 | 11 | 
| 11 This is a helper file for the genproto_java action in protoc_java.gypi. | 12 This is a helper file for the genproto_java action in protoc_java.gypi. | 
| 12 | 13 | 
| 13 It performs the following steps: | 14 It performs the following steps: | 
| 14 1. Deletes all old sources (ensures deleted classes are not part of new jars). | 15 1. Deletes all old sources (ensures deleted classes are not part of new jars). | 
| 15 2. Creates source directory. | 16 2. Creates source directory. | 
| 16 3. Generates Java files using protoc. | 17 3. Generates Java files using protoc. | 
| 17 4. Creates a new stamp file. | 18 4. Creates a new stamp file. | 
|  | 19 | 
|  | 20 proto_runtime must be one of 'nano' and 'lite'. | 
| 18 """ | 21 """ | 
| 19 | 22 | 
| 20 import os | 23 import os | 
| 21 import shutil | 24 import shutil | 
| 22 import subprocess | 25 import subprocess | 
| 23 import sys | 26 import sys | 
| 24 | 27 | 
| 25 def main(argv): | 28 def main(argv): | 
| 26   if len(argv) < 5: | 29   if len(argv) < 6: | 
| 27     usage() | 30     usage() | 
| 28     return 1 | 31     return 1 | 
| 29 | 32 | 
| 30   protoc_path, proto_path, java_out, stamp_file = argv[1:5] | 33   protoc_path, proto_path, java_out, proto_runtime, stamp_file = argv[1:6] | 
| 31   proto_files = argv[5:] | 34   proto_files = argv[6:] | 
| 32 | 35 | 
| 33   # Delete all old sources | 36   # Delete all old sources. | 
| 34   if os.path.exists(java_out): | 37   if os.path.exists(java_out): | 
| 35     shutil.rmtree(java_out) | 38     shutil.rmtree(java_out) | 
| 36 | 39 | 
| 37   # Create source directory | 40   # Create source directory. | 
| 38   os.makedirs(java_out) | 41   os.makedirs(java_out) | 
| 39 | 42 | 
| 40   # Generate Java files using protoc | 43   # Figure out which runtime to use. | 
|  | 44   if proto_runtime == 'nano': | 
|  | 45     out_arg = '--javanano_out=optional_field_style=reftypes,' + \ | 
|  | 46         'store_unknown_fields=true:' + java_out | 
|  | 47   elif proto_runtime == 'lite': | 
|  | 48     out_arg = '--java_out=' + java_out | 
|  | 49   else: | 
|  | 50     usage() | 
|  | 51     return 1 | 
|  | 52 | 
|  | 53   # Generate Java files using protoc. | 
| 41   ret = subprocess.call( | 54   ret = subprocess.call( | 
| 42       [protoc_path, '--proto_path', proto_path, '--java_out', java_out] | 55       [protoc_path, '--proto_path', proto_path, out_arg] + proto_files) | 
| 43       + proto_files) |  | 
| 44 | 56 | 
| 45   if ret == 0: | 57   if ret == 0: | 
| 46     # Create a new stamp file | 58     # Create a new stamp file. | 
| 47     with file(stamp_file, 'a'): | 59     with file(stamp_file, 'a'): | 
| 48       os.utime(stamp_file, None) | 60       os.utime(stamp_file, None) | 
| 49 | 61 | 
| 50   return ret | 62   return ret | 
| 51 | 63 | 
| 52 def usage(): | 64 def usage(): | 
| 53   print(__doc__); | 65   print(__doc__); | 
| 54 | 66 | 
| 55 if __name__ == '__main__': | 67 if __name__ == '__main__': | 
| 56   sys.exit(main(sys.argv)) | 68   sys.exit(main(sys.argv)) | 
| OLD | NEW | 
|---|