OLD | NEW |
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 skypy.paths | 6 import skypy.paths |
7 from skypy.skyserver import SkyServer | 7 from skypy.skyserver import SkyServer |
8 import argparse | 8 import argparse |
9 import json | 9 import json |
10 import logging | 10 import logging |
(...skipping 18 matching lines...) Expand all Loading... |
29 'text/sky', | 29 'text/sky', |
30 'text/plain', | 30 'text/plain', |
31 ] | 31 ] |
32 | 32 |
33 DEFAULT_SKY_COMMAND_PORT = 7777 | 33 DEFAULT_SKY_COMMAND_PORT = 7777 |
34 GDB_PORT = 8888 | 34 GDB_PORT = 8888 |
35 SKY_SERVER_PORT = 9999 | 35 SKY_SERVER_PORT = 9999 |
36 PID_FILE_PATH = "/tmp/skydb.pids" | 36 PID_FILE_PATH = "/tmp/skydb.pids" |
37 DEFAULT_URL = "https://raw.githubusercontent.com/domokit/mojo/master/sky/example
s/home.sky" | 37 DEFAULT_URL = "https://raw.githubusercontent.com/domokit/mojo/master/sky/example
s/home.sky" |
38 | 38 |
| 39 ANDROID_PACKAGE = "org.chromium.mojo.shell" |
| 40 ANDROID_ACTIVITY = "%s/.MojoShellActivity" % ANDROID_PACKAGE |
39 | 41 |
40 # FIXME: Move this into mopy.config | 42 # FIXME: Move this into mopy.config |
41 def gn_args_from_build_dir(build_dir): | 43 def gn_args_from_build_dir(build_dir): |
42 gn_cmd = [ | 44 gn_cmd = [ |
43 'gn', 'args', | 45 'gn', 'args', |
44 build_dir, | 46 build_dir, |
45 '--list', '--short' | 47 '--list', '--short' |
46 ] | 48 ] |
47 config = {} | 49 config = {} |
48 for line in subprocess.check_output(gn_cmd).strip().split('\n'): | 50 for line in subprocess.check_output(gn_cmd).strip().split('\n'): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 # am shell --esa: (someone shoot me now) | 83 # am shell --esa: (someone shoot me now) |
82 # [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] | 84 # [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]] |
83 # (to embed a comma into a string escape it using "\,") | 85 # (to embed a comma into a string escape it using "\,") |
84 escaped_args = map(lambda arg: arg.replace(',', '\\,'), shell_args) | 86 escaped_args = map(lambda arg: arg.replace(',', '\\,'), shell_args) |
85 return [ | 87 return [ |
86 'adb', 'shell', | 88 'adb', 'shell', |
87 'am', 'start', | 89 'am', 'start', |
88 '-W', | 90 '-W', |
89 '-S', | 91 '-S', |
90 '-a', 'android.intent.action.VIEW', | 92 '-a', 'android.intent.action.VIEW', |
91 '-n', 'org.chromium.mojo.shell/.MojoShellActivity', | 93 '-n', ANDROID_ACTIVITY, |
92 # FIXME: This quoting is very error-prone. Perhaps we should read | 94 # FIXME: This quoting is very error-prone. Perhaps we should read |
93 # our args from a file instead? | 95 # our args from a file instead? |
94 '--esa', 'parameters', ','.join(escaped_args), | 96 '--esa', 'parameters', ','.join(escaped_args), |
95 ] | 97 ] |
96 | 98 |
97 def _build_mojo_shell_command(self, args): | 99 def _build_mojo_shell_command(self, args): |
98 content_handlers = ['%s,%s' % (mime_type, 'mojo:sky_viewer') | 100 content_handlers = ['%s,%s' % (mime_type, 'mojo:sky_viewer') |
99 for mime_type in SUPPORTED_MIME_TYPES] | 101 for mime_type in SUPPORTED_MIME_TYPES] |
100 | 102 |
101 remote_command_port = self.pids.get('remote_sky_command_port', self.pids
['sky_command_port']) | 103 remote_command_port = self.pids.get('remote_sky_command_port', self.pids
['sky_command_port']) |
102 | 104 |
103 shell_args = [ | 105 shell_args = [ |
104 '--v=1', | 106 '--v=1', |
105 '--content-handlers=%s' % ','.join(content_handlers), | 107 '--content-handlers=%s' % ','.join(content_handlers), |
106 '--url-mappings=mojo:window_manager=mojo:sky_debugger', | 108 '--url-mappings=mojo:window_manager=mojo:sky_debugger', |
107 '--args-for=mojo:sky_debugger_prompt %d' % remote_command_port, | 109 '--args-for=mojo:sky_debugger_prompt %d' % remote_command_port, |
108 'mojo:window_manager', | 110 'mojo:window_manager', |
109 ] | 111 ] |
110 # FIXME: This probably is wrong for android? | |
111 if args.use_osmesa: | |
112 shell_args.append('--args-for=mojo:native_viewport_service --use-osm
esa') | |
113 | 112 |
114 if 'remote_sky_server_port' in self.pids: | 113 if 'remote_sky_server_port' in self.pids: |
115 shell_command = self._wrap_for_android(shell_args) | 114 shell_command = self._wrap_for_android(shell_args) |
116 else: | 115 else: |
117 shell_command = [self.paths.mojo_shell_path] + shell_args | 116 shell_command = [self.paths.mojo_shell_path] + shell_args |
118 | 117 |
119 return shell_command | 118 return shell_command |
120 | 119 |
121 def _connect_to_device(self): | 120 def _connect_to_device(self): |
122 device = android_commands.AndroidCommands( | 121 device = android_commands.AndroidCommands( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 self.pids['remote_sky_server_port'] = device_http_port | 171 self.pids['remote_sky_server_port'] = device_http_port |
173 | 172 |
174 port_string = 'tcp:%s' % args.command_port | 173 port_string = 'tcp:%s' % args.command_port |
175 subprocess.check_call([ | 174 subprocess.check_call([ |
176 'adb', 'forward', port_string, port_string | 175 'adb', 'forward', port_string, port_string |
177 ]) | 176 ]) |
178 self.pids['remote_sky_command_port'] = args.command_port | 177 self.pids['remote_sky_command_port'] = args.command_port |
179 | 178 |
180 shell_command = self._build_mojo_shell_command(args) | 179 shell_command = self._build_mojo_shell_command(args) |
181 | 180 |
182 # On android we can't launch inside gdb, but rather have to attach. | 181 if not is_android: |
183 if args.gdb and not is_android: | 182 # Desktop-only work-around for mojo crashing under chromoting. |
184 shell_command = ['gdbserver', ':%s' % GDB_PORT] + shell_command | 183 if args.use_osmesa: |
| 184 shell_args.append( |
| 185 '--args-for=mojo:native_viewport_service --use-osmesa') |
| 186 |
| 187 # On android we can't launch inside gdb, but rather have to attach. |
| 188 if args.gdb: |
| 189 shell_command = ['gdbserver', ':%s' % GDB_PORT] + shell_command |
185 | 190 |
186 print ' '.join(map(pipes.quote, shell_command)) | 191 print ' '.join(map(pipes.quote, shell_command)) |
187 self.pids['mojo_shell_pid'] = subprocess.Popen(shell_command).pid | 192 self.pids['mojo_shell_pid'] = subprocess.Popen(shell_command).pid |
188 | 193 |
189 if args.gdb and is_android: | 194 if args.gdb and is_android: |
190 gdbserver_cmd = ['gdbserver', '--attach', ':%s' % GDB_PORT] | 195 gdbserver_cmd = ['gdbserver', '--attach', ':%s' % GDB_PORT] |
191 self.pids['remote_gdbserver_pid'] = subprocess.Popen(shell_command).
pid | 196 self.pids['remote_gdbserver_pid'] = subprocess.Popen(shell_command).
pid |
192 | 197 |
193 port_string = 'tcp:%s' % GDB_PORT | 198 port_string = 'tcp:%s' % GDB_PORT |
194 subprocess.check_call([ | 199 subprocess.check_call([ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if 'remote_sky_server_port' in self.pids: | 231 if 'remote_sky_server_port' in self.pids: |
227 device = android_commands.AndroidCommands( | 232 device = android_commands.AndroidCommands( |
228 self.pids['device_serial']) | 233 self.pids['device_serial']) |
229 forwarder.Forwarder.UnmapAllDevicePorts(device) | 234 forwarder.Forwarder.UnmapAllDevicePorts(device) |
230 | 235 |
231 if 'remote_sky_command_port' in self.pids: | 236 if 'remote_sky_command_port' in self.pids: |
232 # adb forward --remove takes the *host* port, not the remote port. | 237 # adb forward --remove takes the *host* port, not the remote port. |
233 port_string = 'tcp:%s' % self.pids['sky_command_port'] | 238 port_string = 'tcp:%s' % self.pids['sky_command_port'] |
234 subprocess.call(['adb', 'forward', '--remove', port_string]) | 239 subprocess.call(['adb', 'forward', '--remove', port_string]) |
235 | 240 |
| 241 subprocess.call([ |
| 242 'adb', 'shell', 'am', 'force-stop', ANDROID_PACKAGE]) |
| 243 |
236 if 'remote_gdbserver_port' in self.pids: | 244 if 'remote_gdbserver_port' in self.pids: |
237 port_string = 'tcp:%s' % self.pids['remote_gdbserver_port'] | 245 port_string = 'tcp:%s' % self.pids['remote_gdbserver_port'] |
238 subprocess.call(['adb', 'forward', '--remove', port_string]) | 246 subprocess.call(['adb', 'forward', '--remove', port_string]) |
239 | 247 |
240 def load_command(self, args): | 248 def load_command(self, args): |
241 if not urlparse.urlparse(args.url_or_path).scheme: | 249 if not urlparse.urlparse(args.url_or_path).scheme: |
242 # The load happens on the remote device, use the remote port. | 250 # The load happens on the remote device, use the remote port. |
243 remote_sky_server_port = self.pids.get('remote_sky_server_port', | 251 remote_sky_server_port = self.pids.get('remote_sky_server_port', |
244 self.pids['sky_server_port']) | 252 self.pids['sky_server_port']) |
245 url = SkyServer.url_for_path(remote_sky_server_port, | 253 url = SkyServer.url_for_path(remote_sky_server_port, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 load_parser.set_defaults(func=self.load_command) | 374 load_parser.set_defaults(func=self.load_command) |
367 | 375 |
368 args = parser.parse_args() | 376 args = parser.parse_args() |
369 args.func(args) | 377 args.func(args) |
370 | 378 |
371 self._write_pid_file(PID_FILE_PATH, self.pids) | 379 self._write_pid_file(PID_FILE_PATH, self.pids) |
372 | 380 |
373 | 381 |
374 if __name__ == '__main__': | 382 if __name__ == '__main__': |
375 SkyDebugger().main() | 383 SkyDebugger().main() |
OLD | NEW |