OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import optparse | 7 import optparse |
8 import os | |
9 import sys | 8 import sys |
10 | 9 |
11 from util import build_utils | 10 from util import build_utils |
| 11 from util import proguard_util |
12 | 12 |
13 def DoProguard(options): | 13 def DoProguard(options): |
14 injars = options.input_path | 14 proguard = proguard_util.ProguardCmdBuilder(options.proguard_path) |
15 outjars = options.output_path | 15 proguard.injars(build_utils.ParseGypList(options.input_paths)) |
| 16 proguard.configs(build_utils.ParseGypList(options.proguard_configs)) |
| 17 proguard.outjar(options.output_path) |
| 18 |
| 19 if options.mapping: |
| 20 proguard.mapping(options.mapping) |
| 21 |
| 22 if options.is_test: |
| 23 proguard.is_test(True) |
| 24 |
16 classpath = [] | 25 classpath = [] |
17 for arg in options.classpath: | 26 for arg in options.classpath: |
18 classpath += build_utils.ParseGypList(arg) | 27 classpath += build_utils.ParseGypList(arg) |
19 classpath = list(set(classpath)) | 28 classpath = list(set(classpath)) |
20 libraryjars = ':'.join(classpath) | 29 proguard.libraryjars(classpath) |
21 # proguard does its own dependency checking, which can be avoided by deleting | |
22 # the output. | |
23 if os.path.exists(options.output_path): | |
24 os.remove(options.output_path) | |
25 proguard_cmd = ['java', '-jar', | |
26 options.proguard_path, | |
27 '-injars', injars, | |
28 '-outjars', outjars, | |
29 '-libraryjars', libraryjars, | |
30 '@' + options.proguard_config] | |
31 build_utils.CheckOutput(proguard_cmd, print_stdout=True, | |
32 stdout_filter=FilterProguardOutput) | |
33 | 30 |
| 31 proguard.CheckOutput() |
34 | 32 |
35 def FilterProguardOutput(output): | 33 return proguard.GetInputs() |
36 '''ProGuard outputs boring stuff to stdout (proguard version, jar path, etc) | |
37 as well as interesting stuff (notes, warnings, etc). If stdout is entirely | |
38 boring, this method suppresses the output. | |
39 ''' | |
40 ignore_patterns = [ | |
41 'ProGuard, version ', | |
42 'Reading program jar [', | |
43 'Reading library jar [', | |
44 'Preparing output jar [', | |
45 ' Copying resources from program jar [', | |
46 ] | |
47 for line in output.splitlines(): | |
48 for pattern in ignore_patterns: | |
49 if line.startswith(pattern): | |
50 break | |
51 else: | |
52 # line doesn't match any of the patterns; it's probably something worth | |
53 # printing out. | |
54 return output | |
55 return '' | |
56 | 34 |
57 | 35 |
58 def main(args): | 36 def main(args): |
59 args = build_utils.ExpandFileArgs(args) | 37 args = build_utils.ExpandFileArgs(args) |
60 parser = optparse.OptionParser() | 38 parser = optparse.OptionParser() |
61 build_utils.AddDepfileOption(parser) | 39 build_utils.AddDepfileOption(parser) |
62 parser.add_option('--proguard-path', | 40 parser.add_option('--proguard-path', |
63 help='Path to the proguard executable.') | 41 help='Path to the proguard executable.') |
64 parser.add_option('--input-path', | 42 parser.add_option('--input-paths', |
65 help='Path to the .jar file proguard should run on.') | 43 help='Paths to the .jar files proguard should run on.') |
66 parser.add_option('--output-path', help='Path to the generated .jar file.') | 44 parser.add_option('--output-path', help='Path to the generated .jar file.') |
67 parser.add_option('--proguard-config', | 45 parser.add_option('--proguard-configs', |
68 help='Path to the proguard configuration file.') | 46 help='Paths to proguard configuration files.') |
| 47 parser.add_option('--mapping', help='Path to proguard mapping to apply.') |
| 48 parser.add_option('--is-test', action='store_true', |
| 49 help='If true, extra proguard options for instrumentation tests will be ' |
| 50 'added.') |
69 parser.add_option('--classpath', action='append', | 51 parser.add_option('--classpath', action='append', |
70 help="Classpath for proguard.") | 52 help='Classpath for proguard.') |
71 parser.add_option('--stamp', help='Path to touch on success.') | 53 parser.add_option('--stamp', help='Path to touch on success.') |
72 | 54 |
73 options, _ = parser.parse_args(args) | 55 options, _ = parser.parse_args(args) |
74 | 56 |
75 DoProguard(options) | 57 inputs = DoProguard(options) |
76 | 58 |
77 if options.depfile: | 59 if options.depfile: |
78 build_utils.WriteDepfile( | 60 build_utils.WriteDepfile( |
79 options.depfile, | 61 options.depfile, |
80 build_utils.GetPythonDependencies()) | 62 inputs + build_utils.GetPythonDependencies()) |
81 | 63 |
82 if options.stamp: | 64 if options.stamp: |
83 build_utils.Touch(options.stamp) | 65 build_utils.Touch(options.stamp) |
84 | 66 |
85 | 67 |
86 if __name__ == '__main__': | 68 if __name__ == '__main__': |
87 sys.exit(main(sys.argv[1:])) | 69 sys.exit(main(sys.argv[1:])) |
OLD | NEW |