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