Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2015 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 | 6 |
| 7 """Adds the code parts to a resource APK.""" | 7 """Adds the code parts to a resource APK.""" |
| 8 | 8 |
| 9 import argparse | 9 import argparse |
| 10 import os | 10 import os |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 help='Path to the output file', | 25 help='Path to the output file', |
| 26 required=True) | 26 required=True) |
| 27 parser.add_argument('--dex-file', | 27 parser.add_argument('--dex-file', |
| 28 help='Path to the classes.dex to use') | 28 help='Path to the classes.dex to use') |
| 29 # TODO(agrieve): Switch this to be a list of files rather than a directory. | 29 # TODO(agrieve): Switch this to be a list of files rather than a directory. |
| 30 parser.add_argument('--native-libs-dir', | 30 parser.add_argument('--native-libs-dir', |
| 31 help='Directory containing native libraries to include', | 31 help='Directory containing native libraries to include', |
| 32 default=[]) | 32 default=[]) |
| 33 parser.add_argument('--android-abi', | 33 parser.add_argument('--android-abi', |
| 34 help='Android architecture to use for native libraries') | 34 help='Android architecture to use for native libraries') |
| 35 parser.add_argument('--create-placeholder-lib', | |
| 36 action='store_true', | |
| 37 help='Whether to add a dummy library file') | |
| 35 options = parser.parse_args(args) | 38 options = parser.parse_args(args) |
| 36 if options.native_libs_dir and not options.android_abi: | 39 if not options.android_abi and (options.native_libs_dir or |
| 40 options.create_placeholder_lib): | |
| 37 raise Exception('Must specify --android-abi with --native-libs-dir') | 41 raise Exception('Must specify --android-abi with --native-libs-dir') |
| 38 return options | 42 return options |
| 39 | 43 |
| 40 | 44 |
| 41 def _ListSubPaths(path): | 45 def _ListSubPaths(path): |
| 42 """Returns a list of full paths to all files in the given path.""" | 46 """Returns a list of full paths to all files in the given path.""" |
| 43 return [os.path.join(path, name) for name in os.listdir(path)] | 47 return [os.path.join(path, name) for name in os.listdir(path)] |
| 44 | 48 |
| 45 | 49 |
| 46 def main(args): | 50 def main(args): |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 61 # Use a temp file to avoid creating an output if anything goes wrong. | 65 # Use a temp file to avoid creating an output if anything goes wrong. |
| 62 shutil.copyfile(options.resource_apk, tmp_apk) | 66 shutil.copyfile(options.resource_apk, tmp_apk) |
| 63 | 67 |
| 64 # TODO(agrieve): It would be more efficient to combine this step | 68 # TODO(agrieve): It would be more efficient to combine this step |
| 65 # with finalize_apk(), which sometimes aligns and uncompresses the | 69 # with finalize_apk(), which sometimes aligns and uncompresses the |
| 66 # native libraries. | 70 # native libraries. |
| 67 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk: | 71 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk: |
| 68 for path in native_libs: | 72 for path in native_libs: |
| 69 basename = os.path.basename(path) | 73 basename = os.path.basename(path) |
| 70 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename)) | 74 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename)) |
| 75 if options.create_placeholder_lib: | |
| 76 # Make it non-empty so that its checksum is non-zero and is not | |
| 77 # ignored by md5_check. | |
| 78 apk.writestr('lib/%s/libplaceholder.so' % options.android_abi, ':-)') | |
|
newt (away)
2015/10/09 00:00:10
Nice :-)
| |
| 71 if options.dex_file: | 79 if options.dex_file: |
| 72 apk.write(options.dex_file, 'classes.dex') | 80 apk.write(options.dex_file, 'classes.dex') |
| 73 | 81 |
| 74 shutil.move(tmp_apk, options.output_apk) | 82 shutil.move(tmp_apk, options.output_apk) |
| 75 finally: | 83 finally: |
| 76 if os.path.exists(tmp_apk): | 84 if os.path.exists(tmp_apk): |
| 77 os.unlink(tmp_apk) | 85 os.unlink(tmp_apk) |
| 78 | 86 |
| 79 build_utils.CallAndWriteDepfileIfStale( | 87 build_utils.CallAndWriteDepfileIfStale( |
| 80 on_stale_md5, | 88 on_stale_md5, |
| 81 options, | 89 options, |
| 82 input_paths=input_paths, | 90 input_paths=input_paths, |
| 91 input_strings=[options.create_placeholder_lib, options.android_abi], | |
| 83 output_paths=[options.output_apk]) | 92 output_paths=[options.output_apk]) |
| 84 | 93 |
| 85 | 94 |
| 86 if __name__ == '__main__': | 95 if __name__ == '__main__': |
| 87 main(sys.argv[1:]) | 96 main(sys.argv[1:]) |
| OLD | NEW |