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('--output-directory', | 59 parser.add_argument('--output-directory', |
58 help='Path to the root build directory.', | 60 help='Path to the root build directory.', |
59 default='.') | 61 default='.') |
60 parser.add_argument('--apk-path', | 62 parser.add_argument('--apk-path', |
61 help='Path to the .apk to install.', | 63 help='Path to the .apk to install.', |
62 required=True) | 64 required=True) |
63 parser.add_argument('--split', | 65 parser.add_argument('--split', |
64 action='append', | 66 action='append', |
65 dest='splits', | 67 dest='splits', |
66 default=[], | 68 default=[], |
67 help='A glob matching the apk splits. ' | 69 help='A glob matching the apk splits. ' |
68 'Can be specified multiple times.') | 70 'Can be specified multiple times.') |
69 parser.add_argument('--lib-dir', | 71 parser.add_argument('--lib-dir', |
70 help='Path to native libraries directory.') | 72 help='Path to native libraries directory.') |
| 73 parser.add_argument('--dex-file', |
| 74 action='append', |
| 75 default=[], |
| 76 dest='dex_files', |
| 77 help='List of dex files to include.') |
| 78 parser.add_argument('--dex-file-list', |
| 79 help='GYP-list of dex files.') |
71 | 80 |
72 options = parser.parse_args(args) | 81 options = parser.parse_args(args) |
| 82 options.dex_files += build_utils.ParseGypList(options.dex_file_list) |
| 83 return options |
| 84 |
| 85 |
| 86 def main(args): |
| 87 options = _ParseArgs(args) |
73 | 88 |
74 def relativize(path): | 89 def relativize(path): |
75 return os.path.relpath(path, os.path.dirname(options.script_output_path)) | 90 return os.path.relpath(path, os.path.dirname(options.script_output_path)) |
76 | 91 |
77 incremental_install_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 92 installer_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', |
78 'android', 'incremental_install.py') | 93 'incremental_install', 'installer.py') |
79 incremental_install_path = relativize(incremental_install_path) | 94 installer_path = relativize(installer_path) |
80 | 95 |
81 incremental_install_path_args = [ | 96 path_args = [ |
82 ('--output-directory', relativize(options.output_directory)), | 97 ('--output-directory', relativize(options.output_directory)), |
83 (None, relativize(options.apk_path)), | 98 (None, relativize(options.apk_path)), |
84 ] | 99 ] |
| 100 |
85 if options.lib_dir: | 101 if options.lib_dir: |
86 incremental_install_path_args.append( | 102 path_args.append(('--lib-dir', relativize(options.lib_dir))) |
87 ('--lib-dir', relativize(options.lib_dir))) | 103 |
| 104 if options.dex_files: |
| 105 for dex_file in options.dex_files: |
| 106 path_args.append(('--dex-file', relativize(dex_file))) |
| 107 |
88 for split_arg in options.splits: | 108 for split_arg in options.splits: |
89 incremental_install_path_args.append(('--split', relativize(split_arg))) | 109 path_args.append(('--split', relativize(split_arg))) |
90 | 110 |
91 with open(options.script_output_path, 'w') as script: | 111 with open(options.script_output_path, 'w') as script: |
92 script.write(SCRIPT_TEMPLATE.format( | 112 script.write(SCRIPT_TEMPLATE.format( |
93 cmd_path=repr(incremental_install_path), | 113 cmd_path=pprint.pformat(installer_path), |
94 cmd_args='[]', | 114 cmd_args='[]', |
95 cmd_path_args=repr(incremental_install_path_args))) | 115 cmd_path_args=pprint.pformat(path_args))) |
96 | 116 |
97 os.chmod(options.script_output_path, 0750) | 117 os.chmod(options.script_output_path, 0750) |
98 | 118 |
99 if options.depfile: | 119 if options.depfile: |
100 build_utils.WriteDepfile( | 120 build_utils.WriteDepfile( |
101 options.depfile, | 121 options.depfile, |
102 build_utils.GetPythonDependencies()) | 122 build_utils.GetPythonDependencies()) |
103 | 123 |
104 | 124 |
105 if __name__ == '__main__': | 125 if __name__ == '__main__': |
106 sys.exit(main(sys.argv[1:])) | 126 sys.exit(main(sys.argv[1:])) |
OLD | NEW |