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

Side by Side Diff: mojo/devtools/common/devtoolslib/shell_arguments.py

Issue 1256843004: Merge --origin and --origin-path in devtools scripts. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | mojo/devtools/common/mojo_run » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Functions that configure the shell before it is run manipulating its argument 5 """Functions that configure the shell before it is run manipulating its argument
6 list. 6 list.
7 """ 7 """
8 8
9 import os.path 9 import os.path
10 import sys 10 import sys
11 import urlparse 11 import urlparse
12 12
13 from devtoolslib.android_shell import AndroidShell 13 from devtoolslib.android_shell import AndroidShell
14 from devtoolslib.linux_shell import LinuxShell 14 from devtoolslib.linux_shell import LinuxShell
15 15
16 # When spinning up servers for local origins, we want to use predictable ports 16 # When spinning up servers for local origins, we want to use predictable ports
17 # so that caching works between subsequent runs with the same command line. 17 # so that caching works between subsequent runs with the same command line.
18 _LOCAL_ORIGIN_PORT = 31840 18 _LOCAL_ORIGIN_PORT = 31840
19 _MAPPINGS_BASE_PORT = 31841 19 _MAPPINGS_BASE_PORT = 31841
20 20
21 _SKY_SERVER_PORT = 9998 21 _SKY_SERVER_PORT = 9998
22 22
23 23
24 def _IsWebUrl(dest):
25 return True if urlparse.urlparse(dest).scheme else False
26
27
24 def _HostLocalUrlDestination(shell, dest_file, port): 28 def _HostLocalUrlDestination(shell, dest_file, port):
25 """Starts a local server to host |dest_file|. 29 """Starts a local server to host |dest_file|.
26 30
27 Returns: 31 Returns:
28 Url of the hosted file. 32 Url of the hosted file.
29 """ 33 """
30 directory = os.path.dirname(dest_file) 34 directory = os.path.dirname(dest_file)
31 if not os.path.exists(directory): 35 if not os.path.exists(directory):
32 raise ValueError('local path passed as --map-url destination ' 36 raise ValueError('local path passed as --map-url destination '
33 'does not exist') 37 'does not exist')
(...skipping 11 matching lines...) Expand all
45 49
46 50
47 def _Rewrite(mapping, host_destination_functon, shell, port): 51 def _Rewrite(mapping, host_destination_functon, shell, port):
48 """Takes a mapping given as <src>=<dest> and rewrites the <dest> part to be 52 """Takes a mapping given as <src>=<dest> and rewrites the <dest> part to be
49 hosted locally using the given function if <dest> is not a web url. 53 hosted locally using the given function if <dest> is not a web url.
50 """ 54 """
51 parts = mapping.split('=') 55 parts = mapping.split('=')
52 if len(parts) != 2: 56 if len(parts) != 2:
53 raise ValueError('each mapping value should be in format ' 57 raise ValueError('each mapping value should be in format '
54 '"<url>=<url-or-local-path>"') 58 '"<url>=<url-or-local-path>"')
55 if urlparse.urlparse(parts[1])[0]: 59 if _IsWebUrl(parts[1]):
56 # The destination is a web url, do nothing. 60 # The destination is a web url, do nothing.
57 return mapping 61 return mapping
58 62
59 src = parts[0] 63 src = parts[0]
60 dest = host_destination_functon(shell, parts[1], port) 64 dest = host_destination_functon(shell, parts[1], port)
61 return src + '=' + dest 65 return src + '=' + dest
62 66
63 67
64 def _ApplyMappings(shell, original_arguments, map_urls, map_origins): 68 def _ApplyMappings(shell, original_arguments, map_urls, map_origins):
65 """Applies mappings for specified urls and origins. For each local path 69 """Applies mappings for specified urls and origins. For each local path
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 return arguments 185 return arguments
182 186
183 187
184 def AddShellArguments(parser): 188 def AddShellArguments(parser):
185 """Adds argparse arguments allowing to configure shell abstraction using 189 """Adds argparse arguments allowing to configure shell abstraction using
186 ConfigureShell() below. 190 ConfigureShell() below.
187 """ 191 """
188 # Arguments indicating paths to binaries and tools. 192 # Arguments indicating paths to binaries and tools.
189 parser.add_argument('--adb-path', help='Path of the adb binary.') 193 parser.add_argument('--adb-path', help='Path of the adb binary.')
190 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') 194 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.')
191 parser.add_argument('--origin-path', help='Path of a directory to be set as '
192 'the origin for mojo: urls')
193 195
194 # Arguments configuring the shell run. 196 # Arguments configuring the shell run.
195 parser.add_argument('--android', help='Run on Android', 197 parser.add_argument('--android', help='Run on Android',
196 action='store_true') 198 action='store_true')
197 parser.add_argument('--origin', help='Origin for mojo: URLs.') 199 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a '
200 'web url or a local directory path.')
198 parser.add_argument('--map-url', action='append', 201 parser.add_argument('--map-url', action='append',
199 help='Define a mapping for a url in the format ' 202 help='Define a mapping for a url in the format '
200 '<url>=<url-or-local-file-path>') 203 '<url>=<url-or-local-file-path>')
201 parser.add_argument('--map-origin', action='append', 204 parser.add_argument('--map-origin', action='append',
202 help='Define a mapping for a url origin in the format ' 205 help='Define a mapping for a url origin in the format '
203 '<origin>=<url-or-local-file-path>') 206 '<origin>=<url-or-local-file-path>')
204 207
205 # Android-only arguments. 208 # Android-only arguments.
206 parser.add_argument('--target-device', 209 parser.add_argument('--target-device',
207 help='(android-only) Device to run on.') 210 help='(android-only) Device to run on.')
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 config_args.map_origin) 261 config_args.map_origin)
259 else: 262 else:
260 if not config_args.shell_path: 263 if not config_args.shell_path:
261 raise ShellConfigurationException('Can not run without a shell binary. ' 264 raise ShellConfigurationException('Can not run without a shell binary. '
262 'Please pass --shell-path.') 265 'Please pass --shell-path.')
263 shell = LinuxShell(config_args.shell_path) 266 shell = LinuxShell(config_args.shell_path)
264 if config_args.use_osmesa: 267 if config_args.use_osmesa:
265 shell_args.append('--args-for=mojo:native_viewport_service --use-osmesa') 268 shell_args.append('--args-for=mojo:native_viewport_service --use-osmesa')
266 269
267 if config_args.origin: 270 if config_args.origin:
268 shell_args.append('--origin=' + config_args.origin) 271 if _IsWebUrl(config_args.origin):
269 elif config_args.origin_path: 272 shell_args.append('--origin=' + config_args.origin)
270 shell_args.extend(ConfigureLocalOrigin(shell, config_args.origin_path, 273 else:
271 fixed_port=True)) 274 shell_args.extend(ConfigureLocalOrigin(shell, config_args.origin,
275 fixed_port=True))
272 276
273 return shell, shell_args 277 return shell, shell_args
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_run » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698