Adam Barth e16b5b6655 Teach skydb about --release and --debug
Previously, skydb could be used only for Debug builds. As part of working on
graphics performance, I'd like to use it for release builds as well. This CL
teaches it to use the same configuration arguments as sky_server, test_sky, and
test_perf.

The downside of this CL is that you'll need to supply --debug in the common
case of working with a debug build.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/746473003
2014-11-20 14:39:55 -08:00

115 lines
3.5 KiB
Python
Executable File

#!/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.
import argparse
import logging
import os
from skypy.paths import Paths
import skypy.configuration as configuration
import socket;
import subprocess
import sys
import urlparse
SUPPORTED_MIME_TYPES = [
'text/html',
'text/sky',
'text/plain',
]
class SkyDebugger(object):
def __init__(self):
self._sky_server = None
self.paths = None
@staticmethod
def _port_in_use(port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
return sock.connect_ex(('localhost', port)) == 0
def _start_http_server_for_file(self, path, configuration):
HTTP_PORT = 9999
path = os.path.abspath(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))
relative_path = os.path.relpath(path, server_root)
if self._port_in_use(HTTP_PORT):
logging.warn(
'Port %s already in use, assuming custom sky_server started.' %
HTTP_PORT)
else:
server_command = [
os.path.join(self.paths.sky_tools_directory, 'sky_server'),
'-t', configuration,
server_root,
str(HTTP_PORT),
]
self._sky_server = subprocess.Popen(server_command)
return 'http://localhost:%s/%s' % (HTTP_PORT, relative_path)
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', 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.url:
url = args.url
if not urlparse.urlparse(url).scheme:
url = self._start_http_server_for_file(url, args.configuration)
prompt_args = '--args-for=mojo:sky_debugger_prompt %s' % url
shell_command.append(prompt_args)
if args.use_osmesa:
shell_command.append('--args-for=mojo:native_viewport_service --use-osmesa')
if args.gdb:
shell_command = ['gdb', '--args'] + shell_command
subprocess.check_call(shell_command)
def shutdown(self):
print "Quitting"
if self._sky_server:
self._sky_server.terminate()
if __name__ == '__main__':
skydb = SkyDebugger()
try:
skydb.main()
except (KeyboardInterrupt, SystemExit):
pass
finally:
skydb.shutdown()