1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 from util
import build_utils
8 def FilterProguardOutput(output
):
9 '''ProGuard outputs boring stuff to stdout (proguard version, jar path, etc)
10 as well as interesting stuff (notes, warnings, etc). If stdout is entirely
11 boring, this method suppresses the output.
15 'Reading program jar [',
16 'Reading library jar [',
17 'Preparing output jar [',
18 ' Copying resources from program jar [',
20 for line
in output
.splitlines():
21 for pattern
in ignore_patterns
:
22 if line
.startswith(pattern
):
25 # line doesn't match any of the patterns; it's probably something worth
31 class ProguardCmdBuilder(object):
32 def __init__(self
, proguard_jar
):
33 assert os
.path
.exists(proguard_jar
)
34 self
._proguard
_jar
_path
= proguard_jar
37 self
._libraries
= None
42 def outjar(self
, path
):
43 assert self
._outjar
is None
46 def is_test(self
, enable
):
47 assert self
._test
is None
50 def mapping(self
, path
):
51 assert self
._mapping
is None
52 assert os
.path
.exists(path
), path
55 def libraryjars(self
, paths
):
56 assert self
._libraries
is None
58 assert os
.path
.exists(p
), p
59 self
._libraries
= paths
61 def injars(self
, paths
):
62 assert self
._injars
is None
64 assert os
.path
.exists(p
), p
67 def configs(self
, paths
):
68 assert self
._configs
is None
70 assert os
.path
.exists(p
), p
74 assert self
._injars
is not None
75 assert self
._outjar
is not None
76 assert self
._configs
is not None
78 'java', '-jar', self
._proguard
_jar
_path
,
86 '-dontskipnonpubliclibraryclassmembers',
91 '-applymapping', self
._mapping
,
96 '-libraryjars', ':'.join(self
._libraries
),
100 '-injars', ':'.join(self
._injars
)
103 for config_file
in self
._configs
:
104 cmd
+= ['-include', config_file
]
106 # The output jar must be specified after inputs.
108 '-outjars', self
._outjar
,
109 '-dump', self
._outjar
+ '.dump',
110 '-printseeds', self
._outjar
+ '.seeds',
111 '-printusage', self
._outjar
+ '.usage',
112 '-printmapping', self
._outjar
+ '.mapping',
117 inputs
= [self
._proguard
_jar
_path
] + self
._configs
+ self
._injars
119 inputs
.append(self
._mapping
)
121 inputs
+= self
._libraries
125 def CheckOutput(self
):
126 build_utils
.CheckOutput(self
.build(), print_stdout
=True,
127 stdout_filter
=FilterProguardOutput
)