OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
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. | |
6 | |
7 import argparse | |
8 import os | |
9 import sys | |
10 import tempfile | |
11 | |
12 from util import build_utils | |
13 | |
14 | |
15 def main(): | |
16 parser = argparse.ArgumentParser() | |
17 parser.add_argument('--main-dex-rules-path', action='append', default=[], | |
18 dest='main_dex_rules_paths', | |
19 help='A file containing a list of proguard rules to use ' | |
20 'in determining the class to include in the ' | |
21 'main dex.') | |
22 parser.add_argument('--main-dex-list-path', required=True, | |
23 help='The main dex list file to generate.') | |
24 parser.add_argument('--android-sdk-tools', required=True, | |
25 help='Android sdk build tools directory.') | |
26 parser.add_argument('paths', nargs='+', | |
27 help='JARs for which a main dex list should be ' | |
28 'generated.') | |
29 | |
30 args = parser.parse_args() | |
31 | |
32 with open(args.main_dex_list_path, 'w') as main_dex_list_file: | |
33 | |
34 proguard_binary = os.path.abspath( | |
35 os.path.join(args.android_sdk_tools, os.pardir, os.pardir, 'tools', | |
Yaron
2015/08/13 20:12:10
we're about to introduce a new proguard path: http
jbudorick
2015/08/14 21:01:21
done
| |
36 'proguard', 'bin', 'proguard.sh')) | |
37 shrinked_android_jar = os.path.join( | |
38 args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar') | |
39 dx_jar = os.path.join( | |
40 args.android_sdk_tools, 'lib', 'dx.jar') | |
41 paths_arg = ':'.join(args.paths) | |
42 rules_file = os.path.abspath(os.path.join( | |
43 args.android_sdk_tools, 'mainDexClasses.rules')) | |
44 | |
45 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: | |
46 proguard_cmd = [ | |
47 proguard_binary, | |
48 '-forceprocessing', | |
49 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', | |
50 '-injars', paths_arg, | |
51 '-outjars', temp_jar.name, | |
52 '-libraryjars', shrinked_android_jar, | |
53 '-include', rules_file, | |
54 ] | |
55 for m in args.main_dex_rules_paths: | |
56 proguard_cmd.extend(['-include', m]) | |
57 | |
58 main_dex_list = '' | |
59 try: | |
60 build_utils.CheckOutput(proguard_cmd) | |
61 | |
62 java_cmd = [ | |
63 'java', '-cp', dx_jar, | |
64 'com.android.multidex.MainDexListBuilder', | |
65 temp_jar.name, paths_arg | |
66 ] | |
67 main_dex_list = build_utils.CheckOutput(java_cmd) | |
68 except build_utils.CalledProcessError as e: | |
69 if 'output jar is empty' in e.output: | |
70 pass | |
71 elif "input doesn't contain any classes" in e.output: | |
72 pass | |
73 else: | |
74 raise | |
75 | |
76 main_dex_list_file.write(main_dex_list) | |
77 | |
78 return 0 | |
79 | |
80 | |
81 if __name__ == '__main__': | |
82 sys.exit(main()) | |
83 | |
OLD | NEW |