1#!/usr/bin/env python
2#
3# Copyright 2013 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import optparse
8import os
9import sys
10
11from util import build_utils
12from util import proguard_util
13
14
15def _ParseOptions(args):
16  parser = optparse.OptionParser()
17  build_utils.AddDepfileOption(parser)
18  parser.add_option('--proguard-path',
19                    help='Path to the proguard executable.')
20  parser.add_option('--input-paths',
21                    help='Paths to the .jar files proguard should run on.')
22  parser.add_option('--output-path', help='Path to the generated .jar file.')
23  parser.add_option('--proguard-configs',
24                    help='Paths to proguard configuration files.')
25  parser.add_option('--mapping', help='Path to proguard mapping to apply.')
26  parser.add_option('--is-test', action='store_true',
27      help='If true, extra proguard options for instrumentation tests will be '
28      'added.')
29  parser.add_option('--tested-apk-info', help='Path to the proguard .info file '
30      'for the tested apk')
31  parser.add_option('--classpath', action='append',
32                    help='Classpath for proguard.')
33  parser.add_option('--stamp', help='Path to touch on success.')
34  parser.add_option('--verbose', '-v', action='store_true',
35                    help='Print all proguard output')
36
37  options, _ = parser.parse_args(args)
38
39  classpath = []
40  for arg in options.classpath:
41    classpath += build_utils.ParseGypList(arg)
42  options.classpath = classpath
43
44  return options
45
46
47def main(args):
48  args = build_utils.ExpandFileArgs(args)
49  options = _ParseOptions(args)
50
51  proguard = proguard_util.ProguardCmdBuilder(options.proguard_path)
52  proguard.injars(build_utils.ParseGypList(options.input_paths))
53  proguard.configs(build_utils.ParseGypList(options.proguard_configs))
54  proguard.outjar(options.output_path)
55
56  if options.mapping:
57    proguard.mapping(options.mapping)
58
59  if options.tested_apk_info:
60    proguard.tested_apk_info(options.tested_apk_info)
61
62  classpath = list(set(options.classpath))
63  proguard.libraryjars(classpath)
64  proguard.verbose(options.verbose)
65
66  input_paths = proguard.GetInputs()
67
68  build_utils.CallAndWriteDepfileIfStale(
69      proguard.CheckOutput,
70      options,
71      input_paths=input_paths,
72      input_strings=proguard.build(),
73      output_paths=[options.output_path])
74
75
76if __name__ == '__main__':
77  sys.exit(main(sys.argv[1:]))
78