OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright 2015 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 """Creates a script to run a "_incremental" .apk.""" | |
8 | |
9 import argparse | |
10 import os | |
11 import sys | |
12 | |
13 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | |
14 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'gyp')) | |
15 from util import build_utils | |
16 from pylib import constants | |
17 | |
18 | |
19 SCRIPT_TEMPLATE = """\ | |
20 #!/usr/bin/env python | |
21 # | |
22 # This file was generated by: | |
23 # //build/android/gyp/create_incremental_install_script.py | |
24 | |
25 import os | |
26 import subprocess | |
27 import sys | |
28 | |
29 def main(): | |
30 script_directory = os.path.dirname(__file__) | |
31 | |
32 def resolve_path(path): | |
33 return os.path.abspath(os.path.join(script_directory, path)) | |
34 | |
35 cmd_path = resolve_path({cmd_path}) | |
36 cmd_args = [cmd_path] + {cmd_args} | |
37 cmd_path_args = {cmd_path_args} | |
38 for arg, path in cmd_path_args: | |
39 if arg: | |
40 cmd_args.append(arg) | |
41 cmd_args.append(resolve_path(path)) | |
42 | |
43 return subprocess.call(cmd_args + sys.argv[1:]) | |
44 | |
45 if __name__ == '__main__': | |
46 sys.exit(main()) | |
47 """ | |
48 | |
49 | |
50 def main(args): | |
51 args = build_utils.ExpandFileArgs(args) | |
52 parser = argparse.ArgumentParser() | |
53 build_utils.AddDepfileOption(parser) | |
54 parser.add_argument('--script-output-path', | |
55 help='Output path for executable script.', | |
56 required=True) | |
57 parser.add_argument('--output-directory', | |
58 help='Path to the root build directory.', | |
59 default='.') | |
60 parser.add_argument('--apk-path', | |
61 help='Path to the .apk to install.', | |
62 required=True) | |
63 parser.add_argument('--split', | |
64 action='append', | |
65 dest='splits', | |
66 default=[], | |
67 help='A glob matching the apk splits. ' | |
68 'Can be specified multiple times.') | |
69 parser.add_argument('--lib-dir', | |
70 help='Path to native libraries directory.') | |
71 | |
72 options = parser.parse_args(args) | |
73 | |
74 def relativize(path): | |
75 return os.path.relpath(path, os.path.dirname(options.script_output_path)) | |
76 | |
77 incremental_install_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | |
78 'android', 'incremental_install.py') | |
79 incremental_install_path = relativize(incremental_install_path) | |
80 | |
81 incremental_install_path_args = [ | |
82 ('--output-directory', relativize(options.output_directory)), | |
83 (None, relativize(options.apk_path)), | |
84 ] | |
85 if options.lib_dir: | |
86 incremental_install_path_args.append( | |
87 ('--lib-dir', relativize(options.lib_dir))) | |
88 for split_arg in options.splits: | |
89 incremental_install_path_args.append(('--split', relativize(split_arg))) | |
90 | |
91 with open(options.script_output_path, 'w') as script: | |
92 script.write(SCRIPT_TEMPLATE.format( | |
93 cmd_path=repr(incremental_install_path), | |
94 cmd_args='[]', | |
95 cmd_path_args=repr(incremental_install_path_args))) | |
96 | |
97 os.chmod(options.script_output_path, 0750) | |
98 | |
99 if options.depfile: | |
100 build_utils.WriteDepfile( | |
101 options.depfile, | |
102 build_utils.GetPythonDependencies()) | |
103 | |
104 | |
105 if __name__ == '__main__': | |
106 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |