mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
We keep seeing timeouts on the bots that seem to be due to cherrypy dropping requests on the floor, which in turn causes imports to stall, which causes the test to time out. In local testing, I was able to reproduce the timeouts and wasn't able to do so with the go-based server. R=abarth@chromium.org, eseidel@chromium.org Review URL: https://codereview.chromium.org/746373002
117 lines
3.7 KiB
Python
Executable File
117 lines
3.7 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:
|
|
subprocess.call(os.path.join(self.paths.sky_tools_directory,
|
|
'download_sky_server'))
|
|
server_command = [
|
|
os.path.join(self.paths.src_root, 'out', 'downloads', '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()
|