Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 # pylint: disable=unused-import | |
| 11 # resource_sizes modifies zipfile for zip64 compatibility. See | |
| 12 # https://bugs.python.org/issue14315. | |
| 13 import os | |
| 14 import sys | |
| 15 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | |
| 16 import resource_sizes | |
|
jbudorick
2016/07/29 19:11:45
Why are these out of order?
ghost stip (do not use)
2016/07/29 20:12:09
need os and sys to do the PYTHONPATH adjustment
jbudorick
2016/07/29 20:18:08
Right, but the standard python imports should prec
| |
| 17 | |
| 10 import optparse | 18 import optparse |
| 11 import shutil | 19 import shutil |
| 12 import sys | 20 import sys |
| 13 import tempfile | 21 import tempfile |
| 22 import zipfile | |
| 14 | 23 |
| 15 from util import build_utils | 24 from util import build_utils |
| 16 | 25 |
| 17 def RenameInflateAndAddPageAlignment( | 26 def RenameInflateAndAddPageAlignment( |
| 18 rezip_apk_jar_path, in_zip_file, out_zip_file): | 27 rezip_apk_jar_path, in_zip_file, out_zip_file): |
| 19 rezip_apk_cmd = [ | 28 rezip_apk_cmd = [ |
| 20 'java', | 29 'java', |
| 21 '-classpath', | 30 '-classpath', |
| 22 rezip_apk_jar_path, | 31 rezip_apk_jar_path, |
| 23 'RezipApk', | 32 'RezipApk', |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 apk_to_sign = apk_to_sign_tmp.name | 145 apk_to_sign = apk_to_sign_tmp.name |
| 137 RenameInflateAndAddPageAlignment( | 146 RenameInflateAndAddPageAlignment( |
| 138 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) | 147 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) |
| 139 else: | 148 else: |
| 140 apk_to_sign = options.unsigned_apk_path | 149 apk_to_sign = options.unsigned_apk_path |
| 141 | 150 |
| 142 signed_apk_path = signed_apk_path_tmp.name | 151 signed_apk_path = signed_apk_path_tmp.name |
| 143 JarSigner(options.key_path, options.key_name, options.key_passwd, | 152 JarSigner(options.key_path, options.key_name, options.key_passwd, |
| 144 apk_to_sign, signed_apk_path) | 153 apk_to_sign, signed_apk_path) |
| 145 | 154 |
| 155 # Make the signing files hermetic. | |
| 156 with tempfile.NamedTemporaryFile(suffix='.zip') as hermetic_signed_apk: | |
| 157 with zipfile.ZipFile(signed_apk_path, 'r') as zi: | |
| 158 with zipfile.ZipFile(hermetic_signed_apk, 'w') as zo: | |
| 159 for info in zi.infolist(): | |
| 160 info.date_time = build_utils.HERMETIC_TIMESTAMP | |
| 161 zo.writestr(info, zi.read(info.filename)) | |
| 162 shutil.copy(hermetic_signed_apk.name, signed_apk_path) | |
| 163 | |
| 146 if options.load_library_from_zip: | 164 if options.load_library_from_zip: |
| 147 # Reorder the contents of the APK. This re-establishes the canonical | 165 # Reorder the contents of the APK. This re-establishes the canonical |
| 148 # order which means the library will be back at its page aligned location. | 166 # order which means the library will be back at its page aligned location. |
| 149 # This step also aligns uncompressed items to 4 bytes. | 167 # This step also aligns uncompressed items to 4 bytes. |
| 150 ReorderAndAlignApk( | 168 ReorderAndAlignApk( |
| 151 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) | 169 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) |
| 152 else: | 170 else: |
| 153 # Align uncompressed items to 4 bytes | 171 # Align uncompressed items to 4 bytes |
| 154 AlignApk(options.zipalign_path, | 172 AlignApk(options.zipalign_path, |
| 155 options.page_align_shared_libraries, | 173 options.page_align_shared_libraries, |
| 156 signed_apk_path, | 174 signed_apk_path, |
| 157 options.final_apk_path) | 175 options.final_apk_path) |
| 158 | 176 |
| 159 | 177 |
| 160 if __name__ == '__main__': | 178 if __name__ == '__main__': |
| 161 sys.exit(main(sys.argv[1:])) | 179 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |