summaryrefslogtreecommitdiffstats
path: root/build/android/gyp/proguard.py
blob: b27365b7fc1607b78c23a261b9e5c2e88ec7e3e2 (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
#!/usr/bin/env python
#
# Copyright 2013 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 optparse
import os
import sys

from util import build_utils

def DoProguard(options):
  injars = options.input_path
  outjars = options.output_path
  classpath = build_utils.ParseGypList(options.classpath)
  classpath = list(set(classpath))
  libraryjars = ':'.join(classpath)
  # proguard does its own dependency checking, which can be avoided by deleting
  # the output.
  if os.path.exists(options.output_path):
    os.remove(options.output_path)
  proguard_cmd = ['java', '-jar',
                  options.proguard_path,
                  '-injars', injars,
                  '-outjars', outjars,
                  '-libraryjars', libraryjars,
                  '@' + options.proguard_config]
  build_utils.CheckOutput(proguard_cmd, print_stdout=True)


def main():
  parser = optparse.OptionParser()
  parser.add_option('--proguard-path',
                    help='Path to the proguard executable.')
  parser.add_option('--input-path',
                    help='Path to the .jar file proguard should run on.')
  parser.add_option('--output-path', help='Path to the generated .jar file.')
  parser.add_option('--proguard-config',
                    help='Path to the proguard configuration file.')
  parser.add_option('--classpath', help="Classpath for proguard.")
  parser.add_option('--stamp', help='Path to touch on success.')

  options, _ = parser.parse_args()

  DoProguard(options)

  if options.stamp:
    build_utils.Touch(options.stamp)


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