OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # | |
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 | |
5 # found in the LICENSE file. | |
6 | |
7 """Combines stripped libraries and incomplete APK into single standalone APK. | |
8 | |
9 """ | |
10 | |
11 import optparse | |
12 import os | |
13 import shutil | |
14 import sys | |
15 import tempfile | |
16 | |
17 from util import build_utils | |
18 from util import md5_check | |
19 | |
20 def CreateStandaloneApk(options): | |
21 def DoZip(): | |
22 with tempfile.NamedTemporaryFile(suffix='.zip') as intermediate_file: | |
23 intermediate_path = intermediate_file.name | |
24 shutil.copy(options.input_apk_path, intermediate_path) | |
25 apk_path_abs = os.path.abspath(intermediate_path) | |
26 build_utils.CheckCallDie( | |
27 ['zip', '-r', '-1', apk_path_abs, 'lib'], | |
28 cwd=options.libraries_top_dir, | |
29 suppress_output=True) | |
30 shutil.copy(intermediate_path, options.output_apk_path) | |
31 | |
32 input_paths = [options.input_apk_path, options.libraries_top_dir] | |
33 record_path = '%s.standalone.stamp' % options.input_apk_path | |
34 md5_check.CallAndRecordIfStale( | |
35 DoZip, | |
36 record_path=record_path, | |
37 input_paths=input_paths) | |
38 | |
39 | |
40 def main(argv): | |
41 parser = optparse.OptionParser() | |
42 parser.add_option('--libraries-top-dir', | |
43 help='Top directory that contains libraries ' | |
44 '(i.e. library paths are like ' | |
45 'libraries_top_dir/lib/android_app_abi/foo.so).') | |
46 parser.add_option('--input-apk-path', help='Path to incomplete APK.') | |
47 parser.add_option('--output-apk-path', help='Path for standalone APK.') | |
48 parser.add_option('--stamp', help='Path to touch on success.') | |
49 options, _ = parser.parse_args() | |
50 | |
51 required_options = ['libraries_top_dir', 'input_apk_path', 'output_apk_path'] | |
52 build_utils.CheckOptions(options, parser, required=required_options) | |
53 | |
54 CreateStandaloneApk(options) | |
55 | |
56 if options.stamp: | |
57 build_utils.Touch(options.stamp) | |
58 | |
59 | |
60 if __name__ == '__main__': | |
61 sys.exit(main(sys.argv)) | |
OLD | NEW |