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.
11 from util
import build_utils
13 def DoProguard(options
):
14 injars
= options
.input_path
15 outjars
= options
.output_path
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
23 if os
.path
.exists(options
.output_path
):
24 os
.remove(options
.output_path
)
25 proguard_cmd
= ['java', '-jar',
26 options
.proguard_path
,
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.
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
):
52 # line doesn't match any of the patterns; it's probably something worth
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
)
78 build_utils
.WriteDepfile(
80 build_utils
.GetPythonDependencies())
83 build_utils
.Touch(options
.stamp
)
86 if __name__
== '__main__':
87 sys
.exit(main(sys
.argv
[1:]))