| 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 parser.add_argument('--dex-file-list', |
| 76 help='GYP-list of dex files.') |
| 68 | 77 |
| 69 options = parser.parse_args(args) | 78 options = parser.parse_args(args) |
| 79 options.dex_files += build_utils.ParseGypList(options.dex_file_list) |
| 80 return options |
| 81 |
| 82 |
| 83 def main(args): |
| 84 options = _ParseArgs(args) |
| 70 | 85 |
| 71 def relativize(path): | 86 def relativize(path): |
| 72 return os.path.relpath(path, os.path.dirname(options.script_output_path)) | 87 return os.path.relpath(path, os.path.dirname(options.script_output_path)) |
| 73 | 88 |
| 74 incremental_install_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 89 installer_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', |
| 75 'android', 'incremental_install.py') | 90 'incremental_install', 'installer.py') |
| 76 incremental_install_path = relativize(incremental_install_path) | 91 installer_path = relativize(installer_path) |
| 77 | 92 |
| 78 incremental_install_path_args = [ | 93 path_args = [ |
| 79 (None, relativize(options.apk_path)), | 94 (None, relativize(options.apk_path)), |
| 80 ] | 95 ] |
| 96 |
| 81 if options.lib_dir: | 97 if options.lib_dir: |
| 82 incremental_install_path_args.append( | 98 path_args.append(('--lib-dir', relativize(options.lib_dir))) |
| 83 ('--lib-dir', relativize(options.lib_dir))) | 99 |
| 100 if options.dex_files: |
| 101 for dex_file in options.dex_files: |
| 102 path_args.append(('--dex-file', relativize(dex_file))) |
| 103 |
| 84 for split_arg in options.splits: | 104 for split_arg in options.splits: |
| 85 incremental_install_path_args.append(('--split', relativize(split_arg))) | 105 path_args.append(('--split', relativize(split_arg))) |
| 86 | 106 |
| 87 with open(options.script_output_path, 'w') as script: | 107 with open(options.script_output_path, 'w') as script: |
| 88 script.write(SCRIPT_TEMPLATE.format( | 108 script.write(SCRIPT_TEMPLATE.format( |
| 89 cmd_path=repr(incremental_install_path), | 109 cmd_path=pprint.pformat(installer_path), |
| 90 cmd_args='[]', | 110 cmd_args='[]', |
| 91 cmd_path_args=repr(incremental_install_path_args))) | 111 cmd_path_args=pprint.pformat(path_args))) |
| 92 | 112 |
| 93 os.chmod(options.script_output_path, 0750) | 113 os.chmod(options.script_output_path, 0750) |
| 94 | 114 |
| 95 if options.depfile: | 115 if options.depfile: |
| 96 build_utils.WriteDepfile( | 116 build_utils.WriteDepfile( |
| 97 options.depfile, | 117 options.depfile, |
| 98 build_utils.GetPythonDependencies()) | 118 build_utils.GetPythonDependencies()) |
| 99 | 119 |
| 100 | 120 |
| 101 if __name__ == '__main__': | 121 if __name__ == '__main__': |
| 102 sys.exit(main(sys.argv[1:])) | 122 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |