xref: /aosp_15_r20/external/cronet/build/android/gyp/flatc_java.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
7This is the action script for the flatbuffer_java_library template.
8"""
9
10import argparse
11import sys
12
13from util import build_utils
14import action_helpers
15import zip_helpers
16
17
18def 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
41if __name__ == '__main__':
42  sys.exit(main(sys.argv[1:]))
43