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

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

Issue 1318513003: [Android] Add gyp support for multidex. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add @VisibleForTesting to ChromiumMultiDex.install Created 5 years, 4 months 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/apkbuilder_action.gypi ('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 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 DoMultiDex(options, paths):
19 main_dex_list = []
20 main_dex_list_files = build_utils.ParseGypList(options.main_dex_list_paths)
21 for m in main_dex_list_files:
22 with open(m) as main_dex_list_file:
23 main_dex_list.extend(l for l in main_dex_list_file if l)
24
25 with tempfile.NamedTemporaryFile(suffix='.txt') as combined_main_dex_list:
26 combined_main_dex_list.write('\n'.join(main_dex_list))
27 combined_main_dex_list.flush()
28
29 dex_args = [
30 '--multi-dex',
31 '--minimal-main-dex',
32 '--main-dex-list=%s' % combined_main_dex_list.name
33 ]
34
35 DoDex(options, paths, dex_args=dex_args)
36
37 if options.dex_path.endswith('.zip'):
38 iz = zipfile.ZipFile(options.dex_path, 'r')
39 tmp_dex_path = '%s.tmp.zip' % options.dex_path
40 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED)
41 for i in iz.namelist():
42 if i.endswith('.dex'):
43 oz.writestr(i, iz.read(i))
44 os.remove(options.dex_path)
45 os.rename(tmp_dex_path, options.dex_path)
46
47
48 def DoDex(options, paths, dex_args=None):
16 dx_binary = os.path.join(options.android_sdk_tools, 'dx') 49 dx_binary = os.path.join(options.android_sdk_tools, 'dx')
17 # See http://crbug.com/272064 for context on --force-jumbo. 50 # See http://crbug.com/272064 for context on --force-jumbo.
18 dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path] 51 dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path]
19 if options.no_locals != '0': 52 if options.no_locals != '0':
20 dex_cmd.append('--no-locals') 53 dex_cmd.append('--no-locals')
21 54
55 if dex_args:
56 dex_cmd += dex_args
57
22 dex_cmd += paths 58 dex_cmd += paths
23 59
24 record_path = '%s.md5.stamp' % options.dex_path 60 record_path = '%s.md5.stamp' % options.dex_path
25 md5_check.CallAndRecordIfStale( 61 md5_check.CallAndRecordIfStale(
26 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False), 62 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False),
27 record_path=record_path, 63 record_path=record_path,
28 input_paths=paths, 64 input_paths=paths,
29 input_strings=dex_cmd, 65 input_strings=dex_cmd,
30 force=not os.path.exists(options.dex_path)) 66 force=not os.path.exists(options.dex_path))
31 build_utils.WriteJson( 67 build_utils.WriteJson(
(...skipping 15 matching lines...) Expand all
47 parser.add_option('--dex-path', help='Dex output path.') 83 parser.add_option('--dex-path', help='Dex output path.')
48 parser.add_option('--configuration-name', 84 parser.add_option('--configuration-name',
49 help='The build CONFIGURATION_NAME.') 85 help='The build CONFIGURATION_NAME.')
50 parser.add_option('--proguard-enabled', 86 parser.add_option('--proguard-enabled',
51 help='"true" if proguard is enabled.') 87 help='"true" if proguard is enabled.')
52 parser.add_option('--proguard-enabled-input-path', 88 parser.add_option('--proguard-enabled-input-path',
53 help=('Path to dex in Release mode when proguard ' 89 help=('Path to dex in Release mode when proguard '
54 'is enabled.')) 90 'is enabled.'))
55 parser.add_option('--no-locals', 91 parser.add_option('--no-locals',
56 help='Exclude locals list from the dex file.') 92 help='Exclude locals list from the dex file.')
93 parser.add_option('--multi-dex', default=False, action='store_true',
94 help='Create multiple dex files.')
57 parser.add_option('--inputs', help='A list of additional input paths.') 95 parser.add_option('--inputs', help='A list of additional input paths.')
58 parser.add_option('--excluded-paths', 96 parser.add_option('--excluded-paths',
59 help='A list of paths to exclude from the dex file.') 97 help='A list of paths to exclude from the dex file.')
98 parser.add_option('--main-dex-list-paths',
99 help='A list of paths containing a list of the classes to '
100 'include in the main dex.')
60 101
61 options, paths = parser.parse_args(args) 102 options, paths = parser.parse_args(args)
62 103
63 required_options = ('android_sdk_tools',) 104 required_options = ('android_sdk_tools',)
64 build_utils.CheckOptions(options, parser, required=required_options) 105 build_utils.CheckOptions(options, parser, required=required_options)
65 106
66 if (options.proguard_enabled == 'true' 107 if (options.proguard_enabled == 'true'
67 and options.configuration_name == 'Release'): 108 and options.configuration_name == 'Release'):
68 paths = [options.proguard_enabled_input_path] 109 paths = [options.proguard_enabled_input_path]
69 110
70 if options.inputs: 111 if options.inputs:
71 paths += build_utils.ParseGypList(options.inputs) 112 paths += build_utils.ParseGypList(options.inputs)
72 113
73 if options.excluded_paths: 114 if options.excluded_paths:
74 # Excluded paths are relative to the output directory. 115 # Excluded paths are relative to the output directory.
75 exclude_paths = build_utils.ParseGypList(options.excluded_paths) 116 exclude_paths = build_utils.ParseGypList(options.excluded_paths)
76 paths = [p for p in paths if not 117 paths = [p for p in paths if not
77 os.path.relpath(p, options.output_directory) in exclude_paths] 118 os.path.relpath(p, options.output_directory) in exclude_paths]
78 119
79 DoDex(options, paths) 120 if options.multi_dex and options.main_dex_list_paths:
121 DoMultiDex(options, paths)
122 else:
123 if options.multi_dex:
124 logging.warning('--multi-dex is unused without --main-dex-list-paths')
125 elif options.main_dex_list_paths:
126 logging.warning('--main-dex-list-paths is unused without --multi-dex')
127 DoDex(options, paths)
80 128
81 if options.depfile: 129 if options.depfile:
82 build_utils.WriteDepfile( 130 build_utils.WriteDepfile(
83 options.depfile, 131 options.depfile,
84 paths + build_utils.GetPythonDependencies()) 132 paths + build_utils.GetPythonDependencies())
85 133
86 134
87 135
88 if __name__ == '__main__': 136 if __name__ == '__main__':
89 sys.exit(main()) 137 sys.exit(main())
OLDNEW
« no previous file with comments | « build/android/apkbuilder_action.gypi ('k') | build/android/gyp/main_dex_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698