| #!/usr/bin/env python |
| # Copyright 2014 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import argparse |
| import logging |
| import sys |
| |
| from devtoolslib import shell_arguments |
| from devtoolslib import shell_config |
| |
| _USAGE = ("mojo_run " |
| "[--args-for=<mojo-app>] " |
| "[--content-handlers=<handlers>] " |
| "[--enable-external-applications] " |
| "[--disable-cache] " |
| "[--enable-multiprocess] " |
| "[--wait-for-debugger] " |
| "[--sky <mojo-app>|<mojo-app>] " |
| """ |
| |
| A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. |
| Example: mojo_run "mojo:js_standalone test.js". |
| <url-lib-path> is searched for shared libraries named by mojo URLs. |
| The value of <handlers> is a comma separated list like: |
| text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler |
| """) |
| |
| _DESCRIPTION = """Runner for Mojo applications. |
| |
| Any arguments not recognized by the script will be passed on as shell arguments. |
| """ |
| |
| |
| # Port on which the mojo:debugger http server will be available on the host |
| # machine. |
| _MOJO_DEBUGGER_PORT = 7777 |
| _DEFAULT_WINDOW_MANAGER = "mojo:kiosk_wm" |
| |
| |
| def _configure_debugger(shell): |
| """Configures mojo:debugger to run and sets up port forwarding for its http |
| server if the shell is running on a device. |
| |
| Returns: |
| Arguments that need to be appended to the shell argument list in order to |
| run with the debugger. |
| """ |
| shell.forward_host_port_to_shell(_MOJO_DEBUGGER_PORT) |
| return ['mojo:debugger %d' % _MOJO_DEBUGGER_PORT] |
| |
| |
| def main(): |
| logging.basicConfig() |
| |
| parser = argparse.ArgumentParser(usage=_USAGE, description=_DESCRIPTION) |
| shell_config.add_shell_arguments(parser) |
| |
| parser.add_argument('--no-debugger', action="store_true", |
| help='Do not spawn mojo:debugger.') |
| parser.add_argument('--window-manager', default=_DEFAULT_WINDOW_MANAGER, |
| help='Window manager app to be mapped as ' |
| 'mojo:window_manager. By default it is ' + |
| _DEFAULT_WINDOW_MANAGER) |
| |
| script_args, shell_args = parser.parse_known_args() |
| |
| try: |
| config = shell_config.get_shell_config(script_args) |
| shell, shell_args = shell_arguments.get_shell(config, shell_args) |
| except shell_config.ShellConfigurationException as e: |
| print e |
| return 1 |
| |
| if not script_args.no_debugger: |
| if script_args.verbose: |
| print 'Spawning mojo:debugger, use `mojo_debug` to inspect the shell.' |
| print 'Note that mojo:debugger will prevent the shell from terminating,' |
| print ' pass --no-debugger to skip spawning mojo:debugger.' |
| shell_args.extend(_configure_debugger(shell)) |
| |
| shell_args = shell_arguments.append_to_argument(shell_args, '--url-mappings=', |
| 'mojo:window_manager=%s' % |
| script_args.window_manager) |
| |
| if script_args.verbose: |
| print "Shell arguments: " + str(shell_args) |
| |
| shell.run(shell_args) |
| return 0 |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main()) |