| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ Merges a 64-bit and a 32-bit APK into a single APK | 6 """ Merges a 64-bit and a 32-bit APK into a single APK |
| 7 | 7 |
| 8 This script is used to merge two APKs which have only 32-bit or 64-bit | 8 This script is used to merge two APKs which have only 32-bit or 64-bit |
| 9 binaries respectively into a APK that has both 32-bit and 64-bit binaries | 9 binaries respectively into a APK that has both 32-bit and 64-bit binaries |
| 10 for 64-bit Android platform. | 10 for 64-bit Android platform. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 compress = not uncompress_shared_libraries | 128 compress = not uncompress_shared_libraries |
| 129 else: | 129 else: |
| 130 compress = expected_files[os.path.basename(diff_file)] | 130 compress = expected_files[os.path.basename(diff_file)] |
| 131 build_utils.AddToZipHermetic(out_zip, | 131 build_utils.AddToZipHermetic(out_zip, |
| 132 diff_file, | 132 diff_file, |
| 133 os.path.join(tmp_dir_32, diff_file), | 133 os.path.join(tmp_dir_32, diff_file), |
| 134 compress=compress) | 134 compress=compress) |
| 135 | 135 |
| 136 | 136 |
| 137 def SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, zipalign_path, | 137 def SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, zipalign_path, |
| 138 keystore_path, key_name, key_password, | 138 keystore_path, key_name, key_password): |
| 139 page_align_shared_libraries): | |
| 140 try: | 139 try: |
| 141 finalize_apk.JarSigner( | 140 finalize_apk.JarSigner( |
| 142 keystore_path, | 141 keystore_path, |
| 143 key_name, | 142 key_name, |
| 144 key_password, | 143 key_password, |
| 145 tmp_apk, | 144 tmp_apk, |
| 146 signed_tmp_apk) | 145 signed_tmp_apk) |
| 147 except build_utils.CalledProcessError as e: | 146 except build_utils.CalledProcessError as e: |
| 148 raise ApkMergeFailure('Failed to sign APK: ' + e.output) | 147 raise ApkMergeFailure('Failed to sign APK: ' + e.output) |
| 149 | 148 |
| 150 try: | 149 try: |
| 151 finalize_apk.AlignApk(zipalign_path, | 150 finalize_apk.AlignApk(zipalign_path, |
| 152 page_align_shared_libraries, | |
| 153 signed_tmp_apk, | 151 signed_tmp_apk, |
| 154 new_apk) | 152 new_apk) |
| 155 except build_utils.CalledProcessError as e: | 153 except build_utils.CalledProcessError as e: |
| 156 raise ApkMergeFailure('Failed to align APK: ' + e.output) | 154 raise ApkMergeFailure('Failed to align APK: ' + e.output) |
| 157 | 155 |
| 158 def GetSecondaryAbi(apk_zipfile, shared_library): | 156 def GetSecondaryAbi(apk_zipfile, shared_library): |
| 159 ret = '' | 157 ret = '' |
| 160 for name in apk_zipfile.namelist(): | 158 for name in apk_zipfile.namelist(): |
| 161 if os.path.basename(name) == shared_library: | 159 if os.path.basename(name) == shared_library: |
| 162 abi = re.search('(^lib/)(.+)(/' + shared_library + '$)', name).group(2) | 160 abi = re.search('(^lib/)(.+)(/' + shared_library + '$)', name).group(2) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 # Using type=os.path.abspath converts file paths to absolute paths so that | 215 # Using type=os.path.abspath converts file paths to absolute paths so that |
| 218 # we can change working directory without affecting these paths | 216 # we can change working directory without affecting these paths |
| 219 parser.add_argument('--apk_32bit', required=True, type=os.path.abspath) | 217 parser.add_argument('--apk_32bit', required=True, type=os.path.abspath) |
| 220 parser.add_argument('--apk_64bit', required=True, type=os.path.abspath) | 218 parser.add_argument('--apk_64bit', required=True, type=os.path.abspath) |
| 221 parser.add_argument('--out_apk', required=True, type=os.path.abspath) | 219 parser.add_argument('--out_apk', required=True, type=os.path.abspath) |
| 222 parser.add_argument('--zipalign_path', required=True, type=os.path.abspath) | 220 parser.add_argument('--zipalign_path', required=True, type=os.path.abspath) |
| 223 parser.add_argument('--keystore_path', required=True, type=os.path.abspath) | 221 parser.add_argument('--keystore_path', required=True, type=os.path.abspath) |
| 224 parser.add_argument('--key_name', required=True) | 222 parser.add_argument('--key_name', required=True) |
| 225 parser.add_argument('--key_password', required=True) | 223 parser.add_argument('--key_password', required=True) |
| 226 parser.add_argument('--shared_library') | 224 parser.add_argument('--shared_library') |
| 227 parser.add_argument('--page-align-shared-libraries', action='store_true') | 225 parser.add_argument('--page-align-shared-libraries', action='store_true', |
| 226 help='Obsolete, but remains for backwards compatibility') |
| 228 parser.add_argument('--uncompress-shared-libraries', action='store_true') | 227 parser.add_argument('--uncompress-shared-libraries', action='store_true') |
| 229 parser.add_argument('--debug', action='store_true') | 228 parser.add_argument('--debug', action='store_true') |
| 230 # This option shall only used in debug build, see http://crbug.com/631494. | 229 # This option shall only used in debug build, see http://crbug.com/631494. |
| 231 parser.add_argument('--ignore-classes-dex', action='store_true') | 230 parser.add_argument('--ignore-classes-dex', action='store_true') |
| 232 parser.add_argument('--component-build', action='store_true') | 231 parser.add_argument('--component-build', action='store_true') |
| 233 args = parser.parse_args() | 232 args = parser.parse_args() |
| 234 | 233 |
| 235 tmp_dir = tempfile.mkdtemp() | 234 tmp_dir = tempfile.mkdtemp() |
| 236 tmp_dir_64 = os.path.join(tmp_dir, '64_bit') | 235 tmp_dir_64 = os.path.join(tmp_dir, '64_bit') |
| 237 tmp_dir_32 = os.path.join(tmp_dir, '32_bit') | 236 tmp_dir_32 = os.path.join(tmp_dir, '32_bit') |
| 238 tmp_apk = os.path.join(tmp_dir, 'tmp.apk') | 237 tmp_apk = os.path.join(tmp_dir, 'tmp.apk') |
| 239 signed_tmp_apk = os.path.join(tmp_dir, 'signed.apk') | 238 signed_tmp_apk = os.path.join(tmp_dir, 'signed.apk') |
| 240 new_apk = args.out_apk | 239 new_apk = args.out_apk |
| 241 | 240 |
| 242 try: | 241 try: |
| 243 if args.component_build and args.shared_library: | 242 if args.component_build and args.shared_library: |
| 244 raise ApkMergeFailure('--component-build and shared-library shouldn\'t' | 243 raise ApkMergeFailure('--component-build and shared-library shouldn\'t' |
| 245 ' be specified at same time.') | 244 ' be specified at same time.') |
| 246 if not args.component_build and not args.shared_library: | 245 if not args.component_build and not args.shared_library: |
| 247 raise ApkMergeFailure('Either --component-build or shared-library should' | 246 raise ApkMergeFailure('Either --component-build or shared-library should' |
| 248 ' be specified.') | 247 ' be specified.') |
| 249 | 248 |
| 250 MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64) | 249 MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64) |
| 251 | 250 |
| 252 SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, args.zipalign_path, | 251 SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, args.zipalign_path, |
| 253 args.keystore_path, args.key_name, args.key_password, | 252 args.keystore_path, args.key_name, args.key_password) |
| 254 args.page_align_shared_libraries) | |
| 255 | 253 |
| 256 except ApkMergeFailure as e: | 254 except ApkMergeFailure as e: |
| 257 print e | 255 print e |
| 258 return 1 | 256 return 1 |
| 259 finally: | 257 finally: |
| 260 shutil.rmtree(tmp_dir) | 258 shutil.rmtree(tmp_dir) |
| 261 return 0 | 259 return 0 |
| 262 | 260 |
| 263 | 261 |
| 264 if __name__ == '__main__': | 262 if __name__ == '__main__': |
| 265 sys.exit(main()) | 263 sys.exit(main()) |
| OLD | NEW |