Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: build/android/gyp/util/proguard_util.py

Issue 1565433002: Fix up proguard output filtering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: non-capturing groups Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gyp/proguard.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import re
6 from util import build_utils 7 from util import build_utils
7 8
8 def FilterProguardOutput(output): 9
9 '''ProGuard outputs boring stuff to stdout (proguard version, jar path, etc) 10 class _ProguardOutputFilter(object):
11 """ProGuard outputs boring stuff to stdout (proguard version, jar path, etc)
10 as well as interesting stuff (notes, warnings, etc). If stdout is entirely 12 as well as interesting stuff (notes, warnings, etc). If stdout is entirely
11 boring, this method suppresses the output. 13 boring, this class suppresses the output.
12 ''' 14 """
13 ignore_patterns = [ 15
14 'ProGuard, version ', 16 IGNORE_RE = re.compile(
15 'Reading program jar [', 17 r'(?:Pro.*version|Note:|Reading|Preparing|.*:.*(?:MANIFEST\.MF|\.empty))')
16 'Reading library jar [', 18
17 'Preparing output jar [', 19 def __init__(self):
18 ' Copying resources from program jar [', 20 self._last_line_ignored = False
19 ] 21
20 for line in output.splitlines(): 22 def __call__(self, output):
21 for pattern in ignore_patterns: 23 ret = []
22 if line.startswith(pattern): 24 for line in output.splitlines(True):
23 break 25 if not line.startswith(' '):
24 else: 26 self._last_line_ignored = bool(self.IGNORE_RE.match(line))
25 # line doesn't match any of the patterns; it's probably something worth 27 elif 'You should check if you need to specify' in line:
26 # printing out. 28 self._last_line_ignored = True
27 return output 29
28 return '' 30 if not self._last_line_ignored:
Nico 2016/01/05 22:22:21 Ooh I see, I was misreading this.
31 ret.append(line)
32 return ''.join(ret)
29 33
30 34
31 class ProguardCmdBuilder(object): 35 class ProguardCmdBuilder(object):
32 def __init__(self, proguard_jar): 36 def __init__(self, proguard_jar):
33 assert os.path.exists(proguard_jar) 37 assert os.path.exists(proguard_jar)
34 self._proguard_jar_path = proguard_jar 38 self._proguard_jar_path = proguard_jar
35 self._tested_apk_info_path = None 39 self._tested_apk_info_path = None
36 self._tested_apk_info = None 40 self._tested_apk_info = None
37 self._mapping = None 41 self._mapping = None
38 self._libraries = None 42 self._libraries = None
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 inputs = [self._proguard_jar_path] + self._configs + self._injars 142 inputs = [self._proguard_jar_path] + self._configs + self._injars
139 if self._mapping: 143 if self._mapping:
140 inputs.append(self._mapping) 144 inputs.append(self._mapping)
141 if self._libraries: 145 if self._libraries:
142 inputs += self._libraries 146 inputs += self._libraries
143 if self._tested_apk_info_path: 147 if self._tested_apk_info_path:
144 inputs += [self._tested_apk_info_path] 148 inputs += [self._tested_apk_info_path]
145 return inputs 149 return inputs
146 150
147 151
148 def CheckOutput(self): 152 def CheckOutput(self, verbose=False):
149 self.build() 153 self.build()
150 # Proguard will skip writing these files if they would be empty. Create 154 # Proguard will skip writing these files if they would be empty. Create
151 # empty versions of them all now so that they are updated as the build 155 # empty versions of them all now so that they are updated as the build
152 # expects. 156 # expects.
153 open(self._outjar + '.dump', 'w').close() 157 open(self._outjar + '.dump', 'w').close()
154 open(self._outjar + '.seeds', 'w').close() 158 open(self._outjar + '.seeds', 'w').close()
155 open(self._outjar + '.usage', 'w').close() 159 open(self._outjar + '.usage', 'w').close()
156 open(self._outjar + '.mapping', 'w').close() 160 open(self._outjar + '.mapping', 'w').close()
161 # Warning: and Error: are sent to stderr, but messages and Note: are sent
162 # to stdout.
163 stdout_filter = None
164 stderr_filter = None
165 if not verbose:
166 stdout_filter = _ProguardOutputFilter()
167 stderr_filter = _ProguardOutputFilter()
157 build_utils.CheckOutput(self._cmd, print_stdout=True, 168 build_utils.CheckOutput(self._cmd, print_stdout=True,
158 stdout_filter=FilterProguardOutput) 169 print_stderr=True,
170 stdout_filter=stdout_filter,
171 stderr_filter=stderr_filter)
159 172
160 this_info = { 173 this_info = {
161 'inputs': self._injars, 174 'inputs': self._injars,
162 'configs': self._configs, 175 'configs': self._configs,
163 'mapping': self._outjar + '.mapping', 176 'mapping': self._outjar + '.mapping',
164 } 177 }
165 178
166 build_utils.WriteJson(this_info, self._outjar + '.info') 179 build_utils.WriteJson(this_info, self._outjar + '.info')
167 180
OLDNEW
« no previous file with comments | « build/android/gyp/proguard.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698