OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Produces configured shell abstractions. | 5 """Produces configured shell abstractions. |
6 | 6 |
7 This module knows how to produce a configured shell abstraction based on | 7 This module knows how to produce a configured shell abstraction based on |
8 shell_config.ShellConfig. | 8 shell_config.ShellConfig. |
9 """ | 9 """ |
10 | 10 |
11 import os.path | 11 import os.path |
12 import urlparse | 12 import urlparse |
13 | 13 |
| 14 from devtoolslib import download |
| 15 from devtoolslib import paths |
14 from devtoolslib.android_shell import AndroidShell | 16 from devtoolslib.android_shell import AndroidShell |
15 from devtoolslib.linux_shell import LinuxShell | 17 from devtoolslib.linux_shell import LinuxShell |
16 from devtoolslib.shell_config import ShellConfigurationException | 18 from devtoolslib.shell_config import ShellConfigurationException |
17 | 19 |
18 # When spinning up servers for local origins, we want to use predictable ports | 20 # When spinning up servers for local origins, we want to use predictable ports |
19 # so that caching works between subsequent runs with the same command line. | 21 # so that caching works between subsequent runs with the same command line. |
20 _LOCAL_ORIGIN_PORT = 31840 | 22 _LOCAL_ORIGIN_PORT = 31840 |
21 _MAPPINGS_BASE_PORT = 31841 | 23 _MAPPINGS_BASE_PORT = 31841 |
22 | 24 |
23 | 25 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 once on the argument list (e.g. url-mappings) so we need to coalesce any | 188 once on the argument list (e.g. url-mappings) so we need to coalesce any |
187 overrides and the existing value into just one argument. | 189 overrides and the existing value into just one argument. |
188 | 190 |
189 Returns: | 191 Returns: |
190 A tuple of (shell, shell_args). |shell| is the configured shell abstraction, | 192 A tuple of (shell, shell_args). |shell| is the configured shell abstraction, |
191 |shell_args| is updated list of shell arguments. | 193 |shell_args| is updated list of shell arguments. |
192 | 194 |
193 Throws: | 195 Throws: |
194 ShellConfigurationException if shell abstraction could not be configured. | 196 ShellConfigurationException if shell abstraction could not be configured. |
195 """ | 197 """ |
| 198 platform = 'android-arm' if shell_config.android else 'linux-x64' |
| 199 |
| 200 shell_path = shell_config.shell_path |
| 201 if not shell_path and shell_config.mojo_version: |
| 202 download_dir = os.path.join(paths.DEVTOOLS_ROOT, '_prebuilt') |
| 203 shell_path = download.download_shell(shell_config.mojo_version, platform, |
| 204 download_dir, shell_config.verbose) |
| 205 if shell_config.verbose: |
| 206 if shell_path: |
| 207 print('Using shell binary at ' + shell_path) |
| 208 else: |
| 209 print('No shell path given, only running on Android with pre-installed ' |
| 210 'shell will be possible.') |
| 211 |
196 if shell_config.android: | 212 if shell_config.android: |
197 shell = AndroidShell(shell_config.adb_path, shell_config.target_device, | 213 shell = AndroidShell(shell_config.adb_path, shell_config.target_device, |
198 logcat_tags=shell_config.logcat_tags, | 214 logcat_tags=shell_config.logcat_tags, |
199 verbose=shell_config.verbose) | 215 verbose=shell_config.verbose) |
200 | 216 |
201 device_status, error = shell.check_device() | 217 device_status, error = shell.check_device() |
202 if not device_status: | 218 if not device_status: |
203 raise ShellConfigurationException('Device check failed: ' + error) | 219 raise ShellConfigurationException('Device check failed: ' + error) |
204 if shell_config.shell_path: | 220 if shell_path: |
205 shell.install_apk(shell_config.shell_path) | 221 shell.install_apk(shell_path) |
206 else: | 222 else: |
207 if not shell_config.shell_path: | 223 if not shell_path: |
208 raise ShellConfigurationException('Can not run without a shell binary. ' | 224 raise ShellConfigurationException('Can not run without a shell binary. ' |
209 'Please pass --shell-path.') | 225 'Please pass --mojo-version or ' |
210 shell = LinuxShell(shell_config.shell_path) | 226 '--shell-path.') |
| 227 shell = LinuxShell(shell_path) |
211 if shell_config.use_osmesa: | 228 if shell_config.use_osmesa: |
212 shell_args.append('--args-for=mojo:native_viewport_service --use-osmesa') | 229 shell_args.append('--args-for=mojo:native_viewport_service --use-osmesa') |
213 | 230 |
214 shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list, | 231 shell_args = _apply_mappings(shell, shell_args, shell_config.map_url_list, |
215 shell_config.map_origin_list, | 232 shell_config.map_origin_list, |
216 shell_config.reuse_servers) | 233 shell_config.reuse_servers) |
217 | 234 |
| 235 # Configure origin for mojo: urls. |
218 if shell_config.origin: | 236 if shell_config.origin: |
| 237 # If origin was set on the command line, this takes precedence. |
219 if _is_web_url(shell_config.origin): | 238 if _is_web_url(shell_config.origin): |
220 shell_args.append('--origin=' + shell_config.origin) | 239 shell_args.append('--origin=' + shell_config.origin) |
221 else: | 240 else: |
222 local_origin_port = _LOCAL_ORIGIN_PORT | 241 local_origin_port = _LOCAL_ORIGIN_PORT |
223 shell_args.extend(configure_local_origin(shell, shell_config.origin, | 242 shell_args.extend(configure_local_origin(shell, shell_config.origin, |
224 local_origin_port, | 243 local_origin_port, |
225 shell_config.reuse_servers)) | 244 shell_config.reuse_servers)) |
| 245 elif shell_config.mojo_version: |
| 246 # Otherwise we infer the origin from the mojo_version. |
| 247 web_origin = "https://storage.googleapis.com/mojo/services/%s/%s" % ( |
| 248 platform, shell_config.mojo_version) |
| 249 if shell_config.verbose: |
| 250 print('Inferring origin from `MOJO_VERSION` as: ' + web_origin) |
| 251 shell_args.append('--origin=' + web_origin) |
226 | 252 |
227 if shell_config.content_handlers: | 253 if shell_config.content_handlers: |
228 for (mime_type, | 254 for (mime_type, |
229 content_handler_url) in shell_config.content_handlers.iteritems(): | 255 content_handler_url) in shell_config.content_handlers.iteritems(): |
230 shell_args = append_to_argument(shell_args, '--content-handlers=', | 256 shell_args = append_to_argument(shell_args, '--content-handlers=', |
231 '%s,%s' % (mime_type, | 257 '%s,%s' % (mime_type, |
232 content_handler_url)) | 258 content_handler_url)) |
233 | 259 |
234 for dev_server_config in shell_config.dev_servers: | 260 for dev_server_config in shell_config.dev_servers: |
235 shell_args = _configure_dev_server(shell, shell_args, dev_server_config, | 261 shell_args = _configure_dev_server(shell, shell_args, dev_server_config, |
236 shell_config.reuse_servers, | 262 shell_config.reuse_servers, |
237 shell_config.verbose) | 263 shell_config.verbose) |
238 | 264 |
239 return shell, shell_args | 265 return shell, shell_args |
OLD | NEW |