| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 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 """Adds the code parts to a resource APK.""" | 7 """Adds the code parts to a resource APK.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import itertools | 10 import itertools |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 help='Path to the classes.dex to use') | 44 help='Path to the classes.dex to use') |
| 45 # TODO(agrieve): Switch this to be a list of files rather than a directory. | 45 # TODO(agrieve): Switch this to be a list of files rather than a directory. |
| 46 parser.add_argument('--native-libs-dir', | 46 parser.add_argument('--native-libs-dir', |
| 47 help='Directory containing native libraries to include', | 47 help='Directory containing native libraries to include', |
| 48 default=[]) | 48 default=[]) |
| 49 parser.add_argument('--android-abi', | 49 parser.add_argument('--android-abi', |
| 50 help='Android architecture to use for native libraries') | 50 help='Android architecture to use for native libraries') |
| 51 parser.add_argument('--native-lib-placeholders', | 51 parser.add_argument('--native-lib-placeholders', |
| 52 help='GYP-list of native library placeholders to add.', | 52 help='GYP-list of native library placeholders to add.', |
| 53 default='[]') | 53 default='[]') |
| 54 parser.add_argument('--emma-device-jar', |
| 55 help='Path to emma_device.jar to include.') |
| 54 options = parser.parse_args(args) | 56 options = parser.parse_args(args) |
| 55 options.assets = build_utils.ParseGypList(options.assets) | 57 options.assets = build_utils.ParseGypList(options.assets) |
| 56 options.uncompressed_assets = build_utils.ParseGypList( | 58 options.uncompressed_assets = build_utils.ParseGypList( |
| 57 options.uncompressed_assets) | 59 options.uncompressed_assets) |
| 58 options.native_lib_placeholders = build_utils.ParseGypList( | 60 options.native_lib_placeholders = build_utils.ParseGypList( |
| 59 options.native_lib_placeholders) | 61 options.native_lib_placeholders) |
| 60 | 62 |
| 61 if not options.android_abi and (options.native_libs_dir or | 63 if not options.android_abi and (options.native_libs_dir or |
| 62 options.native_lib_placeholders): | 64 options.native_lib_placeholders): |
| 63 raise Exception('Must specify --android-abi with --native-libs-dir') | 65 raise Exception('Must specify --android-abi with --native-libs-dir') |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 options = _ParseArgs(args) | 117 options = _ParseArgs(args) |
| 116 | 118 |
| 117 native_libs = [] | 119 native_libs = [] |
| 118 if options.native_libs_dir: | 120 if options.native_libs_dir: |
| 119 native_libs = _ListSubPaths(options.native_libs_dir) | 121 native_libs = _ListSubPaths(options.native_libs_dir) |
| 120 | 122 |
| 121 input_paths = [options.resource_apk, __file__] + native_libs | 123 input_paths = [options.resource_apk, __file__] + native_libs |
| 122 if options.dex_file: | 124 if options.dex_file: |
| 123 input_paths.append(options.dex_file) | 125 input_paths.append(options.dex_file) |
| 124 | 126 |
| 127 if options.emma_device_jar: |
| 128 input_paths.append(options.emma_device_jar) |
| 129 |
| 125 input_strings = [options.android_abi, options.native_lib_placeholders] | 130 input_strings = [options.android_abi, options.native_lib_placeholders] |
| 126 | 131 |
| 127 for path in itertools.chain(options.assets, options.uncompressed_assets): | 132 for path in itertools.chain(options.assets, options.uncompressed_assets): |
| 128 src_path, dest_path = _SplitAssetPath(path) | 133 src_path, dest_path = _SplitAssetPath(path) |
| 129 input_paths.append(src_path) | 134 input_paths.append(src_path) |
| 130 input_strings.append(dest_path) | 135 input_strings.append(dest_path) |
| 131 | 136 |
| 132 def on_stale_md5(): | 137 def on_stale_md5(): |
| 133 tmp_apk = options.output_apk + '.tmp' | 138 tmp_apk = options.output_apk + '.tmp' |
| 134 try: | 139 try: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 145 basename = os.path.basename(path) | 150 basename = os.path.basename(path) |
| 146 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename)) | 151 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename)) |
| 147 for name in options.native_lib_placeholders: | 152 for name in options.native_lib_placeholders: |
| 148 # Make it non-empty so that its checksum is non-zero and is not | 153 # Make it non-empty so that its checksum is non-zero and is not |
| 149 # ignored by md5_check. | 154 # ignored by md5_check. |
| 150 apk.writestr('lib/%s/%s' % (options.android_abi, name), ':)', | 155 apk.writestr('lib/%s/%s' % (options.android_abi, name), ':)', |
| 151 zipfile.ZIP_STORED) | 156 zipfile.ZIP_STORED) |
| 152 if options.dex_file: | 157 if options.dex_file: |
| 153 apk.write(options.dex_file, 'classes.dex') | 158 apk.write(options.dex_file, 'classes.dex') |
| 154 | 159 |
| 160 if options.emma_device_jar: |
| 161 # Add EMMA Java resources to APK. |
| 162 with zipfile.ZipFile(options.emma_device_jar, 'r') as emma_device_jar: |
| 163 for emma_device_jar_entry in emma_device_jar.namelist(): |
| 164 entry_name_lower = emma_device_jar_entry.lower() |
| 165 if entry_name_lower.startswith('meta-inf/'): |
| 166 continue |
| 167 |
| 168 if entry_name_lower.endswith('/'): |
| 169 continue |
| 170 |
| 171 if entry_name_lower.endswith('.class'): |
| 172 continue |
| 173 |
| 174 apk.writestr(emma_device_jar_entry, |
| 175 emma_device_jar.read(emma_device_jar_entry)) |
| 176 |
| 155 shutil.move(tmp_apk, options.output_apk) | 177 shutil.move(tmp_apk, options.output_apk) |
| 156 finally: | 178 finally: |
| 157 if os.path.exists(tmp_apk): | 179 if os.path.exists(tmp_apk): |
| 158 os.unlink(tmp_apk) | 180 os.unlink(tmp_apk) |
| 159 | 181 |
| 160 build_utils.CallAndWriteDepfileIfStale( | 182 build_utils.CallAndWriteDepfileIfStale( |
| 161 on_stale_md5, | 183 on_stale_md5, |
| 162 options, | 184 options, |
| 163 input_paths=input_paths, | 185 input_paths=input_paths, |
| 164 input_strings=input_strings, | 186 input_strings=input_strings, |
| 165 output_paths=[options.output_apk]) | 187 output_paths=[options.output_apk]) |
| 166 | 188 |
| 167 | 189 |
| 168 if __name__ == '__main__': | 190 if __name__ == '__main__': |
| 169 main(sys.argv[1:]) | 191 main(sys.argv[1:]) |
| OLD | NEW |