2010-04-28 Eric Seidel <eric@webkit.org>
[WebKit-https.git] / WebKitTools / Scripts / webkitpy / layout_tests / port / http_server.py
index c7fe6a8..fbe47e3 100755 (executable)
@@ -55,7 +55,7 @@ class HttpdNotStarted(Exception):
 class Lighttpd(http_server_base.HttpServerBase):
 
     def __init__(self, port_obj, output_dir, background=False, port=None,
-                 root=None, run_background=None):
+                 root=None, register_cygwin=None, run_background=None):
         """Args:
           output_dir: the absolute path to the layout test result directory
         """
@@ -65,6 +65,7 @@ class Lighttpd(http_server_base.HttpServerBase):
         self._process = None
         self._port = port
         self._root = root
+        self._register_cygwin = register_cygwin
         self._run_background = run_background
         if self._port:
             self._port = int(self._port)
@@ -198,7 +199,22 @@ class Lighttpd(http_server_base.HttpServerBase):
             shutil.copyfile(os.path.join(module_path, lib_file),
                             os.path.join(tmp_module_path, lib_file))
 
+        # Put the cygwin directory first in the path to find cygwin1.dll
+        env = os.environ
+        if sys.platform in ('cygwin', 'win32'):
+            env['PATH'] = '%s;%s' % (
+                self._port_obj.path_from_chromium_base('third_party',
+                                                       'cygwin', 'bin'),
+                env['PATH'])
+
+        if sys.platform == 'win32' and self._register_cygwin:
+            setup_mount = self._port_obj.path_from_chromium_base('third_party',
+                'cygwin', 'setup_mount.bat')
+            # FIXME: Should use Executive.run_command
+            subprocess.Popen(setup_mount).wait()
+
         _log.debug('Starting http server')
+        # FIXME: Should use Executive.run_command
         self._process = subprocess.Popen(start_cmd, env=env)
 
         # Wait for server to start.
@@ -225,5 +241,7 @@ class Lighttpd(http_server_base.HttpServerBase):
         self._port_obj._shut_down_http_server(httpd_pid)
 
         if self._process:
+            # wait() is not threadsafe and can throw OSError due to:
+            # http://bugs.python.org/issue1731717
             self._process.wait()
             self._process = None