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