blob: 5fee198566078a9cbf5c12120da37e3e2fa91d3b [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from skypy.paths import Paths
from skypy.skyserver import SkyServer
import argparse
import logging
import os
import skypy.configuration as configuration
import subprocess
import urlparse
SUPPORTED_MIME_TYPES = [
'text/html',
'text/sky',
'text/plain',
]
HTTP_PORT = 9999
class SkyDebugger(object):
def __init__(self):
self.paths = None
def _server_root_and_url_from_path_arg(self, url_or_path):
# This is already a valid url we don't need a local server.
if urlparse.urlparse(url_or_path).scheme:
return None, url_or_path
path = os.path.abspath(url_or_path)
if os.path.commonprefix([path, self.paths.src_root]) == self.paths.src_root:
server_root = self.paths.src_root
else:
server_root = os.path.dirname(path)
logging.warn(
'%s is outside of mojo root, using %s as server root' %
(path, server_root))
local_url = SkyServer.url_for_path(HTTP_PORT, server_root, path)
return server_root, local_url
def _in_chromoting(self):
return os.environ.get('CHROME_REMOTE_DESKTOP_SESSION', False)
def main(self):
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description='Sky launcher/debugger')
parser.add_argument('--gdb', action='store_true')
parser.add_argument('--use-osmesa', action='store_true',
default=self._in_chromoting())
parser.add_argument('url_or_path', nargs='?', type=str)
configuration.add_arguments(parser)
args = parser.parse_args()
self.paths = Paths(os.path.join('out', args.configuration))
content_handlers = ['%s,%s' % (mime_type, 'mojo:sky_viewer')
for mime_type in SUPPORTED_MIME_TYPES]
shell_command = [
self.paths.mojo_shell_path,
'--v=1',
'--content-handlers=%s' % ','.join(content_handlers),
'--url-mappings=mojo:window_manager=mojo:sky_debugger',
'mojo:window_manager',
]
if args.use_osmesa:
shell_command.append('--args-for=mojo:native_viewport_service --use-osmesa')
server_root = None
if args.url_or_path:
# Check if we need a local server for the url/path arg:
server_root, url = \
self._server_root_and_url_from_path_arg(args.url_or_path)
prompt_args = '--args-for=mojo:sky_debugger_prompt %s' % url
shell_command.append(prompt_args)
if args.gdb:
shell_command = ['gdb', '--args'] + shell_command
if server_root:
with SkyServer(self.paths, HTTP_PORT, args.configuration,
server_root):
subprocess.check_call(shell_command)
else:
subprocess.check_call(shell_command)
if __name__ == '__main__':
SkyDebugger().main()