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

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

Issue 1153213005: Extract argument-rewriting map-origin magic to devtoolslib/shell_arguments. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Better names are better. Created 5 years, 6 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/shell_arguments.py ('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 6 import argparse
7 import logging 7 import logging
8 import sys 8 import sys
9 import urlparse
10 9
11 import devtools 10 import devtools
12 devtools.add_lib_to_path() 11 devtools.add_lib_to_path()
13 from devtoolslib.android_shell import AndroidShell 12 from devtoolslib.android_shell import AndroidShell
13 from devtoolslib import shell_arguments
14 14
15 from mopy.config import Config 15 from mopy.config import Config
16 from mopy.paths import Paths 16 from mopy.paths import Paths
17 17
18 USAGE = ("android_mojo_shell.py " 18 USAGE = ("android_mojo_shell.py "
19 "[--args-for=<mojo-app>] " 19 "[--args-for=<mojo-app>] "
20 "[--content-handlers=<handlers>] " 20 "[--content-handlers=<handlers>] "
21 "[--enable-external-applications] " 21 "[--enable-external-applications] "
22 "[--disable-cache] " 22 "[--disable-cache] "
23 "[--enable-multiprocess] " 23 "[--enable-multiprocess] "
24 "[--url-mappings=from1=to1,from2=to2] " 24 "[--url-mappings=from1=to1,from2=to2] "
25 "[<mojo-app>] " 25 "[<mojo-app>] "
26 """ 26 """
27 27
28 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes. 28 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.
29 Example: mojo_shell "mojo:js_standalone test.js". 29 Example: mojo_shell "mojo:js_standalone test.js".
30 <url-lib-path> is searched for shared libraries named by mojo URLs. 30 <url-lib-path> is searched for shared libraries named by mojo URLs.
31 The value of <handlers> is a comma separated list like: 31 The value of <handlers> is a comma separated list like:
32 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler 32 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler
33 """) 33 """)
34 34
35 _MAPPING_PREFIX = '--map-origin='
36 # When spinning up servers for local origins, we want to use predictable ports
37 # so that caching works between subsequent runs with the same command line.
38 _MAP_ORIGIN_BASE_PORT = 31338
39
40
41 def _IsMapOrigin(arg):
42 """Returns whether |arg| is a --map-origin argument."""
43 return arg.startswith(_MAPPING_PREFIX)
44
45
46 def _Split(l, pred):
47 positive = []
48 negative = []
49 for v in l:
50 if pred(v):
51 positive.append(v)
52 else:
53 negative.append(v)
54 return (positive, negative)
55
56
57 def _RewriteMapOriginParameter(shell, mapping, device_port):
58 parts = mapping[len(_MAPPING_PREFIX):].split('=')
59 if len(parts) != 2:
60 return mapping
61 dest = parts[1]
62 # If the destination is a url, don't map it.
63 if urlparse.urlparse(dest)[0]:
64 return mapping
65 # Assume the destination is a local directory and serve it.
66 localUrl = shell.ServeLocalDirectory(dest, device_port)
67 print 'started server at %s for %s' % (dest, localUrl)
68 return _MAPPING_PREFIX + parts[0] + '=' + localUrl
69
70 35
71 def main(): 36 def main():
72 logging.basicConfig() 37 logging.basicConfig()
73 38
74 parser = argparse.ArgumentParser(usage=USAGE) 39 parser = argparse.ArgumentParser(usage=USAGE)
75 40
76 debug_group = parser.add_mutually_exclusive_group() 41 debug_group = parser.add_mutually_exclusive_group()
77 debug_group.add_argument('--debug', help='Debug build (default)', 42 debug_group.add_argument('--debug', help='Debug build (default)',
78 default=True, action='store_true') 43 default=True, action='store_true')
79 debug_group.add_argument('--release', help='Release build', default=False, 44 debug_group.add_argument('--release', help='Release build', default=False,
(...skipping 12 matching lines...) Expand all
92 target_cpu=launcher_args.target_cpu, 57 target_cpu=launcher_args.target_cpu,
93 is_debug=launcher_args.debug) 58 is_debug=launcher_args.debug)
94 paths = Paths(config) 59 paths = Paths(config)
95 verbose_pipe = sys.stdout if launcher_args.verbose else None 60 verbose_pipe = sys.stdout if launcher_args.verbose else None
96 shell = AndroidShell(paths.adb_path, launcher_args.target_device, 61 shell = AndroidShell(paths.adb_path, launcher_args.target_device,
97 logcat_tags=launcher_args.logcat_tags, 62 logcat_tags=launcher_args.logcat_tags,
98 verbose_pipe=verbose_pipe) 63 verbose_pipe=verbose_pipe)
99 shell.InstallApk(paths.target_mojo_shell_path) 64 shell.InstallApk(paths.target_mojo_shell_path)
100 args.append("--origin=" + launcher_args.origin if launcher_args.origin else 65 args.append("--origin=" + launcher_args.origin if launcher_args.origin else
101 shell.SetUpLocalOrigin(paths.build_dir)) 66 shell.SetUpLocalOrigin(paths.build_dir))
102 67 args = shell_arguments.RewriteMapOriginParameters(shell, args)
103 # Serve the local destinations indicated in map-origin arguments and rewrite 68 shell.Run(args)
104 # the arguments to point to server urls.
105 map_parameters, other_parameters = _Split(args, _IsMapOrigin)
106 parameters = other_parameters
107 next_port = _MAP_ORIGIN_BASE_PORT
108 for mapping in sorted(map_parameters):
109 parameters.append(_RewriteMapOriginParameter(shell, mapping, next_port))
110 next_port += 1
111 shell.Run(parameters)
112 return 0 69 return 0
113 70
114 71
115 if __name__ == "__main__": 72 if __name__ == "__main__":
116 sys.exit(main()) 73 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/devtools/common/devtoolslib/shell_arguments.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698