1 #!/usr/bin/env python 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 4 # found in the LICENSE file. 5 6 """Generate java DescriptorProto file. 7 8 Usage: 9 protobuf_lite_java_descriptor_proto.py {protoc} {java_out} {include} {proto_files} 10 11 This is a helper file for the protobuf_lite_java_gen_descriptor_proto action in 12 protobuf.gyp. 13 14 It performs the following steps: 15 1. Recursively deletes old java_out directory. 16 2. Creates java_out directory. 17 3. Generates Java descriptor proto file using protoc. 18 """ 19 20 import os 21 import shutil 22 import subprocess 23 import sys 24 25 def main(argv): 26 if len(argv) < 4: 27 usage() 28 return 1 29 30 protoc_path, java_out, include = argv[1:4] 31 proto_files = argv[4:] 32 33 # Delete all old sources 34 if os.path.exists(java_out): 35 shutil.rmtree(java_out) 36 37 # Create source directory 38 os.makedirs(java_out) 39 40 # Generate Java files using protoc 41 return subprocess.call( 42 [protoc_path, '--java_out', java_out, '-I' + include] 43 + proto_files) 44 45 def usage(): 46 print(__doc__); 47 48 if __name__ == '__main__': 49 sys.exit(main(sys.argv)) 50