Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 import os | |
| 6 from util import build_utils | |
| 7 | |
| 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. | |
| 12 ''' | |
| 13 ignore_patterns = [ | |
| 14 'ProGuard, version ', | |
| 15 'Reading program jar [', | |
| 16 'Reading library jar [', | |
| 17 'Preparing output jar [', | |
| 18 ' Copying resources from program jar [', | |
| 19 ] | |
| 20 for line in output.splitlines(): | |
| 21 for pattern in ignore_patterns: | |
| 22 if line.startswith(pattern): | |
| 23 break | |
| 24 else: | |
| 25 # line doesn't match any of the patterns; it's probably something worth | |
| 26 # printing out. | |
| 27 return output | |
| 28 return '' | |
| 29 | |
|
newt (away)
2015/04/28 04:22:14
Please move the extraneous newline from java_apk.g
cjhopman
2015/05/02 00:41:44
Done.
| |
| 30 class ProguardCmdBuilder(object): | |
| 31 def __init__(self, proguard_jar): | |
| 32 self._proguard_jar_path = proguard_jar | |
| 33 self._test = None | |
| 34 self._mapping = None | |
| 35 self._libraries = None | |
| 36 self._injars = None | |
| 37 self._configs = None | |
| 38 self._outjar = None | |
| 39 | |
| 40 def outjar(self, path): | |
| 41 assert self._outjar is None | |
| 42 self._outjar = path | |
| 43 | |
| 44 def testoptions(self, enable): | |
| 45 assert self._test is None | |
| 46 self._test = enable | |
| 47 | |
| 48 def mapping(self, path): | |
| 49 assert self._mapping is None | |
| 50 assert os.path.exists(path), path | |
| 51 self._mapping = path | |
| 52 | |
| 53 def libraryjars(self, paths): | |
| 54 assert self._libraries is None | |
| 55 for f in paths: | |
|
newt (away)
2015/04/28 04:22:14
why f? why not p?
cjhopman
2015/05/02 00:41:44
Done.
| |
| 56 assert os.path.exists(f), f | |
| 57 self._libraries = paths | |
| 58 | |
| 59 def injars(self, paths): | |
| 60 assert self._injars is None | |
| 61 for f in paths: | |
| 62 assert os.path.exists(f), f | |
| 63 self._injars = paths | |
| 64 | |
| 65 def configs(self, paths): | |
| 66 assert self._configs is None | |
| 67 for f in paths: | |
| 68 assert os.path.exists(f), f | |
| 69 self._configs = paths | |
| 70 | |
| 71 def build(self): | |
| 72 assert os.path.exists(self._proguard_jar_path) | |
|
newt (away)
2015/04/28 04:22:14
why not put this assertion in __init__?
cjhopman
2015/05/02 00:41:45
Done.
| |
| 73 assert self._injars is not None | |
| 74 assert self._outjar is not None | |
| 75 assert self._configs is not None | |
| 76 cmd = [ | |
| 77 'java', '-jar', self._proguard_jar_path, | |
| 78 '-forceprocessing', | |
|
newt (away)
2015/04/28 04:22:14
Previously, proguard.py wasn't using this argument
cjhopman
2015/05/02 00:41:44
Yeah, -forceprocessing just makes proguard skip it
| |
| 79 ] | |
| 80 if self._test: | |
| 81 cmd += [ | |
| 82 '-dontobfuscate', | |
| 83 '-dontoptimize', | |
| 84 '-dontshrink', | |
| 85 '-dontskipnonpubliclibraryclassmembers', | |
| 86 ] | |
| 87 | |
| 88 if self._mapping: | |
| 89 cmd += [ | |
| 90 '-applymapping', self._mapping, | |
| 91 ] | |
| 92 | |
| 93 if self._libraries: | |
| 94 cmd += [ | |
| 95 '-libraryjars', ':'.join(self._libraries), | |
| 96 ] | |
| 97 | |
| 98 cmd += [ | |
| 99 '-injars', ':'.join(self._injars) | |
| 100 ] | |
| 101 | |
| 102 for config_file in self._configs: | |
| 103 cmd += ['-include', config_file] | |
| 104 | |
| 105 # The output jar must be specified after inputs. | |
| 106 cmd += [ | |
| 107 '-outjars', self._outjar, | |
| 108 '-dump', self._outjar + '.dump', | |
| 109 '-printseeds', self._outjar + '.seeds', | |
| 110 '-printusage', self._outjar + '.usage', | |
| 111 '-printmapping', self._outjar + '.mapping', | |
| 112 ] | |
| 113 return cmd | |
| 114 | |
| 115 def GetInputs(self): | |
| 116 inputs = [self._proguard_jar_path] + self._configs + self._injars | |
| 117 if self._mapping: | |
| 118 inputs.append(self._mapping) | |
| 119 if self._libraries: | |
| 120 inputs += self._libraries | |
| 121 return inputs | |
| 122 | |
| 123 | |
| 124 def CheckOutput(self): | |
| 125 build_utils.CheckOutput(self.build(), print_stdout=True, | |
| 126 stdout_filter=FilterProguardOutput) | |
| 127 | |
| OLD | NEW |