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

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: no-op ChromiumMultiDex.install for non-multidex builds 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 args.paths.extend(multidex_config.get('libs', []))
52
36 with open(args.main_dex_list_path, 'w') as main_dex_list_file: 53 with open(args.main_dex_list_path, 'w') as main_dex_list_file:
37 54
38 shrinked_android_jar = os.path.abspath( 55 shrinked_android_jar = os.path.abspath(
39 os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar')) 56 os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
40 dx_jar = os.path.abspath( 57 dx_jar = os.path.abspath(
41 os.path.join(args.android_sdk_tools, 'lib', 'dx.jar')) 58 os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))
42 paths_arg = ':'.join(args.paths) 59 paths_arg = ':'.join(args.paths)
43 rules_file = os.path.abspath( 60 rules_file = os.path.abspath(
44 os.path.join(args.android_sdk_tools, 'mainDexClasses.rules')) 61 os.path.join(args.android_sdk_tools, 'mainDexClasses.rules'))
45 62
46 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: 63 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar:
47 proguard_cmd = [ 64 proguard_cmd = [
48 constants.PROGUARD_SCRIPT_PATH, 65 constants.PROGUARD_SCRIPT_PATH,
49 '-forceprocessing', 66 '-forceprocessing',
50 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', 67 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
51 '-injars', paths_arg, 68 '-injars', paths_arg,
52 '-outjars', temp_jar.name, 69 '-outjars', temp_jar.name,
53 '-libraryjars', shrinked_android_jar, 70 '-libraryjars', shrinked_android_jar,
54 '-include', rules_file, 71 '-include', rules_file,
55 ] 72 ]
56 for m in args.main_dex_rules_paths: 73 for m in args.main_dex_rules_paths:
57 proguard_cmd.extend(['-include', m]) 74 proguard_cmd.extend(['-include', m])
58 75
59 main_dex_list = '' 76 main_dex_list = ''
60 try: 77 try:
61 build_utils.CheckOutput(proguard_cmd) 78 build_utils.CheckOutput(proguard_cmd, print_stderr=False)
62 79
63 java_cmd = [ 80 java_cmd = [
64 'java', '-cp', dx_jar, 81 'java', '-cp', dx_jar,
65 'com.android.multidex.MainDexListBuilder', 82 'com.android.multidex.MainDexListBuilder',
66 temp_jar.name, paths_arg 83 temp_jar.name, paths_arg
67 ] 84 ]
68 main_dex_list = build_utils.CheckOutput(java_cmd) 85 main_dex_list = build_utils.CheckOutput(java_cmd)
69 except build_utils.CalledProcessError as e: 86 except build_utils.CalledProcessError as e:
70 if 'output jar is empty' in e.output: 87 if 'output jar is empty' in e.output:
71 pass 88 pass
72 elif "input doesn't contain any classes" in e.output: 89 elif "input doesn't contain any classes" in e.output:
73 pass 90 pass
74 else: 91 else:
75 raise 92 raise
76 93
77 main_dex_list_file.write(main_dex_list) 94 main_dex_list_file.write(main_dex_list)
78 95
79 return 0 96 return 0
80 97
81 98
82 if __name__ == '__main__': 99 if __name__ == '__main__':
83 sys.exit(main()) 100 sys.exit(main())
84 101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698