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

Side by Side Diff: build/android/gyp/finalize_apk.py

Issue 608853005: Add rename and inflate support to the RezipApk tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't remove the rezip dependency. The bot needs it. Created 6 years, 2 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
OLDNEW
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 """Signs and zipaligns APK. 6 """Signs and zipaligns APK.
7 7
8 """ 8 """
9 9
10 import optparse 10 import optparse
11 import shutil 11 import shutil
12 import sys 12 import sys
13 import tempfile 13 import tempfile
14 14
15 from util import build_utils 15 from util import build_utils
16 16
17 def AddPageAlignment(rezip_apk_jar_path, in_zip_file, out_zip_file): 17 def RenameInflateAndAddPageAlignment(
18 rezip_apk_jar_path, in_zip_file, out_zip_file):
18 rezip_apk_cmd = [ 19 rezip_apk_cmd = [
19 'java', 20 'java',
20 '-classpath', 21 '-classpath',
21 rezip_apk_jar_path, 22 rezip_apk_jar_path,
22 'RezipApk', 23 'RezipApk',
23 'addalignment', 24 'renamealign',
24 in_zip_file, 25 in_zip_file,
25 out_zip_file, 26 out_zip_file,
26 ] 27 ]
27 build_utils.CheckOutput(rezip_apk_cmd) 28 build_utils.CheckOutput(rezip_apk_cmd)
28 29
29 30
30 def ReorderAndAlignApk(rezip_apk_jar_path, in_zip_file, out_zip_file): 31 def ReorderAndAlignApk(rezip_apk_jar_path, in_zip_file, out_zip_file):
31 rezip_apk_cmd = [ 32 rezip_apk_cmd = [
32 'java', 33 'java',
33 '-classpath', 34 '-classpath',
(...skipping 23 matching lines...) Expand all
57 def AlignApk(zipalign_path, unaligned_path, final_path): 58 def AlignApk(zipalign_path, unaligned_path, final_path):
58 align_cmd = [ 59 align_cmd = [
59 zipalign_path, 60 zipalign_path,
60 '-f', '4', # 4 bytes 61 '-f', '4', # 4 bytes
61 unaligned_path, 62 unaligned_path,
62 final_path, 63 final_path,
63 ] 64 ]
64 build_utils.CheckOutput(align_cmd) 65 build_utils.CheckOutput(align_cmd)
65 66
66 67
67 def RenameAndUncompressLibInApk(rezip_path, in_zip_file, out_zip_file):
68 rename_cmd = [
69 rezip_path,
70 'renameinflate',
71 in_zip_file,
72 out_zip_file,
73 ]
74 build_utils.CheckOutput(rename_cmd)
75
76
77 def main(): 68 def main():
78 parser = optparse.OptionParser() 69 parser = optparse.OptionParser()
79 build_utils.AddDepfileOption(parser) 70 build_utils.AddDepfileOption(parser)
80 71
81 parser.add_option('--rezip-apk-jar-path', 72 parser.add_option('--rezip-apk-jar-path',
82 help='Path to the RezipApk jar file.') 73 help='Path to the RezipApk jar file.')
83 parser.add_option('--zipalign-path', help='Path to the zipalign tool.') 74 parser.add_option('--zipalign-path', help='Path to the zipalign tool.')
84 parser.add_option('--rezip-path', help='Path to the rezip executable.')
85 parser.add_option('--unsigned-apk-path', help='Path to input unsigned APK.') 75 parser.add_option('--unsigned-apk-path', help='Path to input unsigned APK.')
86 parser.add_option('--final-apk-path', 76 parser.add_option('--final-apk-path',
87 help='Path to output signed and aligned APK.') 77 help='Path to output signed and aligned APK.')
88 parser.add_option('--key-path', help='Path to keystore for signing.') 78 parser.add_option('--key-path', help='Path to keystore for signing.')
89 parser.add_option('--key-passwd', help='Keystore password') 79 parser.add_option('--key-passwd', help='Keystore password')
90 parser.add_option('--key-name', help='Keystore name') 80 parser.add_option('--key-name', help='Keystore name')
91 parser.add_option('--stamp', help='Path to touch on success.') 81 parser.add_option('--stamp', help='Path to touch on success.')
92 parser.add_option('--load-library-from-zip-file', type='int', 82 parser.add_option('--load-library-from-zip-file', type='int',
93 help='If non-zero, build the APK such that the library can be loaded ' + 83 help='If non-zero, build the APK such that the library can be loaded ' +
94 'directly from the zip file using the crazy linker. The library ' + 84 'directly from the zip file using the crazy linker. The library ' +
95 'will be renamed, uncompressed and page aligned.') 85 'will be renamed, uncompressed and page aligned.')
96 86
97 options, _ = parser.parse_args() 87 options, _ = parser.parse_args()
98 88
99 with tempfile.NamedTemporaryFile() as signed_apk_path_tmp, \ 89 with tempfile.NamedTemporaryFile() as signed_apk_path_tmp, \
100 tempfile.NamedTemporaryFile() as apk_to_sign_tmp, \ 90 tempfile.NamedTemporaryFile() as apk_to_sign_tmp:
101 tempfile.NamedTemporaryFile() as uncompress_lib_apk_tmp:
102 91
103 if options.load_library_from_zip_file: 92 if options.load_library_from_zip_file:
104 # We alter the name of the library so that the Android Package Manager 93 # We alter the name of the library so that the Android Package Manager
105 # does not extract it into a separate file. This must be done before 94 # does not extract it into a separate file. This must be done before
106 # signing, as the filename is part of the signed manifest. At the same 95 # signing, as the filename is part of the signed manifest. At the same
107 # time we uncompress the library, which is necessary so that it can be 96 # time we uncompress the library, which is necessary so that it can be
108 # loaded directly from the APK. 97 # loaded directly from the APK.
109 uncompress_lib_apk_path = uncompress_lib_apk_tmp.name 98 # Move the library to a page boundary by adding a page alignment file.
110 RenameAndUncompressLibInApk(
111 options.rezip_path, options.unsigned_apk_path,
112 uncompress_lib_apk_path)
113 apk_to_sign = apk_to_sign_tmp.name 99 apk_to_sign = apk_to_sign_tmp.name
114 # Move the library to a page boundary by adding a page alignment file. 100 RenameInflateAndAddPageAlignment(
115 AddPageAlignment( 101 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign)
116 options.rezip_apk_jar_path, uncompress_lib_apk_path, apk_to_sign)
117 else: 102 else:
118 apk_to_sign = options.unsigned_apk_path 103 apk_to_sign = options.unsigned_apk_path
119 104
120 signed_apk_path = signed_apk_path_tmp.name 105 signed_apk_path = signed_apk_path_tmp.name
121 JarSigner(options.key_path, options.key_name, options.key_passwd, 106 JarSigner(options.key_path, options.key_name, options.key_passwd,
122 apk_to_sign, signed_apk_path) 107 apk_to_sign, signed_apk_path)
123 108
124 if options.load_library_from_zip_file: 109 if options.load_library_from_zip_file:
125 # Reorder the contents of the APK. This re-establishes the canonical 110 # Reorder the contents of the APK. This re-establishes the canonical
126 # order which means the library will be back at its page aligned location. 111 # order which means the library will be back at its page aligned location.
127 # This step also aligns uncompressed items to 4 bytes. 112 # This step also aligns uncompressed items to 4 bytes.
128 ReorderAndAlignApk( 113 ReorderAndAlignApk(
129 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) 114 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path)
130 else: 115 else:
131 # Align uncompressed items to 4 bytes 116 # Align uncompressed items to 4 bytes
132 AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path) 117 AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path)
133 118
134 if options.depfile: 119 if options.depfile:
135 build_utils.WriteDepfile( 120 build_utils.WriteDepfile(
136 options.depfile, build_utils.GetPythonDependencies()) 121 options.depfile, build_utils.GetPythonDependencies())
137 122
138 if options.stamp: 123 if options.stamp:
139 build_utils.Touch(options.stamp) 124 build_utils.Touch(options.stamp)
140 125
141 126
142 if __name__ == '__main__': 127 if __name__ == '__main__':
143 sys.exit(main()) 128 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698