| 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 | |
| 30 | |
| 31 class ProguardCmdBuilder(object): | |
| 32 def __init__(self, proguard_jar): | |
| 33 assert os.path.exists(proguard_jar) | |
| 34 self._proguard_jar_path = proguard_jar | |
| 35 self._test = None | |
| 36 self._mapping = None | |
| 37 self._libraries = None | |
| 38 self._injars = None | |
| 39 self._configs = None | |
| 40 self._outjar = None | |
| 41 | |
| 42 def outjar(self, path): | |
| 43 assert self._outjar is None | |
| 44 self._outjar = path | |
| 45 | |
| 46 def is_test(self, enable): | |
| 47 assert self._test is None | |
| 48 self._test = enable | |
| 49 | |
| 50 def mapping(self, path): | |
| 51 assert self._mapping is None | |
| 52 assert os.path.exists(path), path | |
| 53 self._mapping = path | |
| 54 | |
| 55 def libraryjars(self, paths): | |
| 56 assert self._libraries is None | |
| 57 for p in paths: | |
| 58 assert os.path.exists(p), p | |
| 59 self._libraries = paths | |
| 60 | |
| 61 def injars(self, paths): | |
| 62 assert self._injars is None | |
| 63 for p in paths: | |
| 64 assert os.path.exists(p), p | |
| 65 self._injars = paths | |
| 66 | |
| 67 def configs(self, paths): | |
| 68 assert self._configs is None | |
| 69 for p in paths: | |
| 70 assert os.path.exists(p), p | |
| 71 self._configs = paths | |
| 72 | |
| 73 def build(self): | |
| 74 assert self._injars is not None | |
| 75 assert self._outjar is not None | |
| 76 assert self._configs is not None | |
| 77 cmd = [ | |
| 78 'java', '-jar', self._proguard_jar_path, | |
| 79 '-forceprocessing', | |
| 80 ] | |
| 81 if self._test: | |
| 82 cmd += [ | |
| 83 '-dontobfuscate', | |
| 84 '-dontoptimize', | |
| 85 '-dontshrink', | |
| 86 '-dontskipnonpubliclibraryclassmembers', | |
| 87 ] | |
| 88 | |
| 89 if self._mapping: | |
| 90 cmd += [ | |
| 91 '-applymapping', self._mapping, | |
| 92 ] | |
| 93 | |
| 94 if self._libraries: | |
| 95 cmd += [ | |
| 96 '-libraryjars', ':'.join(self._libraries), | |
| 97 ] | |
| 98 | |
| 99 cmd += [ | |
| 100 '-injars', ':'.join(self._injars) | |
| 101 ] | |
| 102 | |
| 103 for config_file in self._configs: | |
| 104 cmd += ['-include', config_file] | |
| 105 | |
| 106 # The output jar must be specified after inputs. | |
| 107 cmd += [ | |
| 108 '-outjars', self._outjar, | |
| 109 '-dump', self._outjar + '.dump', | |
| 110 '-printseeds', self._outjar + '.seeds', | |
| 111 '-printusage', self._outjar + '.usage', | |
| 112 '-printmapping', self._outjar + '.mapping', | |
| 113 ] | |
| 114 return cmd | |
| 115 | |
| 116 def GetInputs(self): | |
| 117 inputs = [self._proguard_jar_path] + self._configs + self._injars | |
| 118 if self._mapping: | |
| 119 inputs.append(self._mapping) | |
| 120 if self._libraries: | |
| 121 inputs += self._libraries | |
| 122 return inputs | |
| 123 | |
| 124 | |
| 125 def CheckOutput(self): | |
| 126 build_utils.CheckOutput(self.build(), print_stdout=True, | |
| 127 stdout_filter=FilterProguardOutput) | |
| 128 | |
| OLD | NEW |