flatc_java.py (1299B)
1 #!/usr/bin/env python3 2 # Copyright 2021 The Chromium Authors 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 """Generate java source files from flatbuffer files. 6 7 This is the action script for the flatbuffer_java_library template. 8 """ 9 10 import argparse 11 import sys 12 13 from util import build_utils 14 import action_helpers 15 import zip_helpers 16 17 18 def main(argv): 19 parser = argparse.ArgumentParser() 20 parser.add_argument('--flatc', required=True, help='Path to flatc binary.') 21 parser.add_argument('--srcjar', required=True, help='Path to output srcjar.') 22 parser.add_argument( 23 '--import-dir', 24 action='append', 25 default=[], 26 help='Extra import directory for flatbuffers, can be repeated.') 27 parser.add_argument('flatbuffers', nargs='+', help='flatbuffer source files') 28 options = parser.parse_args(argv) 29 30 import_args = [] 31 for path in options.import_dir: 32 import_args += ['-I', path] 33 with build_utils.TempDir() as temp_dir: 34 build_utils.CheckOutput([options.flatc, '-j', '-o', temp_dir] + 35 import_args + options.flatbuffers) 36 37 with action_helpers.atomic_output(options.srcjar) as f: 38 zip_helpers.zip_directory(f, temp_dir) 39 40 41 if __name__ == '__main__': 42 sys.exit(main(sys.argv[1:]))