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