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): |
| 82 if self._cmd: |
| 83 return self._cmd |
74 assert self._injars is not None | 84 assert self._injars is not None |
75 assert self._outjar is not None | 85 assert self._outjar is not None |
76 assert self._configs is not None | 86 assert self._configs is not None |
77 cmd = [ | 87 cmd = [ |
78 'java', '-jar', self._proguard_jar_path, | 88 'java', '-jar', self._proguard_jar_path, |
79 '-forceprocessing', | 89 '-forceprocessing', |
80 ] | 90 ] |
81 if self._test: | 91 if self._tested_apk_info_path: |
| 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'] |
82 cmd += [ | 101 cmd += [ |
83 '-dontobfuscate', | 102 '-dontobfuscate', |
84 '-dontoptimize', | 103 '-dontoptimize', |
85 '-dontshrink', | 104 '-dontshrink', |
86 '-dontskipnonpubliclibraryclassmembers', | 105 '-dontskipnonpubliclibraryclassmembers', |
87 ] | 106 ] |
88 | 107 |
89 if self._mapping: | 108 if self._mapping: |
90 cmd += [ | 109 cmd += [ |
91 '-applymapping', self._mapping, | 110 '-applymapping', self._mapping, |
(...skipping 12 matching lines...) Expand all Loading... |
104 cmd += ['-include', config_file] | 123 cmd += ['-include', config_file] |
105 | 124 |
106 # The output jar must be specified after inputs. | 125 # The output jar must be specified after inputs. |
107 cmd += [ | 126 cmd += [ |
108 '-outjars', self._outjar, | 127 '-outjars', self._outjar, |
109 '-dump', self._outjar + '.dump', | 128 '-dump', self._outjar + '.dump', |
110 '-printseeds', self._outjar + '.seeds', | 129 '-printseeds', self._outjar + '.seeds', |
111 '-printusage', self._outjar + '.usage', | 130 '-printusage', self._outjar + '.usage', |
112 '-printmapping', self._outjar + '.mapping', | 131 '-printmapping', self._outjar + '.mapping', |
113 ] | 132 ] |
114 return cmd | 133 self._cmd = cmd |
| 134 return self._cmd |
115 | 135 |
116 def GetInputs(self): | 136 def GetInputs(self): |
| 137 self.build() |
117 inputs = [self._proguard_jar_path] + self._configs + self._injars | 138 inputs = [self._proguard_jar_path] + self._configs + self._injars |
118 if self._mapping: | 139 if self._mapping: |
119 inputs.append(self._mapping) | 140 inputs.append(self._mapping) |
120 if self._libraries: | 141 if self._libraries: |
121 inputs += self._libraries | 142 inputs += self._libraries |
| 143 if self._tested_apk_info_path: |
| 144 inputs += [self._tested_apk_info_path] |
122 return inputs | 145 return inputs |
123 | 146 |
124 | 147 |
125 def CheckOutput(self): | 148 def CheckOutput(self): |
126 build_utils.CheckOutput(self.build(), print_stdout=True, | 149 self.build() |
| 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, |
127 stdout_filter=FilterProguardOutput) | 158 stdout_filter=FilterProguardOutput) |
128 | 159 |
| 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 |