Chromium Code Reviews| 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 logging | |
| 7 import optparse | 8 import optparse |
| 8 import os | 9 import os |
| 9 import sys | 10 import sys |
| 11 import tempfile | |
| 12 import zipfile | |
| 10 | 13 |
| 11 from util import build_utils | 14 from util import build_utils |
| 12 from util import md5_check | 15 from util import md5_check |
| 13 | 16 |
| 14 | 17 |
| 15 def DoDex(options, paths): | 18 def DoDex(options, paths): |
| 19 if options.multi_dex and options.main_dex_list_paths: | |
|
Yaron
2015/08/13 20:12:10
Nit: I think it's cleaner to move this all to the
jbudorick
2015/08/14 21:01:21
done
| |
| 20 DoMultiDex(options, paths) | |
| 21 else: | |
| 22 if options.multi_dex: | |
| 23 logging.warning('--multi-dex is unused without --main-dex-list-paths') | |
| 24 elif options.main_dex_list_paths: | |
| 25 logging.warning('--main-dex-list-paths is unused without --multi-dex') | |
| 26 _DoDexImpl([], options, paths) | |
| 27 | |
| 28 | |
| 29 def DoMultiDex(options, paths): | |
| 30 main_dex_list = [] | |
| 31 main_dex_list_files = build_utils.ParseGypList(options.main_dex_list_paths) | |
| 32 for m in main_dex_list_files: | |
| 33 with open(m) as main_dex_list_file: | |
| 34 for l in main_dex_list_file: | |
|
Yaron
2015/08/13 20:12:10
use a list comprehension?
jbudorick
2015/08/14 21:01:21
derp. done.
| |
| 35 if l: | |
| 36 main_dex_list.append(l) | |
| 37 | |
| 38 with tempfile.NamedTemporaryFile(suffix='.txt') as combined_main_dex_list: | |
| 39 combined_main_dex_list.write('\n'.join(main_dex_list)) | |
| 40 combined_main_dex_list.flush() | |
| 41 | |
| 42 dex_args = [ | |
| 43 '--multi-dex', | |
| 44 '--minimal-main-dex', | |
| 45 '--main-dex-list=%s' % combined_main_dex_list.name | |
| 46 ] | |
| 47 | |
| 48 _DoDexImpl(dex_args, options, paths) | |
| 49 | |
| 50 if options.dex_path.endswith('.zip'): | |
| 51 iz = zipfile.ZipFile(options.dex_path, 'r') | |
| 52 tmp_dex_path = '%s.tmp.zip' % options.dex_path | |
| 53 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) | |
| 54 for i in iz.namelist(): | |
| 55 if i.endswith('.dex'): | |
| 56 oz.writestr(i, iz.read(i)) | |
| 57 os.remove(options.dex_path) | |
| 58 os.rename(tmp_dex_path, options.dex_path) | |
| 59 | |
| 60 | |
| 61 def _DoDexImpl(dex_args, options, paths): | |
| 16 dx_binary = os.path.join(options.android_sdk_tools, 'dx') | 62 dx_binary = os.path.join(options.android_sdk_tools, 'dx') |
| 17 # See http://crbug.com/272064 for context on --force-jumbo. | 63 # See http://crbug.com/272064 for context on --force-jumbo. |
| 18 dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path] | 64 dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path] |
| 19 if options.no_locals != '0': | 65 if options.no_locals != '0': |
| 20 dex_cmd.append('--no-locals') | 66 dex_cmd.append('--no-locals') |
| 21 | 67 |
| 68 if dex_args: | |
| 69 dex_cmd += dex_args | |
| 70 | |
| 22 dex_cmd += paths | 71 dex_cmd += paths |
| 23 | 72 |
| 24 record_path = '%s.md5.stamp' % options.dex_path | 73 record_path = '%s.md5.stamp' % options.dex_path |
| 25 md5_check.CallAndRecordIfStale( | 74 md5_check.CallAndRecordIfStale( |
| 26 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False), | 75 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False), |
| 27 record_path=record_path, | 76 record_path=record_path, |
| 28 input_paths=paths, | 77 input_paths=paths, |
| 29 input_strings=dex_cmd, | 78 input_strings=dex_cmd, |
| 30 force=not os.path.exists(options.dex_path)) | 79 force=not os.path.exists(options.dex_path)) |
| 31 build_utils.WriteJson( | 80 build_utils.WriteJson( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 47 parser.add_option('--dex-path', help='Dex output path.') | 96 parser.add_option('--dex-path', help='Dex output path.') |
| 48 parser.add_option('--configuration-name', | 97 parser.add_option('--configuration-name', |
| 49 help='The build CONFIGURATION_NAME.') | 98 help='The build CONFIGURATION_NAME.') |
| 50 parser.add_option('--proguard-enabled', | 99 parser.add_option('--proguard-enabled', |
| 51 help='"true" if proguard is enabled.') | 100 help='"true" if proguard is enabled.') |
| 52 parser.add_option('--proguard-enabled-input-path', | 101 parser.add_option('--proguard-enabled-input-path', |
| 53 help=('Path to dex in Release mode when proguard ' | 102 help=('Path to dex in Release mode when proguard ' |
| 54 'is enabled.')) | 103 'is enabled.')) |
| 55 parser.add_option('--no-locals', | 104 parser.add_option('--no-locals', |
| 56 help='Exclude locals list from the dex file.') | 105 help='Exclude locals list from the dex file.') |
| 106 parser.add_option('--multi-dex', default=False, action='store_true', | |
| 107 help='Create multiple dex files.') | |
| 57 parser.add_option('--inputs', help='A list of additional input paths.') | 108 parser.add_option('--inputs', help='A list of additional input paths.') |
| 58 parser.add_option('--excluded-paths', | 109 parser.add_option('--excluded-paths', |
| 59 help='A list of paths to exclude from the dex file.') | 110 help='A list of paths to exclude from the dex file.') |
| 111 parser.add_option('--main-dex-list-paths', | |
| 112 help='A list of paths containing a list of the classes to ' | |
| 113 'include in the main dex.') | |
| 60 | 114 |
| 61 options, paths = parser.parse_args(args) | 115 options, paths = parser.parse_args(args) |
| 62 | 116 |
| 63 required_options = ('android_sdk_tools',) | 117 required_options = ('android_sdk_tools',) |
| 64 build_utils.CheckOptions(options, parser, required=required_options) | 118 build_utils.CheckOptions(options, parser, required=required_options) |
| 65 | 119 |
| 66 if (options.proguard_enabled == 'true' | 120 if (options.proguard_enabled == 'true' |
| 67 and options.configuration_name == 'Release'): | 121 and options.configuration_name == 'Release'): |
| 68 paths = [options.proguard_enabled_input_path] | 122 paths = [options.proguard_enabled_input_path] |
| 69 | 123 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 80 | 134 |
| 81 if options.depfile: | 135 if options.depfile: |
| 82 build_utils.WriteDepfile( | 136 build_utils.WriteDepfile( |
| 83 options.depfile, | 137 options.depfile, |
| 84 paths + build_utils.GetPythonDependencies()) | 138 paths + build_utils.GetPythonDependencies()) |
| 85 | 139 |
| 86 | 140 |
| 87 | 141 |
| 88 if __name__ == '__main__': | 142 if __name__ == '__main__': |
| 89 sys.exit(main()) | 143 sys.exit(main()) |
| OLD | NEW |