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 import optparse | 10 import optparse |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 '-sigalg', 'MD5withRSA', | 48 '-sigalg', 'MD5withRSA', |
| 49 '-digestalg', 'SHA1', | 49 '-digestalg', 'SHA1', |
| 50 '-keystore', key_path, | 50 '-keystore', key_path, |
| 51 '-storepass', key_passwd, | 51 '-storepass', key_passwd, |
| 52 signed_path, | 52 signed_path, |
| 53 key_name, | 53 key_name, |
| 54 ] | 54 ] |
| 55 build_utils.CheckOutput(sign_cmd) | 55 build_utils.CheckOutput(sign_cmd) |
| 56 | 56 |
| 57 | 57 |
| 58 def AlignApk(zipalign_path, unaligned_path, final_path): | 58 def AlignApk(zipalign_path, package_align, unaligned_path, final_path): |
| 59 align_cmd = [ | 59 align_cmd = [ |
| 60 zipalign_path, | 60 zipalign_path, |
| 61 '-f', '4', # 4 bytes | 61 '-f' |
| 62 ] | |
| 63 | |
| 64 if package_align: | |
| 65 align_cmd += ['-p'] | |
|
Yaron
2016/01/21 20:22:46
Is there a reason we don't do this always?
michaelbai
2016/01/21 21:58:03
For the compressed shared libraries, there is no b
| |
| 66 | |
| 67 align_cmd += [ | |
| 68 '4', # 4 bytes | |
| 62 unaligned_path, | 69 unaligned_path, |
| 63 final_path, | 70 final_path, |
| 64 ] | 71 ] |
| 65 build_utils.CheckOutput(align_cmd) | 72 build_utils.CheckOutput(align_cmd) |
| 66 | 73 |
| 67 | 74 |
| 68 def main(args): | 75 def main(args): |
| 69 args = build_utils.ExpandFileArgs(args) | 76 args = build_utils.ExpandFileArgs(args) |
| 70 | 77 |
| 71 parser = optparse.OptionParser() | 78 parser = optparse.OptionParser() |
| 72 build_utils.AddDepfileOption(parser) | 79 build_utils.AddDepfileOption(parser) |
| 73 | 80 |
| 74 parser.add_option('--rezip-apk-jar-path', | 81 parser.add_option('--rezip-apk-jar-path', |
| 75 help='Path to the RezipApk jar file.') | 82 help='Path to the RezipApk jar file.') |
| 76 parser.add_option('--zipalign-path', help='Path to the zipalign tool.') | 83 parser.add_option('--zipalign-path', help='Path to the zipalign tool.') |
| 84 parser.add_option('--page-align-shared-libraries', | |
| 85 action='store_true', | |
| 86 help='Page align shared libraries.') | |
| 77 parser.add_option('--unsigned-apk-path', help='Path to input unsigned APK.') | 87 parser.add_option('--unsigned-apk-path', help='Path to input unsigned APK.') |
| 78 parser.add_option('--final-apk-path', | 88 parser.add_option('--final-apk-path', |
| 79 help='Path to output signed and aligned APK.') | 89 help='Path to output signed and aligned APK.') |
| 80 parser.add_option('--key-path', help='Path to keystore for signing.') | 90 parser.add_option('--key-path', help='Path to keystore for signing.') |
| 81 parser.add_option('--key-passwd', help='Keystore password') | 91 parser.add_option('--key-passwd', help='Keystore password') |
| 82 parser.add_option('--key-name', help='Keystore name') | 92 parser.add_option('--key-name', help='Keystore name') |
| 83 parser.add_option('--stamp', help='Path to touch on success.') | 93 parser.add_option('--stamp', help='Path to touch on success.') |
| 84 parser.add_option('--load-library-from-zip', type='int', | 94 parser.add_option('--load-library-from-zip', type='int', |
| 85 help='If non-zero, build the APK such that the library can be loaded ' + | 95 help='If non-zero, build the APK such that the library can be loaded ' + |
| 86 'directly from the zip file using the crazy linker. The library ' + | 96 'directly from the zip file using the crazy linker. The library ' + |
| 87 'will be renamed, uncompressed and page aligned.') | 97 'will be renamed, uncompressed and page aligned.') |
| 88 | 98 |
| 89 options, _ = parser.parse_args() | 99 options, _ = parser.parse_args() |
| 90 | 100 |
| 91 input_paths = [ | 101 input_paths = [ |
| 92 options.unsigned_apk_path, | 102 options.unsigned_apk_path, |
| 93 options.key_path, | 103 options.key_path, |
| 94 ] | 104 ] |
| 95 | 105 |
| 96 if options.load_library_from_zip: | 106 if options.load_library_from_zip: |
| 97 input_paths.append(options.rezip_apk_jar_path) | 107 input_paths.append(options.rezip_apk_jar_path) |
| 98 | 108 |
| 99 input_strings = [ | 109 input_strings = [ |
| 100 options.load_library_from_zip, | 110 options.load_library_from_zip, |
| 101 options.key_name, | 111 options.key_name, |
| 102 options.key_passwd, | 112 options.key_passwd, |
| 113 options.page_align_shared_libraries, | |
| 103 ] | 114 ] |
| 104 | 115 |
| 105 build_utils.CallAndWriteDepfileIfStale( | 116 build_utils.CallAndWriteDepfileIfStale( |
| 106 lambda: FinalizeApk(options), | 117 lambda: FinalizeApk(options), |
| 107 options, | 118 options, |
| 108 record_path=options.unsigned_apk_path + '.finalize.md5.stamp', | 119 record_path=options.unsigned_apk_path + '.finalize.md5.stamp', |
| 109 input_paths=input_paths, | 120 input_paths=input_paths, |
| 110 input_strings=input_strings, | 121 input_strings=input_strings, |
| 111 output_paths=[options.final_apk_path]) | 122 output_paths=[options.final_apk_path]) |
| 112 | 123 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 133 apk_to_sign, signed_apk_path) | 144 apk_to_sign, signed_apk_path) |
| 134 | 145 |
| 135 if options.load_library_from_zip: | 146 if options.load_library_from_zip: |
| 136 # Reorder the contents of the APK. This re-establishes the canonical | 147 # Reorder the contents of the APK. This re-establishes the canonical |
| 137 # order which means the library will be back at its page aligned location. | 148 # order which means the library will be back at its page aligned location. |
| 138 # This step also aligns uncompressed items to 4 bytes. | 149 # This step also aligns uncompressed items to 4 bytes. |
| 139 ReorderAndAlignApk( | 150 ReorderAndAlignApk( |
| 140 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) | 151 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) |
| 141 else: | 152 else: |
| 142 # Align uncompressed items to 4 bytes | 153 # Align uncompressed items to 4 bytes |
| 143 AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path) | 154 AlignApk(options.zipalign_path, |
| 155 options.page_align_shared_libraries, | |
| 156 signed_apk_path, | |
| 157 options.final_apk_path) | |
| 144 | 158 |
| 145 | 159 |
| 146 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 147 sys.exit(main(sys.argv[1:])) | 161 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |