OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import json | 7 import json |
8 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 | 96 |
97 def _DexWasEmpty(paths, changes): | 97 def _DexWasEmpty(paths, changes): |
98 for path in paths: | 98 for path in paths: |
99 if any(p.endswith('.class') | 99 if any(p.endswith('.class') |
100 for p in changes.old_metadata.IterSubpaths(path)): | 100 for p in changes.old_metadata.IterSubpaths(path)): |
101 return False | 101 return False |
102 return True | 102 return True |
103 | 103 |
104 | 104 |
| 105 def _IterAllClassFiles(changes): |
| 106 for path in changes.IterAllPaths(): |
| 107 for subpath in changes.IterAllSubpaths(path): |
| 108 if subpath.endswith('.class'): |
| 109 yield path |
| 110 |
| 111 |
| 112 def _MightHitDxBug(changes): |
| 113 # We've seen dx --incremental fail for small libraries. It's unlikely a |
| 114 # speed-up anyways in this case. |
| 115 num_classes = sum(1 for x in _IterAllClassFiles(changes)) |
| 116 if num_classes < 10: |
| 117 return True |
| 118 |
| 119 # We've also been able to consistently produce a failure by adding an empty |
| 120 # line to the top of the first .java file of a library. |
| 121 # https://crbug.com/617935 |
| 122 first_file = next(_IterAllClassFiles(changes)) |
| 123 for path in changes.IterChangedPaths(): |
| 124 for subpath in changes.IterChangedSubpaths(path): |
| 125 if first_file == subpath: |
| 126 return True |
| 127 return False |
| 128 |
| 129 |
105 def _RunDx(changes, options, dex_cmd, paths): | 130 def _RunDx(changes, options, dex_cmd, paths): |
106 with build_utils.TempDir() as classes_temp_dir: | 131 with build_utils.TempDir() as classes_temp_dir: |
107 # --multi-dex is incompatible with --incremental. | 132 # --multi-dex is incompatible with --incremental. |
108 if options.multi_dex: | 133 if options.multi_dex: |
109 dex_cmd.append('--main-dex-list=%s' % options.main_dex_list_path) | 134 dex_cmd.append('--main-dex-list=%s' % options.main_dex_list_path) |
110 else: | 135 else: |
111 # Use --incremental when .class files are added or modified (never when | |
112 # removed). | |
113 # --incremental tells dx to merge all newly dex'ed .class files with | 136 # --incremental tells dx to merge all newly dex'ed .class files with |
114 # what that already exist in the output dex file (existing classes are | 137 # what that already exist in the output dex file (existing classes are |
115 # replaced). | 138 # replaced). |
116 if options.incremental and changes.AddedOrModifiedOnly(): | 139 # Use --incremental when .class files are added or modified, but not when |
| 140 # any are removed (since it won't know to remove them). |
| 141 if (options.incremental |
| 142 and not _MightHitDxBug(changes) |
| 143 and changes.AddedOrModifiedOnly()): |
117 changed_inputs = set(changes.IterChangedPaths()) | 144 changed_inputs = set(changes.IterChangedPaths()) |
118 changed_paths = [p for p in paths if p in changed_inputs] | 145 changed_paths = [p for p in paths if p in changed_inputs] |
119 if not changed_paths: | 146 if not changed_paths: |
120 return | 147 return |
121 # When merging in other dex files, there's no easy way to know if | 148 # When merging in other dex files, there's no easy way to know if |
122 # classes were removed from them. | 149 # classes were removed from them. |
123 if (_AllSubpathsAreClassFiles(changed_paths, changes) | 150 if (_AllSubpathsAreClassFiles(changed_paths, changes) |
124 and not _DexWasEmpty(changed_paths, changes)): | 151 and not _DexWasEmpty(changed_paths, changes)): |
125 dex_cmd.append('--incremental') | 152 dex_cmd.append('--incremental') |
126 for path in changed_paths: | 153 for path in changed_paths: |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 options, | 222 options, |
196 input_paths=input_paths, | 223 input_paths=input_paths, |
197 input_strings=dex_cmd, | 224 input_strings=dex_cmd, |
198 output_paths=output_paths, | 225 output_paths=output_paths, |
199 force=force, | 226 force=force, |
200 pass_changes=True) | 227 pass_changes=True) |
201 | 228 |
202 | 229 |
203 if __name__ == '__main__': | 230 if __name__ == '__main__': |
204 sys.exit(main(sys.argv[1:])) | 231 sys.exit(main(sys.argv[1:])) |
OLD | NEW |