Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: mojo/tools/mojo_shell.py

Issue 1242453003: Extract the shell runner into devtools. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Update more paths and devtools README. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/devtools/common/mojo_shell ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse
7 import logging
8 import sys 6 import sys
9 import os.path
10 import subprocess
11
12 import devtools
13 devtools.add_lib_to_path()
14 from devtoolslib.android_shell import AndroidShell
15 from devtoolslib.linux_shell import LinuxShell
16 from devtoolslib import shell_arguments
17
18 from mopy.config import Config
19 from mopy.paths import Paths
20
21 USAGE = ("mojo_shell.py "
22 "[--args-for=<mojo-app>] "
23 "[--content-handlers=<handlers>] "
24 "[--enable-external-applications] "
25 "[--disable-cache] "
26 "[--enable-multiprocess] "
27 "[--url-mappings=from1=to1,from2=to2] "
28 "[<mojo-app>] "
29 """
30
31 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.
32 Example: mojo_shell "mojo:js_standalone test.js".
33 <url-lib-path> is searched for shared libraries named by mojo URLs.
34 The value of <handlers> is a comma separated list like:
35 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler
36 """)
37
38 _DEFAULT_WINDOW_MANAGER = "mojo:kiosk_wm"
39 _SKY_SERVER_PORT = 9998
40 7
41 8
42 def main(): 9 def main():
43 logging.basicConfig() 10 print 'Good news, the shell runner has moved! Please use: '
44 11 print ''
45 parser = argparse.ArgumentParser(usage=USAGE) 12 print ' mojo/devtools/common/mojo_shell'
46 13 print ''
47 # Arguments indicating the configuration we are targeting. 14 print 'as you would use mojo_shell.py before.'
48 parser.add_argument('--android', help='Run on Android', 15 return -1
49 action='store_true')
50 debug_group = parser.add_mutually_exclusive_group()
51 debug_group.add_argument('--debug', help='Debug build (default)',
52 default=True, action='store_true')
53 debug_group.add_argument('--release', help='Release build', default=False,
54 dest='debug', action='store_false')
55 parser.add_argument('--target-cpu', help='CPU architecture to run for.',
56 choices=['x64', 'x86', 'arm'])
57
58 # Arguments configuring the shell run.
59 parser.add_argument('--origin', help='Origin for mojo: URLs.')
60 parser.add_argument('--window-manager', default=_DEFAULT_WINDOW_MANAGER,
61 help='Window manager app to be mapped as '
62 'mojo:window_manager. By default it is ' +
63 _DEFAULT_WINDOW_MANAGER)
64 parser.add_argument('--no-debugger', action="store_true",
65 help='Do not spawn mojo:debugger.')
66 parser.add_argument('--sky',
67 help='Loads the given Sky file.')
68 parser.add_argument('-v', '--verbose', action="store_true",
69 help="Increase output verbosity")
70
71 # Android-only arguments.
72 parser.add_argument('--target-device',
73 help='(android-only) Device to run on.')
74 parser.add_argument('--logcat-tags',
75 help='(android-only) Comma-separated list of additional '
76 'logcat tags to display on the console.')
77
78 # Desktop-only arguments.
79 parser.add_argument('--use-osmesa', action='store_true',
80 help='(linux-only) Configure the native viewport service '
81 'for off-screen rendering.')
82
83 launcher_args, args = parser.parse_known_args()
84 if launcher_args.android:
85 config = Config(target_os=Config.OS_ANDROID,
86 target_cpu=launcher_args.target_cpu,
87 is_debug=launcher_args.debug)
88 paths = Paths(config)
89 verbose_pipe = sys.stdout if launcher_args.verbose else None
90
91 shell = AndroidShell(paths.adb_path, launcher_args.target_device,
92 logcat_tags=launcher_args.logcat_tags,
93 verbose_pipe=verbose_pipe)
94 device_status, error = shell.CheckDevice()
95 if not device_status:
96 print 'Device check failed: ' + error
97 return 1
98 shell.InstallApk(paths.target_mojo_shell_path)
99
100 args = shell_arguments.RewriteMapOriginParameters(shell, args)
101 if not launcher_args.origin:
102 args.extend(shell_arguments.ConfigureLocalOrigin(shell, paths.build_dir))
103 else:
104 config = Config(target_os=Config.OS_LINUX,
105 target_cpu=launcher_args.target_cpu,
106 is_debug=launcher_args.debug)
107 paths = Paths(config)
108 shell = LinuxShell(paths.mojo_shell_path)
109 if launcher_args.use_osmesa:
110 args.append('--args-for=mojo:native_viewport_service --use-osmesa')
111
112 if launcher_args.origin:
113 args.append('--origin=' + launcher_args.origin)
114 args = shell_arguments.AppendToArgument(args, '--url-mappings=',
115 'mojo:window_manager=%s' %
116 launcher_args.window_manager)
117 if not launcher_args.no_debugger:
118 args.extend(shell_arguments.ConfigureDebugger(shell))
119
120 if launcher_args.sky:
121 # Configure a server to serve the checkout root at / (so that Sky examples
122 # are accessible using a root-relative path) and Sky packages at /packages.
123 # This is independent from the server that potentially serves the origin
124 # directory containing the mojo: apps.
125 packages_local_path = os.path.join(paths.build_dir, 'gen', 'dart-pkg',
126 'packages')
127 additional_mappings = [
128 ('packages/', packages_local_path),
129 ]
130 server_url = shell.ServeLocalDirectory(paths.src_root,
131 port=_SKY_SERVER_PORT, additional_mappings=additional_mappings)
132
133 # Configure the content type mappings for the sky_viewer. This is needed
134 # only for the Sky apps that do not declare mojo:sky_viewer in a shebang,
135 # and it is unfortunate as it configures the shell to map all items of the
136 # application/dart content-type as Sky apps.
137 # TODO(ppi): drop this part once we can rely on the Sky files declaring
138 # correct shebang.
139 args = shell_arguments.AppendToArgument(args, '--content-handlers=',
140 'text/sky,mojo:sky_viewer')
141 args = shell_arguments.AppendToArgument(args, '--content-handlers=',
142 'application/dart,mojo:sky_viewer')
143
144 # Configure the window manager to embed the sky_viewer.
145 sky_url = server_url + launcher_args.sky
146 args.append('mojo:window_manager %s' % sky_url)
147
148 if launcher_args.verbose:
149 print "Shell arguments: " + str(args)
150
151 shell.Run(args)
152 return 0
153
154 16
155 if __name__ == "__main__": 17 if __name__ == "__main__":
156 sys.exit(main()) 18 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/devtools/common/mojo_shell ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698