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 |
11 import sys | 11 import sys |
12 import tempfile | 12 import tempfile |
13 import zipfile | 13 import zipfile |
14 | 14 |
15 from util import build_utils | 15 from util import build_utils |
16 | 16 |
17 | 17 |
| 18 def _CheckFilePathEndsWithJar(parser, file_path): |
| 19 if not file_path.endswith(".jar"): |
| 20 # dx ignores non .jar files. |
| 21 parser.error("%s does not end in .jar" % file_path) |
| 22 |
| 23 |
| 24 def _CheckFilePathsEndWithJar(parser, file_paths): |
| 25 for file_path in file_paths: |
| 26 _CheckFilePathEndsWithJar(parser, file_path) |
| 27 |
| 28 |
18 def _RemoveUnwantedFilesFromZip(dex_path): | 29 def _RemoveUnwantedFilesFromZip(dex_path): |
19 iz = zipfile.ZipFile(dex_path, 'r') | 30 iz = zipfile.ZipFile(dex_path, 'r') |
20 tmp_dex_path = '%s.tmp.zip' % dex_path | 31 tmp_dex_path = '%s.tmp.zip' % dex_path |
21 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) | 32 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) |
22 for i in iz.namelist(): | 33 for i in iz.namelist(): |
23 if i.endswith('.dex'): | 34 if i.endswith('.dex'): |
24 oz.writestr(i, iz.read(i)) | 35 oz.writestr(i, iz.read(i)) |
25 os.remove(dex_path) | 36 os.remove(dex_path) |
26 os.rename(tmp_dex_path, dex_path) | 37 os.rename(tmp_dex_path, dex_path) |
27 | 38 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 options.multi_dex = multidex_config.get('enabled', False) | 85 options.multi_dex = multidex_config.get('enabled', False) |
75 | 86 |
76 if options.multi_dex and not options.main_dex_list_path: | 87 if options.multi_dex and not options.main_dex_list_path: |
77 logging.warning('multidex cannot be enabled without --main-dex-list-path') | 88 logging.warning('multidex cannot be enabled without --main-dex-list-path') |
78 options.multi_dex = False | 89 options.multi_dex = False |
79 elif options.main_dex_list_path and not options.multi_dex: | 90 elif options.main_dex_list_path and not options.multi_dex: |
80 logging.warning('--main-dex-list-path is unused if multidex is not enabled') | 91 logging.warning('--main-dex-list-path is unused if multidex is not enabled') |
81 | 92 |
82 if options.inputs: | 93 if options.inputs: |
83 options.inputs = build_utils.ParseGypList(options.inputs) | 94 options.inputs = build_utils.ParseGypList(options.inputs) |
| 95 _CheckFilePathsEndWithJar(parser, options.inputs) |
84 if options.excluded_paths: | 96 if options.excluded_paths: |
85 options.excluded_paths = build_utils.ParseGypList(options.excluded_paths) | 97 options.excluded_paths = build_utils.ParseGypList(options.excluded_paths) |
86 | 98 |
| 99 if options.proguard_enabled_input_path: |
| 100 _CheckFilePathEndsWithJar(parser, options.proguard_enabled_input_path) |
| 101 _CheckFilePathsEndWithJar(parser, paths) |
| 102 |
87 return options, paths | 103 return options, paths |
88 | 104 |
89 | 105 |
90 def _AllSubpathsAreClassFiles(paths, changes): | 106 def _AllSubpathsAreClassFiles(paths, changes): |
91 for path in paths: | 107 for path in paths: |
92 if any(not p.endswith('.class') for p in changes.IterChangedSubpaths(path)): | 108 if any(not p.endswith('.class') for p in changes.IterChangedSubpaths(path)): |
93 return False | 109 return False |
94 return True | 110 return True |
95 | 111 |
96 | 112 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 options, | 238 options, |
223 input_paths=input_paths, | 239 input_paths=input_paths, |
224 input_strings=dex_cmd, | 240 input_strings=dex_cmd, |
225 output_paths=output_paths, | 241 output_paths=output_paths, |
226 force=force, | 242 force=force, |
227 pass_changes=True) | 243 pass_changes=True) |
228 | 244 |
229 | 245 |
230 if __name__ == '__main__': | 246 if __name__ == '__main__': |
231 sys.exit(main(sys.argv[1:])) | 247 sys.exit(main(sys.argv[1:])) |
OLD | NEW |