summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/android/gyp/jetify_jar.py
blob: e97ad97d99ed0bdd2564f626b2e48bb8e048caac (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
68
#!/usr/bin/env python3
#
# Copyright 2019 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.

from __future__ import print_function

import argparse
import os
import subprocess
import sys

from util import build_utils


def _AddArguments(parser):
  """Adds arguments related to jetifying to parser.

  Args:
    parser: ArgumentParser object.
  """
  parser.add_argument(
      '--input-path',
      required=True,
      help='Path to input file(s). Either the classes '
      'directory, or the path to a jar.')
  parser.add_argument(
      '--output-path',
      required=True,
      help='Path to output final file(s) to. Either the '
      'final classes directory, or the directory in '
      'which to place the instrumented/copied jar.')
  parser.add_argument(
      '--jetify-path', required=True, help='Path to jetify bin.')
  parser.add_argument(
      '--jetify-config-path', required=True, help='Path to jetify config file.')


def _RunJetifyCommand(parser):
  args = parser.parse_args()
  cmd = [
      args.jetify_path,
      '-i',
      args.input_path,
      '-o',
      args.output_path,
      # Need to suppress a lot of warning output when jar doesn't have
      # any references rewritten.
      '-l',
      'error'
  ]
  if args.jetify_config_path:
    cmd.extend(['-c', args.jetify_config_path])
  # Must wait for jetify command to complete to prevent race condition.
  env = os.environ.copy()
  env['JAVA_HOME'] = build_utils.JAVA_HOME
  subprocess.check_call(cmd, env=env)


def main():
  parser = argparse.ArgumentParser()
  _AddArguments(parser)
  _RunJetifyCommand(parser)


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