| OLD | NEW |
| 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 from util import build_utils | 6 from util import build_utils |
| 7 | 7 |
| 8 def FilterProguardOutput(output): | 8 def FilterProguardOutput(output): |
| 9 '''ProGuard outputs boring stuff to stdout (proguard version, jar path, etc) | 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 | 10 as well as interesting stuff (notes, warnings, etc). If stdout is entirely |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 # line doesn't match any of the patterns; it's probably something worth | 25 # line doesn't match any of the patterns; it's probably something worth |
| 26 # printing out. | 26 # printing out. |
| 27 return output | 27 return output |
| 28 return '' | 28 return '' |
| 29 | 29 |
| 30 | 30 |
| 31 class ProguardCmdBuilder(object): | 31 class ProguardCmdBuilder(object): |
| 32 def __init__(self, proguard_jar): | 32 def __init__(self, proguard_jar): |
| 33 assert os.path.exists(proguard_jar) | 33 assert os.path.exists(proguard_jar) |
| 34 self._proguard_jar_path = proguard_jar | 34 self._proguard_jar_path = proguard_jar |
| 35 self._tested_apk_info_path = None | 35 self._test = None |
| 36 self._tested_apk_info = None | |
| 37 self._mapping = None | 36 self._mapping = None |
| 38 self._libraries = None | 37 self._libraries = None |
| 39 self._injars = None | 38 self._injars = None |
| 40 self._configs = None | 39 self._configs = None |
| 41 self._outjar = None | 40 self._outjar = None |
| 42 self._cmd = None | |
| 43 | 41 |
| 44 def outjar(self, path): | 42 def outjar(self, path): |
| 45 assert self._cmd is None | |
| 46 assert self._outjar is None | 43 assert self._outjar is None |
| 47 self._outjar = path | 44 self._outjar = path |
| 48 | 45 |
| 49 def tested_apk_info(self, tested_apk_info_path): | 46 def is_test(self, enable): |
| 50 assert self._cmd is None | 47 assert self._test is None |
| 51 assert self._tested_apk_info is None | 48 self._test = enable |
| 52 self._tested_apk_info_path = tested_apk_info_path | |
| 53 | 49 |
| 54 def mapping(self, path): | 50 def mapping(self, path): |
| 55 assert self._cmd is None | |
| 56 assert self._mapping is None | 51 assert self._mapping is None |
| 57 assert os.path.exists(path), path | 52 assert os.path.exists(path), path |
| 58 self._mapping = path | 53 self._mapping = path |
| 59 | 54 |
| 60 def libraryjars(self, paths): | 55 def libraryjars(self, paths): |
| 61 assert self._cmd is None | |
| 62 assert self._libraries is None | 56 assert self._libraries is None |
| 63 for p in paths: | 57 for p in paths: |
| 64 assert os.path.exists(p), p | 58 assert os.path.exists(p), p |
| 65 self._libraries = paths | 59 self._libraries = paths |
| 66 | 60 |
| 67 def injars(self, paths): | 61 def injars(self, paths): |
| 68 assert self._cmd is None | |
| 69 assert self._injars is None | 62 assert self._injars is None |
| 70 for p in paths: | 63 for p in paths: |
| 71 assert os.path.exists(p), p | 64 assert os.path.exists(p), p |
| 72 self._injars = paths | 65 self._injars = paths |
| 73 | 66 |
| 74 def configs(self, paths): | 67 def configs(self, paths): |
| 75 assert self._cmd is None | |
| 76 assert self._configs is None | 68 assert self._configs is None |
| 77 for p in paths: | 69 for p in paths: |
| 78 assert os.path.exists(p), p | 70 assert os.path.exists(p), p |
| 79 self._configs = paths | 71 self._configs = paths |
| 80 | 72 |
| 81 def build(self): | 73 def build(self): |
| 82 if self._cmd: | |
| 83 return self._cmd | |
| 84 assert self._injars is not None | 74 assert self._injars is not None |
| 85 assert self._outjar is not None | 75 assert self._outjar is not None |
| 86 assert self._configs is not None | 76 assert self._configs is not None |
| 87 cmd = [ | 77 cmd = [ |
| 88 'java', '-jar', self._proguard_jar_path, | 78 'java', '-jar', self._proguard_jar_path, |
| 89 '-forceprocessing', | 79 '-forceprocessing', |
| 90 ] | 80 ] |
| 91 if self._tested_apk_info_path: | 81 if self._test: |
| 92 assert len(self._configs) == 1 | |
| 93 tested_apk_info = build_utils.ReadJson(self._tested_apk_info_path) | |
| 94 self._configs += tested_apk_info['configs'] | |
| 95 self._injars = [ | |
| 96 p for p in self._injars if not p in tested_apk_info['inputs']] | |
| 97 if not self._libraries: | |
| 98 self._libraries = [] | |
| 99 self._libraries += tested_apk_info['inputs'] | |
| 100 self._mapping = tested_apk_info['mapping'] | |
| 101 cmd += [ | 82 cmd += [ |
| 102 '-dontobfuscate', | 83 '-dontobfuscate', |
| 103 '-dontoptimize', | 84 '-dontoptimize', |
| 104 '-dontshrink', | 85 '-dontshrink', |
| 105 '-dontskipnonpubliclibraryclassmembers', | 86 '-dontskipnonpubliclibraryclassmembers', |
| 106 ] | 87 ] |
| 107 | 88 |
| 108 if self._mapping: | 89 if self._mapping: |
| 109 cmd += [ | 90 cmd += [ |
| 110 '-applymapping', self._mapping, | 91 '-applymapping', self._mapping, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 cmd += ['-include', config_file] | 104 cmd += ['-include', config_file] |
| 124 | 105 |
| 125 # The output jar must be specified after inputs. | 106 # The output jar must be specified after inputs. |
| 126 cmd += [ | 107 cmd += [ |
| 127 '-outjars', self._outjar, | 108 '-outjars', self._outjar, |
| 128 '-dump', self._outjar + '.dump', | 109 '-dump', self._outjar + '.dump', |
| 129 '-printseeds', self._outjar + '.seeds', | 110 '-printseeds', self._outjar + '.seeds', |
| 130 '-printusage', self._outjar + '.usage', | 111 '-printusage', self._outjar + '.usage', |
| 131 '-printmapping', self._outjar + '.mapping', | 112 '-printmapping', self._outjar + '.mapping', |
| 132 ] | 113 ] |
| 133 self._cmd = cmd | 114 return cmd |
| 134 return self._cmd | |
| 135 | 115 |
| 136 def GetInputs(self): | 116 def GetInputs(self): |
| 137 self.build() | |
| 138 inputs = [self._proguard_jar_path] + self._configs + self._injars | 117 inputs = [self._proguard_jar_path] + self._configs + self._injars |
| 139 if self._mapping: | 118 if self._mapping: |
| 140 inputs.append(self._mapping) | 119 inputs.append(self._mapping) |
| 141 if self._libraries: | 120 if self._libraries: |
| 142 inputs += self._libraries | 121 inputs += self._libraries |
| 143 if self._tested_apk_info_path: | |
| 144 inputs += [self._tested_apk_info_path] | |
| 145 return inputs | 122 return inputs |
| 146 | 123 |
| 147 | 124 |
| 148 def CheckOutput(self): | 125 def CheckOutput(self): |
| 149 self.build() | 126 build_utils.CheckOutput(self.build(), print_stdout=True, |
| 150 # 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 | |
| 152 # expects. | |
| 153 open(self._outjar + '.dump', 'w').close() | |
| 154 open(self._outjar + '.seeds', 'w').close() | |
| 155 open(self._outjar + '.usage', 'w').close() | |
| 156 open(self._outjar + '.mapping', 'w').close() | |
| 157 build_utils.CheckOutput(self._cmd, print_stdout=True, | |
| 158 stdout_filter=FilterProguardOutput) | 127 stdout_filter=FilterProguardOutput) |
| 159 | 128 |
| 160 this_info = { | |
| 161 'inputs': self._injars, | |
| 162 'configs': self._configs, | |
| 163 'mapping': self._outjar + '.mapping', | |
| 164 } | |
| 165 | |
| 166 build_utils.WriteJson(this_info, self._outjar + '.info') | |
| 167 | |
| OLD | NEW |