| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 #!/usr/bin/env python |  | 
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |  | 
| 3 # Use of this source code is governed by a BSD-style license that can be |  | 
| 4 # found in the LICENSE file. |  | 
| 5 |  | 
| 6 import argparse |  | 
| 7 import logging |  | 
| 8 import sys |  | 
| 9 |  | 
| 10 from devtoolslib.android_shell import AndroidShell |  | 
| 11 from devtoolslib.linux_shell import LinuxShell |  | 
| 12 from devtoolslib import paths |  | 
| 13 from devtoolslib import shell_arguments |  | 
| 14 |  | 
| 15 USAGE = ("mojo_shell " |  | 
| 16          "[--args-for=<mojo-app>] " |  | 
| 17          "[--content-handlers=<handlers>] " |  | 
| 18          "[--enable-external-applications] " |  | 
| 19          "[--disable-cache] " |  | 
| 20          "[--enable-multiprocess] " |  | 
| 21          "[--url-mappings=from1=to1,from2=to2] " |  | 
| 22          "[<mojo-app>] " |  | 
| 23          """ |  | 
| 24 |  | 
| 25 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. |  | 
| 26 Example: mojo_shell "mojo:js_standalone test.js". |  | 
| 27 <url-lib-path> is searched for shared libraries named by mojo URLs. |  | 
| 28 The value of <handlers> is a comma separated list like: |  | 
| 29 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler |  | 
| 30 """) |  | 
| 31 |  | 
| 32 _DEFAULT_WINDOW_MANAGER = "mojo:kiosk_wm" |  | 
| 33 |  | 
| 34 |  | 
| 35 def main(): |  | 
| 36   logging.basicConfig() |  | 
| 37 |  | 
| 38   parser = argparse.ArgumentParser(usage=USAGE) |  | 
| 39 |  | 
| 40   # Arguments indicating the configuration we are targeting. |  | 
| 41   parser.add_argument('--android', help='Run on Android', |  | 
| 42                       action='store_true') |  | 
| 43   debug_group = parser.add_mutually_exclusive_group() |  | 
| 44   debug_group.add_argument('--debug', help='Debug build (default)', |  | 
| 45                            default=True, action='store_true') |  | 
| 46   debug_group.add_argument('--release', help='Release build', default=False, |  | 
| 47                            dest='debug', action='store_false') |  | 
| 48   parser.add_argument('--target-cpu', help='CPU architecture to run for.', |  | 
| 49                       choices=['x64', 'x86', 'arm']) |  | 
| 50 |  | 
| 51   # Arguments configuring the shell run. |  | 
| 52   parser.add_argument('--origin', help='Origin for mojo: URLs.') |  | 
| 53   parser.add_argument('--window-manager', default=_DEFAULT_WINDOW_MANAGER, |  | 
| 54                       help='Window manager app to be mapped as ' |  | 
| 55                       'mojo:window_manager. By default it is ' + |  | 
| 56                       _DEFAULT_WINDOW_MANAGER) |  | 
| 57   parser.add_argument('--no-debugger', action="store_true", |  | 
| 58                       help='Do not spawn mojo:debugger.') |  | 
| 59   parser.add_argument('--sky', |  | 
| 60                       help='Loads the given Sky file.') |  | 
| 61   parser.add_argument('-v', '--verbose', action="store_true", |  | 
| 62                       help="Increase output verbosity") |  | 
| 63 |  | 
| 64   # Android-only arguments. |  | 
| 65   parser.add_argument('--target-device', |  | 
| 66                       help='(android-only) Device to run on.') |  | 
| 67   parser.add_argument('--logcat-tags', |  | 
| 68                       help='(android-only) Comma-separated list of additional ' |  | 
| 69                       'logcat tags to display on the console.') |  | 
| 70 |  | 
| 71   # Desktop-only arguments. |  | 
| 72   parser.add_argument('--use-osmesa', action='store_true', |  | 
| 73                       help='(linux-only) Configure the native viewport service ' |  | 
| 74                       'for off-screen rendering.') |  | 
| 75 |  | 
| 76   launcher_args, args = parser.parse_known_args() |  | 
| 77   mojo_paths, _ = paths.infer_mojo_paths(launcher_args.android, |  | 
| 78                                          launcher_args.debug, |  | 
| 79                                          launcher_args.target_cpu) |  | 
| 80   if mojo_paths: |  | 
| 81     adb_path = mojo_paths['adb'] |  | 
| 82     shell_binary_path = mojo_paths['shell'] |  | 
| 83     local_origin_path = mojo_paths['build'] |  | 
| 84     if launcher_args.verbose: |  | 
| 85       print 'Running within a Mojo checkout:' |  | 
| 86       print ' - using the locally built shell at ' + shell_binary_path |  | 
| 87       print ' - using the default origin of ' + local_origin_path |  | 
| 88   else: |  | 
| 89     if launcher_args.android: |  | 
| 90       adb_path = 'adb' |  | 
| 91       shell_binary_path = None |  | 
| 92       local_origin_path = '.' |  | 
| 93       if launcher_args.verbose: |  | 
| 94         print 'Running outside a Mojo checkout:' |  | 
| 95         print ' - using the shell already installed on the device' |  | 
| 96         print ' - using the current working directory as default origin' |  | 
| 97     else: |  | 
| 98       print 'Running outside a Mojo checkout is not supported on Linux yet.' |  | 
| 99       return 1 |  | 
| 100 |  | 
| 101   if launcher_args.android: |  | 
| 102     verbose_pipe = sys.stdout if launcher_args.verbose else None |  | 
| 103 |  | 
| 104     shell = AndroidShell(adb_path, launcher_args.target_device, |  | 
| 105                          logcat_tags=launcher_args.logcat_tags, |  | 
| 106                          verbose_pipe=verbose_pipe) |  | 
| 107     device_status, error = shell.CheckDevice() |  | 
| 108     if not device_status: |  | 
| 109       print 'Device check failed: ' + error |  | 
| 110       return 1 |  | 
| 111     if shell_binary_path: |  | 
| 112       shell.InstallApk(shell_binary_path) |  | 
| 113 |  | 
| 114     args = shell_arguments.RewriteMapOriginParameters(shell, args) |  | 
| 115     if not launcher_args.origin: |  | 
| 116       args.extend(shell_arguments.ConfigureLocalOrigin(shell, |  | 
| 117                                                        local_origin_path)) |  | 
| 118   else: |  | 
| 119     shell = LinuxShell(shell_binary_path) |  | 
| 120     if launcher_args.use_osmesa: |  | 
| 121       args.append('--args-for=mojo:native_viewport_service --use-osmesa') |  | 
| 122 |  | 
| 123   if launcher_args.origin: |  | 
| 124     args.append('--origin=' + launcher_args.origin) |  | 
| 125   args = shell_arguments.AppendToArgument(args, '--url-mappings=', |  | 
| 126                                           'mojo:window_manager=%s' % |  | 
| 127                                           launcher_args.window_manager) |  | 
| 128   if not launcher_args.no_debugger: |  | 
| 129     args.extend(shell_arguments.ConfigureDebugger(shell)) |  | 
| 130 |  | 
| 131   if launcher_args.sky: |  | 
| 132     if not mojo_paths: |  | 
| 133       print 'Running with --sky is not supported outside of the Mojo checkout.' |  | 
| 134       # See https://github.com/domokit/devtools/issues/27. |  | 
| 135       return 1 |  | 
| 136     args.extend(shell_arguments.ConfigureSky(shell, mojo_paths['root'], |  | 
| 137                                              mojo_paths['sky_packages'], |  | 
| 138                                              launcher_args.sky)) |  | 
| 139 |  | 
| 140   if launcher_args.verbose: |  | 
| 141     print "Shell arguments: " + str(args) |  | 
| 142 |  | 
| 143   shell.Run(args) |  | 
| 144   return 0 |  | 
| 145 |  | 
| 146 |  | 
| 147 if __name__ == "__main__": |  | 
| 148   sys.exit(main()) |  | 
| OLD | NEW | 
|---|