Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / build / android / incremental_install / create_install_script.py
blob614cbb77c45ead4339bba964015ad0a8937aa3bf
1 #!/usr/bin/env python
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.
7 """Creates a script to run an "_incremental" .apk."""
9 import argparse
10 import os
11 import pprint
12 import sys
14 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
15 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'gyp'))
17 from pylib import constants
18 from util import build_utils
21 SCRIPT_TEMPLATE = """\
22 #!/usr/bin/env python
24 # This file was generated by:
25 # //build/android/incremental_install/create_install_script.py
27 import os
28 import subprocess
29 import sys
31 def main():
32 script_directory = os.path.dirname(__file__)
34 def resolve_path(path):
35 return os.path.abspath(os.path.join(script_directory, path))
37 cmd_path = resolve_path({cmd_path})
38 cmd_args = [cmd_path] + {cmd_args}
39 cmd_path_args = {cmd_path_args}
40 for arg, path in cmd_path_args:
41 if arg:
42 cmd_args.append(arg)
43 cmd_args.append(resolve_path(path))
45 return subprocess.call(cmd_args + sys.argv[1:])
47 if __name__ == '__main__':
48 sys.exit(main())
49 """
52 def _ParseArgs(args):
53 args = build_utils.ExpandFileArgs(args)
54 parser = argparse.ArgumentParser()
55 build_utils.AddDepfileOption(parser)
56 parser.add_argument('--script-output-path',
57 help='Output path for executable script.',
58 required=True)
59 parser.add_argument('--output-directory',
60 help='Path to the root build directory.',
61 default='.')
62 parser.add_argument('--apk-path',
63 help='Path to the .apk to install.',
64 required=True)
65 parser.add_argument('--split',
66 action='append',
67 dest='splits',
68 default=[],
69 help='A glob matching the apk splits. '
70 'Can be specified multiple times.')
71 parser.add_argument('--lib-dir',
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.')
81 options = parser.parse_args(args)
82 options.dex_files += build_utils.ParseGypList(options.dex_file_list)
83 return options
86 def main(args):
87 options = _ParseArgs(args)
89 def relativize(path):
90 return os.path.relpath(path, os.path.dirname(options.script_output_path))
92 installer_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android',
93 'incremental_install', 'installer.py')
94 installer_path = relativize(installer_path)
96 path_args = [
97 ('--output-directory', relativize(options.output_directory)),
98 (None, relativize(options.apk_path)),
101 if options.lib_dir:
102 path_args.append(('--lib-dir', relativize(options.lib_dir)))
104 if options.dex_files:
105 for dex_file in options.dex_files:
106 path_args.append(('--dex-file', relativize(dex_file)))
108 for split_arg in options.splits:
109 path_args.append(('--split', relativize(split_arg)))
111 with open(options.script_output_path, 'w') as script:
112 script.write(SCRIPT_TEMPLATE.format(
113 cmd_path=pprint.pformat(installer_path),
114 cmd_args='[]',
115 cmd_path_args=pprint.pformat(path_args)))
117 os.chmod(options.script_output_path, 0750)
119 if options.depfile:
120 build_utils.WriteDepfile(
121 options.depfile,
122 build_utils.GetPythonDependencies())
125 if __name__ == '__main__':
126 sys.exit(main(sys.argv[1:]))