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

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

Issue 803573002: Add a launcher script for the mojo shell on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years 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 | 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import argparse
7 import atexit
8 import logging
9 import threading
10 import os
11 import sys
12
13 import SimpleHTTPServer
14 import SocketServer
15
16 from mopy.config import Config
17 from mopy.paths import Paths
18
19 sys.path.insert(0, os.path.join(Paths().src_root, 'build', 'android'))
20 from pylib import android_commands
21 from pylib import constants
22 from pylib import forwarder
23
24 TAGS = [
25 'AndroidHandler',
26 'MojoMain',
27 'MojoShellActivity',
28 'MojoShellApplication',
29 'chromium',
30 ]
31
32 USAGE = ("android_mojo_shell.py "
33 "[--args-for=<mojo-app>] "
sky 2014/12/15 17:13:31 You don't have --debug/--release here.
qsr 2014/12/15 17:20:13 The one this script handled will be handled by arp
34 "[--content-handlers=<handlers>] "
sky 2014/12/15 17:13:31 Many of the arguments you have here aren't handled
qsr 2014/12/15 17:20:13 Yes, all the option that I pass to the shell are n
35 "[--enable-external-applications] "
36 "[--disable-cache] "
37 "[--enable-multiprocess] "
38 "[--url-mappings=from1=to1,from2=to2] "
39 "[<mojo-app> | --no-url] "
40 """
41
42 A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.
43 Example: mojo_shell "mojo:js_standalone test.js".
44 <url-lib-path> is searched for shared libraries named by mojo URLs.
sky 2014/12/15 17:13:31 This comment is out of date.
qsr 2014/12/15 17:20:13 This comment is the one for mojo_shell --help. Not
45 The value of <handlers> is a comma separated list like:
46 text/html,mojo:html_viewer,application/javascript,mojo:js_content_handler
47 """)
48
49 def GetHandlerForPath(base_path):
50 class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
51 """
52 Handler for SocketServer.TCPServer that will serve the files from
53 |base_path| directory over http.
54 """
55
56 def translate_path(self, path):
57 path_from_current = (
58 SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path))
59 return os.path.join(base_path, os.path.relpath(path_from_current))
60
61 return RequestHandler
62
63 def main():
64 logging.basicConfig()
65
66 parser = argparse.ArgumentParser(usage=USAGE)
67
68 debug_group = parser.add_mutually_exclusive_group()
69 debug_group.add_argument('--debug', help='Debug build (default)',
70 default=True, action='store_true')
71 debug_group.add_argument('--release', help='Release build', default=False,
72 dest='debug', action='store_false')
73 parser.add_argument('--no-url',
74 help='Allows not to provide a application URL',
75 action='store_true')
76 launcher_args, args = parser.parse_known_args()
77
78 paths = Paths(Config(target_os=Config.OS_ANDROID,
79 is_debug=launcher_args.debug))
80 constants.SetOutputDirectort(paths.build_dir)
81
82 httpd = SocketServer.TCPServer(('127.0.0.1', 0),
83 GetHandlerForPath(paths.build_dir))
84 atexit.register(httpd.shutdown)
85 port = httpd.server_address[1]
86
87 http_thread = threading.Thread(target=httpd.serve_forever)
88 http_thread.daemon = True
89 http_thread.start()
90
91 device = android_commands.AndroidCommands(
92 android_commands.GetAttachedDevices()[0])
93 device.EnableAdbRoot()
94
95 atexit.register(forwarder.Forwarder.UnmapAllDevicePorts, device)
96 forwarder.Forwarder.Map([(0, port)], device)
97 device_port = forwarder.Forwarder.DevicePortForHostPort(port)
98
99 cmd = ('am start'
100 ' -W'
101 ' -S'
102 ' -a android.intent.action.VIEW'
103 ' -n org.chromium.mojo_shell_apk/.MojoShellActivity')
104
105 parameters = [
106 '--origin=http://127.0.0.1:%d/' % device_port
107 ]
108
109 url = None
110 if launcher_args.no_url:
111 parameters += args
112 else:
113 url = args[-1]
114 parameters += args[:-1]
115
116 cmd += ' --esa parameters \"%s\"' % ','.join(parameters)
117
118 if url:
119 cmd += ' -d %s' % url
120
121 device.RunShellCommand('logcat -c')
122 device.RunShellCommand(cmd)
123 os.system("%s logcat -s %s" % (constants.GetAdbPath(), ' '.join(TAGS)))
124 device.RunShellCommand("am force-stop org.chromium.mojo_shell_apk")
125 return 0
126
127 if __name__ == "__main__":
128 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698