| OLD | NEW |
| 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 json |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 build_utils.AddDepfileOption(parser) | 22 build_utils.AddDepfileOption(parser) |
| 23 parser.add_argument('--android-sdk-tools', required=True, | 23 parser.add_argument('--android-sdk-tools', required=True, |
| 24 help='Android sdk build tools directory.') | 24 help='Android sdk build tools directory.') |
| 25 parser.add_argument('--main-dex-rules-path', action='append', default=[], | 25 parser.add_argument('--main-dex-rules-path', action='append', default=[], |
| 26 dest='main_dex_rules_paths', | 26 dest='main_dex_rules_paths', |
| 27 help='A file containing a list of proguard rules to use ' | 27 help='A file containing a list of proguard rules to use ' |
| 28 'in determining the class to include in the ' | 28 'in determining the class to include in the ' |
| 29 'main dex.') | 29 'main dex.') |
| 30 parser.add_argument('--main-dex-list-path', required=True, | 30 parser.add_argument('--main-dex-list-path', required=True, |
| 31 help='The main dex list file to generate.') | 31 help='The main dex list file to generate.') |
| 32 parser.add_argument('--main-dex-list-path-java', required=True, |
| 33 help='The main dex list file to generate.') |
| 32 parser.add_argument('--enabled-configurations', | 34 parser.add_argument('--enabled-configurations', |
| 33 help='The build configurations for which a main dex list' | 35 help='The build configurations for which a main dex list' |
| 34 ' should be generated.') | 36 ' should be generated.') |
| 35 parser.add_argument('--configuration-name', | 37 parser.add_argument('--configuration-name', |
| 36 help='The current build configuration.') | 38 help='The current build configuration.') |
| 37 parser.add_argument('--multidex-configuration-path', | 39 parser.add_argument('--multidex-configuration-path', |
| 38 help='A JSON file containing multidex build ' | 40 help='A JSON file containing multidex build ' |
| 39 'configuration.') | 41 'configuration.') |
| 40 parser.add_argument('--inputs', | 42 parser.add_argument('--inputs', |
| 41 help='JARs for which a main dex list should be ' | 43 help='JARs for which a main dex list should be ' |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 proguard_cmd, | 95 proguard_cmd, |
| 94 main_dex_list_cmd, | 96 main_dex_list_cmd, |
| 95 ] | 97 ] |
| 96 | 98 |
| 97 output_paths = [ | 99 output_paths = [ |
| 98 args.main_dex_list_path, | 100 args.main_dex_list_path, |
| 99 ] | 101 ] |
| 100 | 102 |
| 101 build_utils.CallAndWriteDepfileIfStale( | 103 build_utils.CallAndWriteDepfileIfStale( |
| 102 lambda: _OnStaleMd5(proguard_cmd, main_dex_list_cmd, args.paths, | 104 lambda: _OnStaleMd5(proguard_cmd, main_dex_list_cmd, args.paths, |
| 103 args.main_dex_list_path), | 105 args.main_dex_list_path, args.main_dex_list_path_java)
, |
| 104 args, | 106 args, |
| 105 input_paths=input_paths, | 107 input_paths=input_paths, |
| 106 input_strings=input_strings, | 108 input_strings=input_strings, |
| 107 output_paths=output_paths) | 109 output_paths=output_paths) |
| 108 | 110 |
| 109 return 0 | 111 return 0 |
| 110 | 112 |
| 111 | 113 |
| 112 def _OnStaleMd5(proguard_cmd, main_dex_list_cmd, paths, main_dex_list_path): | 114 def _OnStaleMd5(proguard_cmd, main_dex_list_cmd, paths, main_dex_list_path, main
_dex_list_path_java): |
| 113 paths_arg = ':'.join(paths) | 115 paths_arg = ':'.join(paths) |
| 114 main_dex_list = '' | 116 main_dex_list = '' |
| 115 try: | 117 try: |
| 116 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: | 118 with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: |
| 117 proguard_cmd += [ | 119 proguard_cmd += [ |
| 118 '-injars', paths_arg, | 120 '-injars', paths_arg, |
| 119 '-outjars', temp_jar.name | 121 '-outjars', temp_jar.name |
| 120 ] | 122 ] |
| 121 build_utils.CheckOutput(proguard_cmd, print_stderr=False) | 123 build_utils.CheckOutput(proguard_cmd, print_stderr=False) |
| 122 | 124 |
| 123 main_dex_list_cmd += [ | 125 main_dex_list_cmd += [ |
| 124 temp_jar.name, paths_arg | 126 temp_jar.name, paths_arg |
| 125 ] | 127 ] |
| 126 main_dex_list = build_utils.CheckOutput(main_dex_list_cmd) | 128 main_dex_list = build_utils.CheckOutput(main_dex_list_cmd) |
| 127 except build_utils.CalledProcessError as e: | 129 except build_utils.CalledProcessError as e: |
| 128 if 'output jar is empty' in e.output: | 130 if 'output jar is empty' in e.output: |
| 129 pass | 131 pass |
| 130 elif "input doesn't contain any classes" in e.output: | 132 elif "input doesn't contain any classes" in e.output: |
| 131 pass | 133 pass |
| 132 else: | 134 else: |
| 133 raise | 135 raise |
| 134 | 136 |
| 137 tmp = [] |
| 138 for line in main_dex_list.split('\n'): |
| 139 if 'FileDescriptorInfo' not in line: |
| 140 tmp.append(line) |
| 141 main_dex_list = '\n'.join(l for l in tmp) |
| 142 |
| 135 with open(main_dex_list_path, 'w') as main_dex_list_file: | 143 with open(main_dex_list_path, 'w') as main_dex_list_file: |
| 136 main_dex_list_file.write(main_dex_list) | 144 main_dex_list_file.write(main_dex_list) |
| 137 | 145 |
| 146 if main_dex_list_path_java: |
| 147 with open(main_dex_list_path_java, 'w') as main_dex_list_file: |
| 148 main_dex_list_file.write( |
| 149 ','.join([c.replace('/', '.').split('.class')[0] |
| 150 for c in main_dex_list.split('\n')])) |
| 138 | 151 |
| 139 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 140 sys.exit(main(sys.argv[1:])) | 153 sys.exit(main(sys.argv[1:])) |
| 141 | 154 |
| OLD | NEW |