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