Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: android_webview/tools/apk_merger.py

Issue 2629663003: Reland of Android: Delete rezip in favor of zipalign -p (Closed)
Patch Set: no gdbserver Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | build/android/gyp/apkbuilder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
163 # Intentionally not to add 64bit abi because they are not used. 161 # Intentionally not to add 64bit abi because they are not used.
164 if abi == 'armeabi-v7a' or abi == 'armeabi': 162 if abi == 'armeabi-v7a' or abi == 'armeabi':
165 ret = 'arm64-v8a' 163 ret = 'arm64-v8a'
166 elif abi == 'mips': 164 elif abi == 'mips':
167 ret = 'mips64' 165 ret = 'mips64'
168 elif abi == 'x86': 166 elif abi == 'x86':
169 ret = 'x86_64' 167 ret = 'x86_64'
170 else: 168 else:
171 raise ApkMergeFailure('Unsupported abi ' + abi) 169 raise ApkMergeFailure('Unsupported abi ' + abi)
172 if ret == '': 170 if ret == '':
173 raise ApkMergeFailure('Failed to find secondary abi') 171 raise ApkMergeFailure('Failed to find secondary abi')
174 return ret 172 return ret
175 173
176 def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64): 174 def MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64):
177 # Expected files to copy from 32- to 64-bit APK together with whether to 175 # Expected files to copy from 32- to 64-bit APK together with whether to
178 # compress within the .apk. 176 # compress within the .apk.
179 expected_files = {'snapshot_blob_32.bin': False} 177 expected_files = {'snapshot_blob_32.bin': False}
180 if args.shared_library: 178 if args.shared_library:
181 expected_files[args.shared_library] = not args.uncompress_shared_libraries 179 expected_files[args.shared_library] = not args.uncompress_shared_libraries
182 if args.debug:
183 expected_files['gdbserver'] = True
184 180
185 # need to unpack APKs to compare their contents 181 # need to unpack APKs to compare their contents
186 UnpackApk(args.apk_64bit, tmp_dir_64) 182 UnpackApk(args.apk_64bit, tmp_dir_64)
187 UnpackApk(args.apk_32bit, tmp_dir_32) 183 UnpackApk(args.apk_32bit, tmp_dir_32)
188 184
189 ignores = ['META-INF', 'AndroidManifest.xml'] 185 ignores = ['META-INF', 'AndroidManifest.xml']
190 if args.ignore_classes_dex: 186 if args.ignore_classes_dex:
191 ignores += ['classes.dex', 'classes2.dex'] 187 ignores += ['classes.dex', 'classes2.dex']
192 if args.debug: 188 if args.debug:
193 # see http://crbug.com/648720 189 # see http://crbug.com/648720
(...skipping 23 matching lines...) Expand all
217 # Using type=os.path.abspath converts file paths to absolute paths so that 213 # Using type=os.path.abspath converts file paths to absolute paths so that
218 # we can change working directory without affecting these paths 214 # we can change working directory without affecting these paths
219 parser.add_argument('--apk_32bit', required=True, type=os.path.abspath) 215 parser.add_argument('--apk_32bit', required=True, type=os.path.abspath)
220 parser.add_argument('--apk_64bit', required=True, type=os.path.abspath) 216 parser.add_argument('--apk_64bit', required=True, type=os.path.abspath)
221 parser.add_argument('--out_apk', required=True, type=os.path.abspath) 217 parser.add_argument('--out_apk', required=True, type=os.path.abspath)
222 parser.add_argument('--zipalign_path', required=True, type=os.path.abspath) 218 parser.add_argument('--zipalign_path', required=True, type=os.path.abspath)
223 parser.add_argument('--keystore_path', required=True, type=os.path.abspath) 219 parser.add_argument('--keystore_path', required=True, type=os.path.abspath)
224 parser.add_argument('--key_name', required=True) 220 parser.add_argument('--key_name', required=True)
225 parser.add_argument('--key_password', required=True) 221 parser.add_argument('--key_password', required=True)
226 parser.add_argument('--shared_library') 222 parser.add_argument('--shared_library')
227 parser.add_argument('--page-align-shared-libraries', action='store_true') 223 parser.add_argument('--page-align-shared-libraries', action='store_true',
224 help='Obsolete, but remains for backwards compatibility')
228 parser.add_argument('--uncompress-shared-libraries', action='store_true') 225 parser.add_argument('--uncompress-shared-libraries', action='store_true')
229 parser.add_argument('--debug', action='store_true') 226 parser.add_argument('--debug', action='store_true')
230 # This option shall only used in debug build, see http://crbug.com/631494. 227 # This option shall only used in debug build, see http://crbug.com/631494.
231 parser.add_argument('--ignore-classes-dex', action='store_true') 228 parser.add_argument('--ignore-classes-dex', action='store_true')
232 parser.add_argument('--component-build', action='store_true') 229 parser.add_argument('--component-build', action='store_true')
233 args = parser.parse_args() 230 args = parser.parse_args()
234 231
235 tmp_dir = tempfile.mkdtemp() 232 tmp_dir = tempfile.mkdtemp()
236 tmp_dir_64 = os.path.join(tmp_dir, '64_bit') 233 tmp_dir_64 = os.path.join(tmp_dir, '64_bit')
237 tmp_dir_32 = os.path.join(tmp_dir, '32_bit') 234 tmp_dir_32 = os.path.join(tmp_dir, '32_bit')
238 tmp_apk = os.path.join(tmp_dir, 'tmp.apk') 235 tmp_apk = os.path.join(tmp_dir, 'tmp.apk')
239 signed_tmp_apk = os.path.join(tmp_dir, 'signed.apk') 236 signed_tmp_apk = os.path.join(tmp_dir, 'signed.apk')
240 new_apk = args.out_apk 237 new_apk = args.out_apk
241 238
242 try: 239 try:
243 if args.component_build and args.shared_library: 240 if args.component_build and args.shared_library:
244 raise ApkMergeFailure('--component-build and shared-library shouldn\'t' 241 raise ApkMergeFailure('--component-build and shared-library shouldn\'t'
245 ' be specified at same time.') 242 ' be specified at same time.')
246 if not args.component_build and not args.shared_library: 243 if not args.component_build and not args.shared_library:
247 raise ApkMergeFailure('Either --component-build or shared-library should' 244 raise ApkMergeFailure('Either --component-build or shared-library should'
248 ' be specified.') 245 ' be specified.')
249 246
250 MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64) 247 MergeApk(args, tmp_apk, tmp_dir_32, tmp_dir_64)
251 248
252 SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, args.zipalign_path, 249 SignAndAlignApk(tmp_apk, signed_tmp_apk, new_apk, args.zipalign_path,
253 args.keystore_path, args.key_name, args.key_password, 250 args.keystore_path, args.key_name, args.key_password)
254 args.page_align_shared_libraries)
255 251
256 except ApkMergeFailure as e: 252 except ApkMergeFailure as e:
257 print e 253 print e
258 return 1 254 return 1
259 finally: 255 finally:
260 shutil.rmtree(tmp_dir) 256 shutil.rmtree(tmp_dir)
261 return 0 257 return 0
262 258
263 259
264 if __name__ == '__main__': 260 if __name__ == '__main__':
265 sys.exit(main()) 261 sys.exit(main())
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | build/android/gyp/apkbuilder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698