Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / build / android / gyp / proguard.py
blobcb547fb97043a091b41370762830618c8dacc33b
1 #!/usr/bin/env python
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.
7 import optparse
8 import os
9 import sys
11 from util import build_utils
13 def DoProguard(options):
14 injars = options.input_path
15 outjars = options.output_path
16 classpath = []
17 for arg in options.classpath:
18 classpath += build_utils.ParseGypList(arg)
19 classpath = list(set(classpath))
20 libraryjars = ':'.join(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)
35 def FilterProguardOutput(output):
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 [',
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 ''
58 def main(args):
59 args = build_utils.ExpandFileArgs(args)
60 parser = optparse.OptionParser()
61 build_utils.AddDepfileOption(parser)
62 parser.add_option('--proguard-path',
63 help='Path to the proguard executable.')
64 parser.add_option('--input-path',
65 help='Path to the .jar file proguard should run on.')
66 parser.add_option('--output-path', help='Path to the generated .jar file.')
67 parser.add_option('--proguard-config',
68 help='Path to the proguard configuration file.')
69 parser.add_option('--classpath', action='append',
70 help="Classpath for proguard.")
71 parser.add_option('--stamp', help='Path to touch on success.')
73 options, _ = parser.parse_args(args)
75 DoProguard(options)
77 if options.depfile:
78 build_utils.WriteDepfile(
79 options.depfile,
80 build_utils.GetPythonDependencies())
82 if options.stamp:
83 build_utils.Touch(options.stamp)
86 if __name__ == '__main__':
87 sys.exit(main(sys.argv[1:]))