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