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