flutter_flutter/tools/skypy/skyserver.py
Eric Seidel 8ad5f14611 Currently we use package: to mean "/gen", which is not at all how
Dart actually expects package: to work.  This CL makes package:foo
map to /packages/foo, similar to how Dartium or bin/dart would expect.

This also means overlaying the /gen directory over the actual package
outputs (as consumers of an SDK would expect) as well as adding
an additional /lib indirection for the actual package source as
the Dart pub tool will expect.

This is far from perfect, but it unlocks us actually producing a
sky SDK.

I expect there may be some fallout from this change as I'm sure I
missed some package: uses.  We also don't have a general solution
for all /foo/bar/baz includes which randomly included parts
of mojo's source directory.  Those will need to be updated to use
a package: and deploy_sdk.py taught how to build a package for them.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/990493002
2015-03-13 16:58:53 -07:00

68 lines
2.0 KiB
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 socket
import subprocess
import logging
import os.path
SKYPY_PATH = os.path.dirname(os.path.abspath(__file__))
SKY_TOOLS_PATH = os.path.dirname(SKYPY_PATH)
SKY_ROOT = os.path.dirname(SKY_TOOLS_PATH)
SRC_ROOT = os.path.dirname(SKY_ROOT)
class SkyServer(object):
def __init__(self, port, configuration, root, package_root):
self.port = port
self.configuration = configuration
self.root = root
self.package_root = package_root
self.server = None
@staticmethod
def _port_in_use(port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
return sock.connect_ex(('localhost', port)) == 0
@staticmethod
def _download_server_if_necessary():
subprocess.call(os.path.join(SKY_TOOLS_PATH, 'download_sky_server'))
return os.path.join(SRC_ROOT, 'out', 'downloads', 'sky_server')
def start(self):
if self._port_in_use(self.port):
logging.warn(
'Port %s already in use, assuming custom sky_server started.' %
self.port)
return
server_path = self._download_server_if_necessary()
server_command = [
server_path,
'-t', self.configuration,
self.root,
str(self.port),
self.package_root,
]
self.server = subprocess.Popen(server_command)
return self.server.pid
def stop(self):
if self.server:
self.server.terminate()
def __enter__(self):
self.start()
def __exit__(self, exc_type, exc_value, traceback):
self.stop()
def path_as_url(self, path):
return self.url_for_path(self.port, self.root, path)
@staticmethod
def url_for_path(port, root, path):
relative_path = os.path.relpath(path, root)
return 'http://localhost:%s/%s' % (port, relative_path)