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

Side by Side Diff: mojo/devtools/common/mojo_shell

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/devtoolslib/default_paths.py ('k') | mojo/tools/mojo_shell.py » ('j') | 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 6 import argparse
7 import logging 7 import logging
8 import sys 8 import sys
9 import os.path
10 import subprocess
11 9
12 import devtools
13 devtools.add_lib_to_path()
14 from devtoolslib.android_shell import AndroidShell 10 from devtoolslib.android_shell import AndroidShell
15 from devtoolslib.linux_shell import LinuxShell 11 from devtoolslib.linux_shell import LinuxShell
16 from devtoolslib import shell_arguments 12 from devtoolslib import shell_arguments
13 from devtoolslib import default_paths
17 14
18 from mopy.config import Config 15 USAGE = ("mojo_shell "
19 from mopy.paths import Paths
20
21 USAGE = ("mojo_shell.py "
22 "[--args-for=<mojo-app>] " 16 "[--args-for=<mojo-app>] "
23 "[--content-handlers=<handlers>] " 17 "[--content-handlers=<handlers>] "
24 "[--enable-external-applications] " 18 "[--enable-external-applications] "
25 "[--disable-cache] " 19 "[--disable-cache] "
26 "[--enable-multiprocess] " 20 "[--enable-multiprocess] "
27 "[--url-mappings=from1=to1,from2=to2] " 21 "[--url-mappings=from1=to1,from2=to2] "
28 "[<mojo-app>] " 22 "[<mojo-app>] "
29 """ 23 """
30 24
31 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. 25 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 parser.add_argument('--logcat-tags', 68 parser.add_argument('--logcat-tags',
75 help='(android-only) Comma-separated list of additional ' 69 help='(android-only) Comma-separated list of additional '
76 'logcat tags to display on the console.') 70 'logcat tags to display on the console.')
77 71
78 # Desktop-only arguments. 72 # Desktop-only arguments.
79 parser.add_argument('--use-osmesa', action='store_true', 73 parser.add_argument('--use-osmesa', action='store_true',
80 help='(linux-only) Configure the native viewport service ' 74 help='(linux-only) Configure the native viewport service '
81 'for off-screen rendering.') 75 'for off-screen rendering.')
82 76
83 launcher_args, args = parser.parse_known_args() 77 launcher_args, args = parser.parse_known_args()
78 paths, error_msg = default_paths.infer_default_paths(launcher_args.android,
79 launcher_args.debug,
80 launcher_args.target_cpu)
81 if not paths:
82 print error_msg
83 return -1
84
84 if launcher_args.android: 85 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 86 verbose_pipe = sys.stdout if launcher_args.verbose else None
90 87
91 shell = AndroidShell(paths.adb_path, launcher_args.target_device, 88 shell = AndroidShell(paths['adb'], launcher_args.target_device,
92 logcat_tags=launcher_args.logcat_tags, 89 logcat_tags=launcher_args.logcat_tags,
93 verbose_pipe=verbose_pipe) 90 verbose_pipe=verbose_pipe)
94 device_status, error = shell.CheckDevice() 91 device_status, error = shell.CheckDevice()
95 if not device_status: 92 if not device_status:
96 print 'Device check failed: ' + error 93 print 'Device check failed: ' + error
97 return 1 94 return 1
98 shell.InstallApk(paths.target_mojo_shell_path) 95 shell.InstallApk(paths['shell'])
99 96
100 args = shell_arguments.RewriteMapOriginParameters(shell, args) 97 args = shell_arguments.RewriteMapOriginParameters(shell, args)
101 if not launcher_args.origin: 98 if not launcher_args.origin:
102 args.extend(shell_arguments.ConfigureLocalOrigin(shell, paths.build_dir)) 99 args.extend(shell_arguments.ConfigureLocalOrigin(shell, paths['build']))
103 else: 100 else:
104 config = Config(target_os=Config.OS_LINUX, 101 shell = LinuxShell(paths['shell'])
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: 102 if launcher_args.use_osmesa:
110 args.append('--args-for=mojo:native_viewport_service --use-osmesa') 103 args.append('--args-for=mojo:native_viewport_service --use-osmesa')
111 104
112 if launcher_args.origin: 105 if launcher_args.origin:
113 args.append('--origin=' + launcher_args.origin) 106 args.append('--origin=' + launcher_args.origin)
114 args = shell_arguments.AppendToArgument(args, '--url-mappings=', 107 args = shell_arguments.AppendToArgument(args, '--url-mappings=',
115 'mojo:window_manager=%s' % 108 'mojo:window_manager=%s' %
116 launcher_args.window_manager) 109 launcher_args.window_manager)
117 if not launcher_args.no_debugger: 110 if not launcher_args.no_debugger:
118 args.extend(shell_arguments.ConfigureDebugger(shell)) 111 args.extend(shell_arguments.ConfigureDebugger(shell))
119 112
120 if launcher_args.sky: 113 if launcher_args.sky:
121 # Configure a server to serve the checkout root at / (so that Sky examples 114 # 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. 115 # are accessible using a root-relative path) and Sky packages at /packages.
123 # This is independent from the server that potentially serves the origin 116 # This is independent from the server that potentially serves the origin
124 # directory containing the mojo: apps. 117 # directory containing the mojo: apps.
125 packages_local_path = os.path.join(paths.build_dir, 'gen', 'dart-pkg',
126 'packages')
127 additional_mappings = [ 118 additional_mappings = [
128 ('packages/', packages_local_path), 119 ('packages/', paths['sky_packages']),
129 ] 120 ]
130 server_url = shell.ServeLocalDirectory(paths.src_root, 121 server_url = shell.ServeLocalDirectory(paths['root'],
131 port=_SKY_SERVER_PORT, additional_mappings=additional_mappings) 122 port=_SKY_SERVER_PORT, additional_mappings=additional_mappings)
132 123
133 # Configure the content type mappings for the sky_viewer. This is needed 124 # 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, 125 # 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 126 # and it is unfortunate as it configures the shell to map all items of the
136 # application/dart content-type as Sky apps. 127 # application/dart content-type as Sky apps.
137 # TODO(ppi): drop this part once we can rely on the Sky files declaring 128 # TODO(ppi): drop this part once we can rely on the Sky files declaring
138 # correct shebang. 129 # correct shebang.
139 args = shell_arguments.AppendToArgument(args, '--content-handlers=', 130 args = shell_arguments.AppendToArgument(args, '--content-handlers=',
140 'text/sky,mojo:sky_viewer') 131 'text/sky,mojo:sky_viewer')
141 args = shell_arguments.AppendToArgument(args, '--content-handlers=', 132 args = shell_arguments.AppendToArgument(args, '--content-handlers=',
142 'application/dart,mojo:sky_viewer') 133 'application/dart,mojo:sky_viewer')
143 134
144 # Configure the window manager to embed the sky_viewer. 135 # Configure the window manager to embed the sky_viewer.
145 sky_url = server_url + launcher_args.sky 136 sky_url = server_url + launcher_args.sky
146 args.append('mojo:window_manager %s' % sky_url) 137 args.append('mojo:window_manager %s' % sky_url)
147 138
148 if launcher_args.verbose: 139 if launcher_args.verbose:
149 print "Shell arguments: " + str(args) 140 print "Shell arguments: " + str(args)
150 141
151 shell.Run(args) 142 shell.Run(args)
152 return 0 143 return 0
153 144
154 145
155 if __name__ == "__main__": 146 if __name__ == "__main__":
156 sys.exit(main()) 147 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/devtools/common/devtoolslib/default_paths.py ('k') | mojo/tools/mojo_shell.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698