Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: build/android/gyp/dex.py

Issue 1408163009: [Android] Enable multidex for debug builds of ChromePublic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn build Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gyp/configure_multidex.py ('k') | build/android/gyp/main_dex_list.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 logging 8 import logging
8 import optparse 9 import optparse
9 import os 10 import os
10 import sys 11 import sys
11 import tempfile 12 import tempfile
12 import zipfile 13 import zipfile
13 14
14 from util import build_utils 15 from util import build_utils
15 16
16 17
17 def _CreateCombinedMainDexList(main_dex_list_paths):
18 main_dex_list = []
19 for m in main_dex_list_paths:
20 with open(m) as main_dex_list_file:
21 main_dex_list.extend(l for l in main_dex_list_file if l)
22 return '\n'.join(main_dex_list)
23
24
25 def _RemoveUnwantedFilesFromZip(dex_path): 18 def _RemoveUnwantedFilesFromZip(dex_path):
26 iz = zipfile.ZipFile(dex_path, 'r') 19 iz = zipfile.ZipFile(dex_path, 'r')
27 tmp_dex_path = '%s.tmp.zip' % dex_path 20 tmp_dex_path = '%s.tmp.zip' % dex_path
28 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) 21 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED)
29 for i in iz.namelist(): 22 for i in iz.namelist():
30 if i.endswith('.dex'): 23 if i.endswith('.dex'):
31 oz.writestr(i, iz.read(i)) 24 oz.writestr(i, iz.read(i))
32 os.remove(dex_path) 25 os.remove(dex_path)
33 os.rename(tmp_dex_path, dex_path) 26 os.rename(tmp_dex_path, dex_path)
34 27
(...skipping 14 matching lines...) Expand all
49 help='The build CONFIGURATION_NAME.') 42 help='The build CONFIGURATION_NAME.')
50 parser.add_option('--proguard-enabled', 43 parser.add_option('--proguard-enabled',
51 help='"true" if proguard is enabled.') 44 help='"true" if proguard is enabled.')
52 parser.add_option('--debug-build-proguard-enabled', 45 parser.add_option('--debug-build-proguard-enabled',
53 help='"true" if proguard is enabled for debug build.') 46 help='"true" if proguard is enabled for debug build.')
54 parser.add_option('--proguard-enabled-input-path', 47 parser.add_option('--proguard-enabled-input-path',
55 help=('Path to dex in Release mode when proguard ' 48 help=('Path to dex in Release mode when proguard '
56 'is enabled.')) 49 'is enabled.'))
57 parser.add_option('--no-locals', 50 parser.add_option('--no-locals',
58 help='Exclude locals list from the dex file.') 51 help='Exclude locals list from the dex file.')
59 parser.add_option('--multi-dex', default=False, action='store_true',
60 help='Create multiple dex files.')
61 parser.add_option('--incremental', 52 parser.add_option('--incremental',
62 action='store_true', 53 action='store_true',
63 help='Enable incremental builds when possible.') 54 help='Enable incremental builds when possible.')
64 parser.add_option('--inputs', help='A list of additional input paths.') 55 parser.add_option('--inputs', help='A list of additional input paths.')
65 parser.add_option('--excluded-paths', 56 parser.add_option('--excluded-paths',
66 help='A list of paths to exclude from the dex file.') 57 help='A list of paths to exclude from the dex file.')
67 parser.add_option('--main-dex-list-paths', 58 parser.add_option('--main-dex-list-path',
68 help='A list of paths containing a list of the classes to ' 59 help='A file containing a list of the classes to '
69 'include in the main dex.') 60 'include in the main dex.')
61 parser.add_option('--multidex-configuration-path',
62 help='A JSON file containing multidex build configuration.')
70 63
71 options, paths = parser.parse_args(args) 64 options, paths = parser.parse_args(args)
72 65
73 required_options = ('android_sdk_tools',) 66 required_options = ('android_sdk_tools',)
74 build_utils.CheckOptions(options, parser, required=required_options) 67 build_utils.CheckOptions(options, parser, required=required_options)
75 68
76 if options.multi_dex and not options.main_dex_list_paths: 69 options.multi_dex = False
77 logging.warning('--multi-dex is unused without --main-dex-list-paths') 70 if options.multidex_configuration_path:
71 with open(options.multidex_configuration_path) as multidex_config_file:
72 multidex_config = json.loads(multidex_config_file.read())
73 options.multi_dex = multidex_config.get('enabled', False)
74
75 if options.multi_dex and not options.main_dex_list_path:
76 logging.warning('multidex cannot be enabled without --main-dex-list-path')
78 options.multi_dex = False 77 options.multi_dex = False
79 elif options.main_dex_list_paths and not options.multi_dex: 78 elif options.main_dex_list_path and not options.multi_dex:
80 logging.warning('--main-dex-list-paths is unused without --multi-dex') 79 logging.warning('--main-dex-list-path is unused if multidex is not enabled')
81 80
82 if options.main_dex_list_paths:
83 options.main_dex_list_paths = build_utils.ParseGypList(
84 options.main_dex_list_paths)
85 if options.inputs: 81 if options.inputs:
86 options.inputs = build_utils.ParseGypList(options.inputs) 82 options.inputs = build_utils.ParseGypList(options.inputs)
87 if options.excluded_paths: 83 if options.excluded_paths:
88 options.excluded_paths = build_utils.ParseGypList(options.excluded_paths) 84 options.excluded_paths = build_utils.ParseGypList(options.excluded_paths)
89 85
90 return options, paths 86 return options, paths
91 87
92 88
93 def _AllSubpathsAreClassFiles(paths, changes): 89 def _AllSubpathsAreClassFiles(paths, changes):
94 for path in paths: 90 for path in paths:
95 if any(not p.endswith('.class') for p in changes.IterChangedSubpaths(path)): 91 if any(not p.endswith('.class') for p in changes.IterChangedSubpaths(path)):
96 return False 92 return False
97 return True 93 return True
98 94
99 95
100 def _RunDx(changes, options, dex_cmd, paths): 96 def _RunDx(changes, options, dex_cmd, paths):
101 with build_utils.TempDir() as classes_temp_dir: 97 with build_utils.TempDir() as classes_temp_dir:
102 # --multi-dex is incompatible with --incremental. 98 # --multi-dex is incompatible with --incremental.
103 if options.multi_dex: 99 if options.multi_dex:
104 combined_main_dex_list = tempfile.NamedTemporaryFile(suffix='.txt') 100 dex_cmd.append('--main-dex-list=%s' % options.main_dex_list_path)
105 combined_main_dex_list.write(
106 _CreateCombinedMainDexList(options.main_dex_list_paths))
107 combined_main_dex_list.flush()
108 dex_cmd.append('--main-dex-list=%s' % combined_main_dex_list.name)
109 else: 101 else:
110 # Use --incremental when .class files are added or modified (never when 102 # Use --incremental when .class files are added or modified (never when
111 # removed). 103 # removed).
112 # --incremental tells dx to merge all newly dex'ed .class files with 104 # --incremental tells dx to merge all newly dex'ed .class files with
113 # what that already exist in the output dex file (existing classes are 105 # what that already exist in the output dex file (existing classes are
114 # replaced). 106 # replaced).
115 if options.incremental and changes.AddedOrModifiedOnly(): 107 if options.incremental and changes.AddedOrModifiedOnly():
116 changed_inputs = set(changes.IterChangedPaths()) 108 changed_inputs = set(changes.IterChangedPaths())
117 changed_paths = [p for p in paths if p in changed_inputs] 109 changed_paths = [p for p in paths if p in changed_inputs]
118 if not changed_paths: 110 if not changed_paths:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 dx_binary = os.path.join(options.android_sdk_tools, 'dx') 158 dx_binary = os.path.join(options.android_sdk_tools, 'dx')
167 # See http://crbug.com/272064 for context on --force-jumbo. 159 # See http://crbug.com/272064 for context on --force-jumbo.
168 # See https://github.com/android/platform_dalvik/commit/dd140a22d for 160 # See https://github.com/android/platform_dalvik/commit/dd140a22d for
169 # --num-threads. 161 # --num-threads.
170 dex_cmd = [dx_binary, '--num-threads=8', '--dex', '--force-jumbo', 162 dex_cmd = [dx_binary, '--num-threads=8', '--dex', '--force-jumbo',
171 '--output', options.dex_path] 163 '--output', options.dex_path]
172 if options.no_locals != '0': 164 if options.no_locals != '0':
173 dex_cmd.append('--no-locals') 165 dex_cmd.append('--no-locals')
174 166
175 if options.multi_dex: 167 if options.multi_dex:
176 input_paths.extend(options.main_dex_list_paths) 168 input_paths.append(options.main_dex_list_path)
177 dex_cmd += [ 169 dex_cmd += [
178 '--multi-dex', 170 '--multi-dex',
179 '--minimal-main-dex', 171 '--minimal-main-dex',
180 ] 172 ]
181 173
182 output_paths = [ 174 output_paths = [
183 options.dex_path, 175 options.dex_path,
184 options.dex_path + '.inputs', 176 options.dex_path + '.inputs',
185 ] 177 ]
186 178
187 # An escape hatch to be able to check if incremental dexing is causing 179 # An escape hatch to be able to check if incremental dexing is causing
188 # problems. 180 # problems.
189 force = int(os.environ.get('DISABLE_INCREMENTAL_DX', 0)) 181 force = int(os.environ.get('DISABLE_INCREMENTAL_DX', 0))
190 182
191 build_utils.CallAndWriteDepfileIfStale( 183 build_utils.CallAndWriteDepfileIfStale(
192 lambda changes: _OnStaleMd5(changes, options, dex_cmd, paths), 184 lambda changes: _OnStaleMd5(changes, options, dex_cmd, paths),
193 options, 185 options,
194 input_paths=input_paths, 186 input_paths=input_paths,
195 input_strings=dex_cmd, 187 input_strings=dex_cmd,
196 output_paths=output_paths, 188 output_paths=output_paths,
197 force=force, 189 force=force,
198 pass_changes=True) 190 pass_changes=True)
199 191
200 192
201 if __name__ == '__main__': 193 if __name__ == '__main__':
202 sys.exit(main(sys.argv[1:])) 194 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/configure_multidex.py ('k') | build/android/gyp/main_dex_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698