<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[196778] trunk/Tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196778">196778</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2016-02-18 14:31:49 -0800 (Thu, 18 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>run-webkit-httpd should use webkitpy to run httpd.
https://bugs.webkit.org/show_bug.cgi?id=154271

Reviewed by Alexey Proskuryakov.

Update run-webkit-httpd to use webkitpy.port to launch httpd. Pass on http_port and http_all_interface
options to match the current run-webkit-httpd (optional) behavior.

* Scripts/run-webkit-httpd:
(parse_args):
(main):
* Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
(LayoutTestApacheHttpd.__init__):
* Scripts/webkitpy/layout_tests/servers/http_server.py:
(Lighttpd._prepare_config):
* Scripts/webkitpy/port/base.py:
(Port.to.start_http_server):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsrunwebkithttpd">trunk/Tools/Scripts/run-webkit-httpd</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testsserversapache_http_serverpy">trunk/Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py</a></li>
<li><a href="#trunkToolsScriptswebkitpylayout_testsservershttp_serverpy">trunk/Tools/Scripts/webkitpy/layout_tests/servers/http_server.py</a></li>
<li><a href="#trunkToolsScriptswebkitpyportbasepy">trunk/Tools/Scripts/webkitpy/port/base.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (196777 => 196778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-02-18 21:58:15 UTC (rev 196777)
+++ trunk/Tools/ChangeLog        2016-02-18 22:31:49 UTC (rev 196778)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2016-02-18  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        run-webkit-httpd should use webkitpy to run httpd.
+        https://bugs.webkit.org/show_bug.cgi?id=154271
+
+        Reviewed by Alexey Proskuryakov.
+
+        Update run-webkit-httpd to use webkitpy.port to launch httpd. Pass on http_port and http_all_interface
+        options to match the current run-webkit-httpd (optional) behavior.
+
+        * Scripts/run-webkit-httpd:
+        (parse_args):
+        (main):
+        * Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
+        (LayoutTestApacheHttpd.__init__):
+        * Scripts/webkitpy/layout_tests/servers/http_server.py:
+        (Lighttpd._prepare_config):
+        * Scripts/webkitpy/port/base.py:
+        (Port.to.start_http_server):
+
</ins><span class="cx"> 2016-02-18  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove remaining references to LLVM, and make sure comments refer to the backend as &quot;B3&quot; not &quot;LLVM&quot;
</span></span></pre></div>
<a id="trunkToolsScriptsrunwebkithttpd"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/run-webkit-httpd (196777 => 196778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/run-webkit-httpd        2016-02-18 21:58:15 UTC (rev 196777)
+++ trunk/Tools/Scripts/run-webkit-httpd        2016-02-18 22:31:49 UTC (rev 196778)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-#!/usr/bin/perl
</del><ins>+#!/usr/bin/python
</ins><span class="cx"> 
</span><span class="cx"> # Copyright (C) 2005, 2006, 2007, 2015 Apple Inc.  All rights reserved.
</span><span class="cx"> # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
</span><span class="lines">@@ -28,73 +28,51 @@
</span><span class="cx"> # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
</span><span class="cx"> # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx"> 
</span><del>-# Script to run Apache with the same configuration as used in http layout tests.
</del><ins>+import optparse
+import subprocess
+import sys
+import tempfile
+import time
</ins><span class="cx"> 
</span><del>-use strict;
-use warnings;
</del><ins>+from webkitpy.common.host import Host
+from webkitpy.port import platform_options
</ins><span class="cx"> 
</span><del>-use Cwd;
-use File::Path;
-use File::Basename;
-use Getopt::Long;
-use FindBin;
</del><ins>+def parse_args(args):
+    parser = optparse.OptionParser()
+    parser.add_option(&quot;-a&quot;, &quot;--all-interfaces&quot;, help=&quot;Bind to all interfaces&quot;, action=&quot;store_true&quot;, dest=&quot;http_all_interfaces&quot;)
+    parser.add_option(&quot;-p&quot;, &quot;--port&quot;, help=&quot;Bind to port NNNN&quot;, action=&quot;store&quot;, type=&quot;int&quot;, dest=&quot;http_port&quot;)
+    return parser.parse_args(args)
</ins><span class="cx"> 
</span><del>-use lib $FindBin::Bin;
-use webkitperl::httpd;
-use webkitdirs;
</del><ins>+def main(argv, stdout, stderr):
+    options, args = parse_args(argv)
+    host = Host()
</ins><span class="cx"> 
</span><del>-# FIXME: Dynamic HTTP-port configuration in this file is wrong.  The various
-# apache config files in LayoutTests/http/config govern the port numbers.
-# Dynamic configuration as-written will also cause random failures in
-# an IPv6 environment.  See https://bugs.webkit.org/show_bug.cgi?id=37104.
-# Argument handling
-my $httpdPort = 8000;
-my $allInterfaces = 0;
-my $showHelp;
</del><ins>+    log_file = tempfile.NamedTemporaryFile()
+    options.http_access_log = log_file.name
+    options.http_error_log = log_file.name
+    options.platform = None
</ins><span class="cx"> 
</span><del>-my $result = GetOptions(
-    'all-interfaces|a' =&gt; \$allInterfaces,
-    'help|h' =&gt; \$showHelp,
-    'port=i' =&gt; \$httpdPort,
-);
</del><ins>+    try:
+        port = host.port_factory.get(options.platform, options)
+    except NotImplementedError, e:
+        print &gt;&gt; stderr, str(e)
+        return EXCEPTIONAL_EXIT_STATUS
</ins><span class="cx"> 
</span><del>-if (!$result || @ARGV || $showHelp) {
-    print &quot;Usage: &quot; . basename($0) . &quot; [options]\n&quot;;
-    print &quot;  -a|--all-interfaces  Bind to all interfaces\n&quot;;
-    print &quot;  -h|--help            Show this help message\n&quot;;
-    print &quot;  -p|--port NNNN       Bind to port NNNN\n&quot;;
-    exit 1;
-}
</del><ins>+    # FIXME(154294): somehow retrieve the actual ports and interfaces bound by the httpd server
+    http_port = options.http_port if options.http_port is not None else &quot;8000&quot;
+    if options.http_all_interfaces is not None:
+        print &quot;Starting httpd on port %s (all interfaces)&quot; % http_port
+    else:
+        print &quot;Starting httpd on &lt;http://127.0.0.1:%s&gt;&quot; % http_port
</ins><span class="cx"> 
</span><del>-setConfiguration();
-my $productDir = productDir();
-chdirWebKit();
-my $testDirectory = File::Spec-&gt;catfile(getcwd(), &quot;LayoutTests&quot;);
-my $listen = &quot;127.0.0.1:$httpdPort&quot;;
-$listen = &quot;$httpdPort&quot; if ($allInterfaces);
</del><ins>+    port.start_http_server()
</ins><span class="cx"> 
</span><del>-if ($allInterfaces) {
-    print &quot;Starting httpd on port $httpdPort (all interfaces)...\n&quot;;
-} else {
-    print &quot;Starting httpd on &lt;http://$listen/&gt;...\n&quot;;
-}
-setShouldWaitForUserInterrupt();
-print &quot;Press Ctrl+C to stop it.\n\n&quot;;
</del><ins>+    try:
+        tail = subprocess.Popen(['tail', '-F', log_file.name], stdout=subprocess.PIPE)
+        while True:
+            sys.stdout.write(tail.stdout.readline())
+    except KeyboardInterrupt:
+        port.stop_http_server()
</ins><span class="cx"> 
</span><del>-my @args = (
-    &quot;-C&quot;, &quot;Listen $listen&quot;,
-    # Run in single-process mode, do not detach from the controlling terminal.
-    &quot;-X&quot;,
-    # Disable Keep-Alive support. Makes testing in multiple browsers easier (no need to wait
-    # for another browser's connection to expire).
-    &quot;-c&quot;, &quot;KeepAlive off&quot;
-);
-
-if (!isAnyWindows()) {
-    push(@args, &quot;-c&quot;, &quot;CustomLog |/usr/bin/tee common&quot;);
-    push(@args, &quot;-c&quot;, &quot;ErrorLog |/usr/bin/tee&quot;);
-}
-
-my @defaultArgs = getDefaultConfigForTestDirectory($testDirectory);
-@args = (@defaultArgs, @args);
-openHTTPD(@args);
</del><ins>+if __name__ == '__main__':
+    sys.exit(main(sys.argv[1:], sys.stdout, sys.stderr))
</ins></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testsserversapache_http_serverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py (196777 => 196778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py        2016-02-18 21:58:15 UTC (rev 196777)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py        2016-02-18 22:31:49 UTC (rev 196778)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class LayoutTestApacheHttpd(http_server_base.HttpServerBase):
</span><del>-    def __init__(self, port_obj, output_dir, additional_dirs=None):
</del><ins>+    def __init__(self, port_obj, output_dir, additional_dirs=None, port=None):
</ins><span class="cx">         &quot;&quot;&quot;Args:
</span><span class="cx">           port_obj: handle to the platform-specific routines
</span><span class="cx">           output_dir: the absolute path to the layout test result directory
</span><span class="lines">@@ -51,10 +51,15 @@
</span><span class="cx">         http_server_base.HttpServerBase.__init__(self, port_obj)
</span><span class="cx">         # We use the name &quot;httpd&quot; instead of &quot;apache&quot; to make our paths (e.g. the pid file: /tmp/WebKit/httpd.pid)
</span><span class="cx">         # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63956
</span><ins>+
</ins><span class="cx">         self._name = 'httpd'
</span><del>-        self._mappings = [{'port': 8000},
-                          {'port': 8080},
-                          {'port': 8443, 'sslcert': True}]
</del><ins>+        self._port = port
+        if self._port is not None:
+            self._mappings = [{'port': self._port}]
+        else:
+            self._mappings = [{'port': 8000},
+                              {'port': 8080},
+                              {'port': 8443, 'sslcert': True}]
</ins><span class="cx">         self._output_dir = output_dir
</span><span class="cx">         self._filesystem.maybe_make_directory(output_dir)
</span><span class="cx"> 
</span><span class="lines">@@ -80,6 +85,12 @@
</span><span class="cx">         error_log = self._filesystem.join(output_dir, &quot;error_log.txt&quot;)
</span><span class="cx">         document_root = self._filesystem.join(test_dir, &quot;http&quot;, &quot;tests&quot;)
</span><span class="cx"> 
</span><ins>+        if port_obj.get_option('http_access_log'):
+            access_log = port_obj.get_option('http_access_log')
+
+        if port_obj.get_option('http_error_log'):
+            error_log = port_obj.get_option('http_error_log')
+
</ins><span class="cx">         # FIXME: We shouldn't be calling a protected method of _port_obj!
</span><span class="cx">         executable = self._port_obj._path_to_apache()
</span><span class="cx"> 
</span><span class="lines">@@ -110,10 +121,12 @@
</span><span class="cx">         except:
</span><span class="cx">             enable_ipv6 = False
</span><span class="cx"> 
</span><ins>+        bind_address = '' if self._port_obj.get_option(&quot;http_all_interfaces&quot;) else '127.0.0.1:'
+
</ins><span class="cx">         for mapping in self._mappings:
</span><span class="cx">             port = mapping['port']
</span><span class="cx"> 
</span><del>-            start_cmd += ['-C', &quot;\'Listen 127.0.0.1:%d\'&quot; % port]
</del><ins>+            start_cmd += ['-C', &quot;\'Listen %s%d\'&quot; % (bind_address, port)]
</ins><span class="cx"> 
</span><span class="cx">             # We listen to both IPv4 and IPv6 loop-back addresses, but ignore
</span><span class="cx">             # requests to 8000 from random users on network.
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpylayout_testsservershttp_serverpy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/layout_tests/servers/http_server.py (196777 => 196778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/layout_tests/servers/http_server.py        2016-02-18 21:58:15 UTC (rev 196777)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/servers/http_server.py        2016-02-18 22:31:49 UTC (rev 196778)
</span><span class="lines">@@ -94,6 +94,12 @@
</span><span class="cx">         log_file_name = &quot;error.log-&quot; + time_str + &quot;.txt&quot;
</span><span class="cx">         error_log = os.path.join(self._output_dir, log_file_name)
</span><span class="cx"> 
</span><ins>+        if self._port_obj.get_option('http_access_log'):
+            access_log = self._port_obj.get_option('http_access_log')
+
+        if self._port_obj.get_option('http_error_log'):
+            error_log = self._port_obj.get_option('http_error_log')
+
</ins><span class="cx">         # Write out the config
</span><span class="cx">         base_conf = self._filesystem.read_text_file(base_conf_file)
</span><span class="cx"> 
</span><span class="lines">@@ -149,16 +155,18 @@
</span><span class="cx">                              'sslcert': self._pem_file}]
</span><span class="cx">         else:
</span><span class="cx">             mappings = self.VIRTUALCONFIG
</span><ins>+
+        bind_address = '' if self._port_obj.get_option('http_all_addresses') else '127.0.0.1'
</ins><span class="cx">         for mapping in mappings:
</span><span class="cx">             ssl_setup = ''
</span><span class="cx">             if 'sslcert' in mapping:
</span><span class="cx">                 ssl_setup = ('  ssl.engine = &quot;enable&quot;\n'
</span><span class="cx">                              '  ssl.pemfile = &quot;%s&quot;\n' % mapping['sslcert'])
</span><span class="cx"> 
</span><del>-            f.write(('$SERVER[&quot;socket&quot;] == &quot;127.0.0.1:%d&quot; {\n'
</del><ins>+            f.write(('$SERVER[&quot;socket&quot;] == &quot;%s:%d&quot; {\n'
</ins><span class="cx">                      '  server.document-root = &quot;%s&quot;\n' +
</span><span class="cx">                      ssl_setup +
</span><del>-                     '}\n\n') % (mapping['port'], mapping['docroot']))
</del><ins>+                     '}\n\n') % (bind_address, mapping['port'], mapping['docroot']))
</ins><span class="cx">         f.close()
</span><span class="cx"> 
</span><span class="cx">         executable = self._port_obj._path_to_lighttpd()
</span></span></pre></div>
<a id="trunkToolsScriptswebkitpyportbasepy"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/webkitpy/port/base.py (196777 => 196778)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/webkitpy/port/base.py        2016-02-18 21:58:15 UTC (rev 196777)
+++ trunk/Tools/Scripts/webkitpy/port/base.py        2016-02-18 22:31:49 UTC (rev 196778)
</span><span class="lines">@@ -905,11 +905,11 @@
</span><span class="cx"> 
</span><span class="cx">         Ports can stub this out if they don't need a web server to be running.&quot;&quot;&quot;
</span><span class="cx">         assert not self._http_server, 'Already running an http server.'
</span><del>-
</del><ins>+        http_port = self.get_option('http_port')
</ins><span class="cx">         if self._uses_apache():
</span><del>-            server = apache_http_server.LayoutTestApacheHttpd(self, self.results_directory(), additional_dirs=additional_dirs)
</del><ins>+            server = apache_http_server.LayoutTestApacheHttpd(self, self.results_directory(), additional_dirs=additional_dirs, port=http_port)
</ins><span class="cx">         else:
</span><del>-            server = http_server.Lighttpd(self, self.results_directory(), additional_dirs=additional_dirs)
</del><ins>+            server = http_server.Lighttpd(self, self.results_directory(), additional_dirs=additional_dirs, port=http_port)
</ins><span class="cx"> 
</span><span class="cx">         server.start()
</span><span class="cx">         self._http_server = server
</span></span></pre>
</div>
</div>

</body>
</html>