Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 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 optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import tempfile | |
| 11 import zipfile | |
| 10 | 12 |
| 11 from util import build_utils | 13 from util import build_utils |
| 12 from util import md5_check | 14 from util import md5_check |
| 13 | 15 |
| 14 | 16 |
| 17 def _GenerateMainDexListFile(main_dex_list_file, paths, options): | |
| 18 proguard_binary = os.path.abspath( | |
| 19 os.path.join(options.android_sdk_tools, os.pardir, os.pardir, 'tools', | |
| 20 'proguard', 'bin', 'proguard.sh')) | |
| 21 shrinked_android_jar = os.path.join( | |
| 22 options.android_sdk_tools, 'lib', 'shrinkedAndroid.jar') | |
| 23 dx_jar = os.path.join( | |
| 24 options.android_sdk_tools, 'lib', 'dx.jar') | |
| 25 paths_arg = ':'.join(paths) | |
| 26 rules_file = os.path.abspath(os.path.join( | |
| 27 options.android_sdk_tools, 'mainDexClasses.rules')) | |
| 28 | |
| 29 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: | |
| 30 proguard_cmd = [ | |
|
Yaron
2015/08/10 20:15:40
I hate running proguard in debug mode. :(
What's t
jbudorick
2015/08/10 22:00:49
I tried nuking *.dex* in the chrome_public_apk int
Yaron
2015/08/11 13:38:36
So.. many changes which touch java files are loads
jbudorick
2015/08/11 13:42:21
A what? I'm not sure I follow...
I'm also not thr
| |
| 31 proguard_binary, | |
| 32 '-forceprocessing', | |
| 33 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', | |
| 34 '-injars', paths_arg, | |
| 35 '-outjars', temp_jar.name, | |
| 36 '-libraryjars', shrinked_android_jar, | |
| 37 '-include', rules_file, | |
| 38 ] | |
| 39 for m in options.main_dex_rules_files: | |
| 40 proguard_cmd.extend(['-include', m]) | |
| 41 build_utils.CheckOutput(proguard_cmd) | |
| 42 | |
| 43 java_cmd = ['java', '-cp', dx_jar, | |
| 44 'com.android.multidex.MainDexListBuilder', | |
| 45 temp_jar.name, paths_arg] | |
| 46 main_dex_list = build_utils.CheckOutput(java_cmd) | |
| 47 main_dex_list_file.write(main_dex_list) | |
| 48 main_dex_list_file.flush() | |
| 49 | |
| 50 | |
| 15 def DoDex(options, paths): | 51 def DoDex(options, paths): |
| 16 dx_binary = os.path.join(options.android_sdk_tools, 'dx') | 52 dx_binary = os.path.join(options.android_sdk_tools, 'dx') |
| 17 # See http://crbug.com/272064 for context on --force-jumbo. | 53 # See http://crbug.com/272064 for context on --force-jumbo. |
| 18 dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path] | 54 dex_cmd = [dx_binary, '--dex', '--force-jumbo'] |
| 19 if options.no_locals != '0': | 55 if options.no_locals != '0': |
| 20 dex_cmd.append('--no-locals') | 56 dex_cmd.append('--no-locals') |
| 57 with tempfile.NamedTemporaryFile() as main_dex_list_file: | |
| 58 if options.multi_dex: | |
| 59 _GenerateMainDexListFile(main_dex_list_file, paths, options) | |
| 21 | 60 |
| 22 dex_cmd += paths | 61 dex_cmd.append('--multi-dex') |
| 62 dex_cmd.append('--minimal-main-dex') | |
| 63 dex_cmd.append('--main-dex-list=%s' % main_dex_list_file.name) | |
| 23 | 64 |
| 24 record_path = '%s.md5.stamp' % options.dex_path | 65 dex_cmd += ['--output', options.dex_path] |
| 25 md5_check.CallAndRecordIfStale( | 66 dex_cmd += paths |
| 26 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False), | 67 |
| 27 record_path=record_path, | 68 record_path = '%s.md5.stamp' % options.dex_path |
| 28 input_paths=paths, | 69 md5_check.CallAndRecordIfStale( |
| 29 input_strings=dex_cmd, | 70 lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False), |
| 30 force=not os.path.exists(options.dex_path)) | 71 record_path=record_path, |
| 31 build_utils.WriteJson( | 72 input_paths=paths, |
| 32 [os.path.relpath(p, options.output_directory) for p in paths], | 73 input_strings=dex_cmd, |
| 33 options.dex_path + '.inputs') | 74 force=not os.path.exists(options.dex_path)) |
| 75 build_utils.WriteJson( | |
| 76 [os.path.relpath(p, options.output_directory) for p in paths], | |
| 77 options.dex_path + '.inputs') | |
| 78 | |
| 79 if options.multi_dex and options.dex_path.endswith('.zip'): | |
| 80 iz = zipfile.ZipFile(options.dex_path, 'r') | |
| 81 tmp_dex_path = '%s.tmp.zip' % options.dex_path | |
| 82 oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) | |
| 83 for i in iz.namelist(): | |
| 84 if i.endswith('.dex'): | |
| 85 oz.writestr(i, iz.read(i)) | |
| 86 os.remove(options.dex_path) | |
| 87 os.rename(tmp_dex_path, options.dex_path) | |
| 34 | 88 |
| 35 | 89 |
| 36 def main(): | 90 def main(): |
| 37 args = build_utils.ExpandFileArgs(sys.argv[1:]) | 91 args = build_utils.ExpandFileArgs(sys.argv[1:]) |
| 38 | 92 |
| 39 parser = optparse.OptionParser() | 93 parser = optparse.OptionParser() |
| 40 build_utils.AddDepfileOption(parser) | 94 build_utils.AddDepfileOption(parser) |
| 41 | 95 |
| 42 parser.add_option('--android-sdk-tools', | 96 parser.add_option('--android-sdk-tools', |
| 43 help='Android sdk build tools directory.') | 97 help='Android sdk build tools directory.') |
| 44 parser.add_option('--output-directory', | 98 parser.add_option('--output-directory', |
| 45 default=os.getcwd(), | 99 default=os.getcwd(), |
| 46 help='Path to the output build directory.') | 100 help='Path to the output build directory.') |
| 47 parser.add_option('--dex-path', help='Dex output path.') | 101 parser.add_option('--dex-path', help='Dex output path.') |
| 48 parser.add_option('--configuration-name', | 102 parser.add_option('--configuration-name', |
| 49 help='The build CONFIGURATION_NAME.') | 103 help='The build CONFIGURATION_NAME.') |
| 50 parser.add_option('--proguard-enabled', | 104 parser.add_option('--proguard-enabled', |
| 51 help='"true" if proguard is enabled.') | 105 help='"true" if proguard is enabled.') |
| 52 parser.add_option('--proguard-enabled-input-path', | 106 parser.add_option('--proguard-enabled-input-path', |
| 53 help=('Path to dex in Release mode when proguard ' | 107 help=('Path to dex in Release mode when proguard ' |
| 54 'is enabled.')) | 108 'is enabled.')) |
| 55 parser.add_option('--no-locals', | 109 parser.add_option('--no-locals', |
| 56 help='Exclude locals list from the dex file.') | 110 help='Exclude locals list from the dex file.') |
| 111 parser.add_option('--multi-dex', default=False, action='store_true', | |
| 112 help='Create multiple dex files.') | |
| 57 parser.add_option('--inputs', help='A list of additional input paths.') | 113 parser.add_option('--inputs', help='A list of additional input paths.') |
| 58 parser.add_option('--excluded-paths', | 114 parser.add_option('--excluded-paths', |
| 59 help='A list of paths to exclude from the dex file.') | 115 help='A list of paths to exclude from the dex file.') |
| 116 parser.add_option('--main-dex-rules-file', | |
| 117 action='append', | |
| 118 default=[], | |
| 119 dest='main_dex_rules_files', | |
| 120 help='A file containing a list of proguard rules to use ' | |
| 121 'in determining the classes to include in the ' | |
| 122 'main dex.') | |
| 60 | 123 |
| 61 options, paths = parser.parse_args(args) | 124 options, paths = parser.parse_args(args) |
| 62 | 125 |
| 63 required_options = ('android_sdk_tools',) | 126 required_options = ('android_sdk_tools',) |
| 64 build_utils.CheckOptions(options, parser, required=required_options) | 127 build_utils.CheckOptions(options, parser, required=required_options) |
| 65 | 128 |
| 66 if (options.proguard_enabled == 'true' | 129 if (options.proguard_enabled == 'true' |
| 67 and options.configuration_name == 'Release'): | 130 and options.configuration_name == 'Release'): |
| 68 paths = [options.proguard_enabled_input_path] | 131 paths = [options.proguard_enabled_input_path] |
| 69 | 132 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 80 | 143 |
| 81 if options.depfile: | 144 if options.depfile: |
| 82 build_utils.WriteDepfile( | 145 build_utils.WriteDepfile( |
| 83 options.depfile, | 146 options.depfile, |
| 84 paths + build_utils.GetPythonDependencies()) | 147 paths + build_utils.GetPythonDependencies()) |
| 85 | 148 |
| 86 | 149 |
| 87 | 150 |
| 88 if __name__ == '__main__': | 151 if __name__ == '__main__': |
| 89 sys.exit(main()) | 152 sys.exit(main()) |
| OLD | NEW |