summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/android/gyp/desugar.py
blob: 87eb1590a5f7de666698a7e12534751861c26760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
#
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import argparse
import os
import sys

from util import build_utils


def main():
  args = build_utils.ExpandFileArgs(sys.argv[1:])
  parser = argparse.ArgumentParser()
  build_utils.AddDepfileOption(parser)
  parser.add_argument('--desugar-jar', required=True,
                      help='Path to Desugar.jar.')
  parser.add_argument('--input-jar', required=True,
                      help='Jar input path to include .class files from.')
  parser.add_argument('--output-jar', required=True,
                      help='Jar output path.')
  parser.add_argument('--classpath',
                      action='append',
                      required=True,
                      help='Classpath.')
  parser.add_argument('--bootclasspath', required=True,
                      help='Path to javac bootclasspath interface jar.')
  parser.add_argument('--warnings-as-errors',
                      action='store_true',
                      help='Treat all warnings as errors.')
  options = parser.parse_args(args)

  options.bootclasspath = build_utils.ParseGnList(options.bootclasspath)
  options.classpath = build_utils.ParseGnList(options.classpath)

  cmd = build_utils.JavaCmd(options.warnings_as_errors) + [
      '-jar',
      options.desugar_jar,
      '--input',
      options.input_jar,
      '--output',
      options.output_jar,
      '--generate_base_classes_for_default_methods',
      # Don't include try-with-resources files in every .jar. Instead, they
      # are included via //third_party/bazel/desugar:desugar_runtime_java.
      '--desugar_try_with_resources_omit_runtime_classes',
  ]
  for path in options.bootclasspath:
    cmd += ['--bootclasspath_entry', path]
  for path in options.classpath:
    cmd += ['--classpath_entry', path]
  build_utils.CheckOutput(
      cmd,
      print_stdout=False,
      stderr_filter=build_utils.FilterReflectiveAccessJavaWarnings,
      fail_on_output=options.warnings_as_errors)

  if options.depfile:
    build_utils.WriteDepfile(options.depfile,
                             options.output_jar,
                             inputs=options.bootclasspath + options.classpath)


if __name__ == '__main__':
  sys.exit(main())