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

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

Issue 1408163009: [Android] Enable multidex for debug builds of ChromePublic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: actually remove --tested-apk-multidex-configuration-path 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 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 argparse 7 import argparse
8 import json
8 import os 9 import os
9 import sys 10 import sys
10 import tempfile 11 import tempfile
11 12
12 from util import build_utils 13 from util import build_utils
13 14
14 sys.path.append(os.path.abspath(os.path.join( 15 sys.path.append(os.path.abspath(os.path.join(
15 os.path.dirname(__file__), os.pardir))) 16 os.path.dirname(__file__), os.pardir)))
16 from pylib import constants 17 from pylib import constants
17 18
18 19
19 def main(): 20 def main():
20 parser = argparse.ArgumentParser() 21 parser = argparse.ArgumentParser()
21 parser.add_argument('--android-sdk-tools', required=True, 22 parser.add_argument('--android-sdk-tools', required=True,
22 help='Android sdk build tools directory.') 23 help='Android sdk build tools directory.')
23 parser.add_argument('--main-dex-rules-path', action='append', default=[], 24 parser.add_argument('--main-dex-rules-path', action='append', default=[],
24 dest='main_dex_rules_paths', 25 dest='main_dex_rules_paths',
25 help='A file containing a list of proguard rules to use ' 26 help='A file containing a list of proguard rules to use '
26 'in determining the class to include in the ' 27 'in determining the class to include in the '
27 'main dex.') 28 'main dex.')
28 parser.add_argument('--main-dex-list-path', required=True, 29 parser.add_argument('--main-dex-list-path', required=True,
29 help='The main dex list file to generate.') 30 help='The main dex list file to generate.')
31 parser.add_argument('--enabled-configurations',
32 help='The build configurations for which a main dex list'
33 ' should be generated.')
34 parser.add_argument('--configuration-name',
35 help='The current build configuration.')
36 parser.add_argument('--multidex-configuration-path',
37 help='A JSON file containing multidex build '
38 'configuration.')
30 parser.add_argument('paths', nargs='+', 39 parser.add_argument('paths', nargs='+',
31 help='JARs for which a main dex list should be ' 40 help='JARs for which a main dex list should be '
32 'generated.') 41 'generated.')
33 42
34 args = parser.parse_args() 43 args = parser.parse_args()
35 44
45 if args.multidex_configuration_path:
46 with open(args.multidex_configuration_path) as multidex_config_file:
47 multidex_config = json.loads(multidex_config_file.read())
48
49 if not multidex_config.get('enabled', False):
50 return 0
51
36 with open(args.main_dex_list_path, 'w') as main_dex_list_file: 52 with open(args.main_dex_list_path, 'w') as main_dex_list_file:
37 53
38 shrinked_android_jar = os.path.abspath( 54 shrinked_android_jar = os.path.abspath(
39 os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar')) 55 os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
40 dx_jar = os.path.abspath( 56 dx_jar = os.path.abspath(
41 os.path.join(args.android_sdk_tools, 'lib', 'dx.jar')) 57 os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))
42 paths_arg = ':'.join(args.paths) 58 paths_arg = ':'.join(args.paths)
43 rules_file = os.path.abspath( 59 rules_file = os.path.abspath(
44 os.path.join(args.android_sdk_tools, 'mainDexClasses.rules')) 60 os.path.join(args.android_sdk_tools, 'mainDexClasses.rules'))
45 61
46 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: 62 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar:
47 proguard_cmd = [ 63 proguard_cmd = [
48 constants.PROGUARD_SCRIPT_PATH, 64 constants.PROGUARD_SCRIPT_PATH,
49 '-forceprocessing', 65 '-forceprocessing',
50 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', 66 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
51 '-injars', paths_arg, 67 '-injars', paths_arg,
52 '-outjars', temp_jar.name, 68 '-outjars', temp_jar.name,
53 '-libraryjars', shrinked_android_jar, 69 '-libraryjars', shrinked_android_jar,
54 '-include', rules_file, 70 '-include', rules_file,
55 ] 71 ]
56 for m in args.main_dex_rules_paths: 72 for m in args.main_dex_rules_paths:
57 proguard_cmd.extend(['-include', m]) 73 proguard_cmd.extend(['-include', m])
58 74
59 main_dex_list = '' 75 main_dex_list = ''
60 try: 76 try:
61 build_utils.CheckOutput(proguard_cmd) 77 build_utils.CheckOutput(proguard_cmd, print_stderr=False)
62 78
63 java_cmd = [ 79 java_cmd = [
64 'java', '-cp', dx_jar, 80 'java', '-cp', dx_jar,
65 'com.android.multidex.MainDexListBuilder', 81 'com.android.multidex.MainDexListBuilder',
66 temp_jar.name, paths_arg 82 temp_jar.name, paths_arg
67 ] 83 ]
68 main_dex_list = build_utils.CheckOutput(java_cmd) 84 main_dex_list = build_utils.CheckOutput(java_cmd)
69 except build_utils.CalledProcessError as e: 85 except build_utils.CalledProcessError as e:
70 if 'output jar is empty' in e.output: 86 if 'output jar is empty' in e.output:
71 pass 87 pass
72 elif "input doesn't contain any classes" in e.output: 88 elif "input doesn't contain any classes" in e.output:
73 pass 89 pass
74 else: 90 else:
75 raise 91 raise
76 92
77 main_dex_list_file.write(main_dex_list) 93 main_dex_list_file.write(main_dex_list)
78 94
79 return 0 95 return 0
80 96
81 97
82 if __name__ == '__main__': 98 if __name__ == '__main__':
83 sys.exit(main()) 99 sys.exit(main())
84 100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698