Chromium Code Reviews| 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._test = None | 35 self._tested_apk_info_path = None |
| 36 self._tested_apk_info = None | |
| 36 self._mapping = None | 37 self._mapping = None |
| 37 self._libraries = None | 38 self._libraries = None |
| 38 self._injars = None | 39 self._injars = None |
| 39 self._configs = None | 40 self._configs = None |
| 40 self._outjar = None | 41 self._outjar = None |
| 42 self._cmd = None | |
| 41 | 43 |
| 42 def outjar(self, path): | 44 def outjar(self, path): |
| 45 assert self._cmd is None | |
| 43 assert self._outjar is None | 46 assert self._outjar is None |
| 44 self._outjar = path | 47 self._outjar = path |
| 45 | 48 |
| 46 def is_test(self, enable): | 49 def tested_apk_info(self, tested_apk_info_path): |
| 47 assert self._test is None | 50 assert self._cmd is None |
| 48 self._test = enable | 51 assert self._tested_apk_info is None |
| 52 self._tested_apk_info_path = tested_apk_info_path | |
| 49 | 53 |
| 50 def mapping(self, path): | 54 def mapping(self, path): |
| 55 assert self._cmd is None | |
| 51 assert self._mapping is None | 56 assert self._mapping is None |
| 52 assert os.path.exists(path), path | 57 assert os.path.exists(path), path |
| 53 self._mapping = path | 58 self._mapping = path |
| 54 | 59 |
| 55 def libraryjars(self, paths): | 60 def libraryjars(self, paths): |
| 61 assert self._cmd is None | |
| 56 assert self._libraries is None | 62 assert self._libraries is None |
| 57 for p in paths: | 63 for p in paths: |
| 58 assert os.path.exists(p), p | 64 assert os.path.exists(p), p |
| 59 self._libraries = paths | 65 self._libraries = paths |
| 60 | 66 |
| 61 def injars(self, paths): | 67 def injars(self, paths): |
| 68 assert self._cmd is None | |
| 62 assert self._injars is None | 69 assert self._injars is None |
| 63 for p in paths: | 70 for p in paths: |
| 64 assert os.path.exists(p), p | 71 assert os.path.exists(p), p |
| 65 self._injars = paths | 72 self._injars = paths |
| 66 | 73 |
| 67 def configs(self, paths): | 74 def configs(self, paths): |
| 75 assert self._cmd is None | |
| 68 assert self._configs is None | 76 assert self._configs is None |
| 69 for p in paths: | 77 for p in paths: |
| 70 assert os.path.exists(p), p | 78 assert os.path.exists(p), p |
| 71 self._configs = paths | 79 self._configs = paths |
| 72 | 80 |
| 73 def build(self): | 81 def build(self): |
| 74 assert self._injars is not None | 82 if not self._cmd: |
|
newt (away)
2015/11/11 18:21:33
an early return would be nice here to reduce nesti
agrieve
2015/11/11 18:53:45
Done.
| |
| 75 assert self._outjar is not None | 83 assert self._injars is not None |
| 76 assert self._configs is not None | 84 assert self._outjar is not None |
| 77 cmd = [ | 85 assert self._configs is not None |
| 78 'java', '-jar', self._proguard_jar_path, | 86 cmd = [ |
| 79 '-forceprocessing', | 87 'java', '-jar', self._proguard_jar_path, |
| 80 ] | 88 '-forceprocessing', |
| 81 if self._test: | 89 ] |
| 90 if self._tested_apk_info_path: | |
| 91 assert len(self._configs) == 1 | |
| 92 tested_apk_info = build_utils.ReadJson(self._tested_apk_info_path) | |
| 93 self._configs += tested_apk_info['configs'] | |
| 94 self._injars = [ | |
| 95 p for p in self._injars if not p in tested_apk_info['inputs']] | |
| 96 if not self._libraries: | |
| 97 self._libraries = [] | |
| 98 self._libraries += tested_apk_info['inputs'] | |
| 99 self._mapping = tested_apk_info['mapping'] | |
| 100 cmd += [ | |
| 101 '-dontobfuscate', | |
| 102 '-dontoptimize', | |
| 103 '-dontshrink', | |
| 104 '-dontskipnonpubliclibraryclassmembers', | |
| 105 ] | |
| 106 | |
| 107 if self._mapping: | |
| 108 cmd += [ | |
| 109 '-applymapping', self._mapping, | |
| 110 ] | |
| 111 | |
| 112 if self._libraries: | |
| 113 cmd += [ | |
| 114 '-libraryjars', ':'.join(self._libraries), | |
| 115 ] | |
| 116 | |
| 82 cmd += [ | 117 cmd += [ |
| 83 '-dontobfuscate', | 118 '-injars', ':'.join(self._injars) |
| 84 '-dontoptimize', | |
| 85 '-dontshrink', | |
| 86 '-dontskipnonpubliclibraryclassmembers', | |
| 87 ] | 119 ] |
| 88 | 120 |
| 89 if self._mapping: | 121 for config_file in self._configs: |
| 122 cmd += ['-include', config_file] | |
| 123 | |
| 124 # The output jar must be specified after inputs. | |
| 90 cmd += [ | 125 cmd += [ |
| 91 '-applymapping', self._mapping, | 126 '-outjars', self._outjar, |
| 127 '-dump', self._outjar + '.dump', | |
| 128 '-printseeds', self._outjar + '.seeds', | |
| 129 '-printusage', self._outjar + '.usage', | |
| 130 '-printmapping', self._outjar + '.mapping', | |
| 92 ] | 131 ] |
| 93 | 132 self._cmd = cmd |
| 94 if self._libraries: | 133 return self._cmd |
| 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 | 134 |
| 116 def GetInputs(self): | 135 def GetInputs(self): |
| 136 self.build() | |
| 117 inputs = [self._proguard_jar_path] + self._configs + self._injars | 137 inputs = [self._proguard_jar_path] + self._configs + self._injars |
| 118 if self._mapping: | 138 if self._mapping: |
| 119 inputs.append(self._mapping) | 139 inputs.append(self._mapping) |
| 120 if self._libraries: | 140 if self._libraries: |
| 121 inputs += self._libraries | 141 inputs += self._libraries |
| 142 if self._tested_apk_info_path: | |
| 143 inputs += [self._tested_apk_info_path] | |
| 122 return inputs | 144 return inputs |
| 123 | 145 |
| 124 | 146 |
| 125 def CheckOutput(self): | 147 def CheckOutput(self): |
| 126 build_utils.CheckOutput(self.build(), print_stdout=True, | 148 self.build() |
| 149 # Proguard will skip writing these files if they would be empty. Create | |
| 150 # empty versions of them all now so that they are updated as the build | |
| 151 # expects. | |
| 152 open(self._outjar + '.dump', 'w').close() | |
| 153 open(self._outjar + '.seeds', 'w').close() | |
| 154 open(self._outjar + '.usage', 'w').close() | |
| 155 open(self._outjar + '.mapping', 'w').close() | |
| 156 build_utils.CheckOutput(self._cmd, print_stdout=True, | |
| 127 stdout_filter=FilterProguardOutput) | 157 stdout_filter=FilterProguardOutput) |
| 128 | 158 |
| 159 this_info = { | |
| 160 'inputs': self._injars, | |
| 161 'configs': self._configs, | |
| 162 'mapping': self._outjar + '.mapping', | |
| 163 } | |
| 164 | |
| 165 build_utils.WriteJson(this_info, self._outjar + '.info') | |
| 166 | |
| OLD | NEW |