cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / build / android / gyp / main_dex_list.py
blob64420019eb905f6e5318837e32ad95ca908ddd83
1 #!/usr/bin/env python
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
5 # found in the LICENSE file.
7 import argparse
8 import os
9 import sys
10 import tempfile
12 from util import build_utils
14 sys.path.append(os.path.abspath(os.path.join(
15 os.path.dirname(__file__), os.pardir)))
16 from pylib import constants
19 def main():
20 parser = argparse.ArgumentParser()
21 parser.add_argument('--android-sdk-tools', required=True,
22 help='Android sdk build tools directory.')
23 parser.add_argument('--main-dex-rules-path', action='append', default=[],
24 dest='main_dex_rules_paths',
25 help='A file containing a list of proguard rules to use '
26 'in determining the class to include in the '
27 'main dex.')
28 parser.add_argument('--main-dex-list-path', required=True,
29 help='The main dex list file to generate.')
30 parser.add_argument('paths', nargs='+',
31 help='JARs for which a main dex list should be '
32 'generated.')
34 args = parser.parse_args()
36 with open(args.main_dex_list_path, 'w') as main_dex_list_file:
38 shrinked_android_jar = os.path.abspath(
39 os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
40 dx_jar = os.path.abspath(
41 os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))
42 paths_arg = ':'.join(args.paths)
43 rules_file = os.path.abspath(
44 os.path.join(args.android_sdk_tools, 'mainDexClasses.rules'))
46 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar:
47 proguard_cmd = [
48 constants.PROGUARD_SCRIPT_PATH,
49 '-forceprocessing',
50 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
51 '-injars', paths_arg,
52 '-outjars', temp_jar.name,
53 '-libraryjars', shrinked_android_jar,
54 '-include', rules_file,
56 for m in args.main_dex_rules_paths:
57 proguard_cmd.extend(['-include', m])
59 main_dex_list = ''
60 try:
61 build_utils.CheckOutput(proguard_cmd)
63 java_cmd = [
64 'java', '-cp', dx_jar,
65 'com.android.multidex.MainDexListBuilder',
66 temp_jar.name, paths_arg
68 main_dex_list = build_utils.CheckOutput(java_cmd)
69 except build_utils.CalledProcessError as e:
70 if 'output jar is empty' in e.output:
71 pass
72 elif "input doesn't contain any classes" in e.output:
73 pass
74 else:
75 raise
77 main_dex_list_file.write(main_dex_list)
79 return 0
82 if __name__ == '__main__':
83 sys.exit(main())