Bug 1308513 - Support running wpt mach command without an objdir, r=gps draft
authorJames Graham <james@hoppipolla.co.uk>
Fri, 07 Oct 2016 15:19:05 +0100
changeset 423523 8ddc482bbb844d7c0783ce6894d76da315be0e99
parent 422189 70758fd844ecca6f084414a52406dd58795d0715
child 533473 42e05587a783d28f043c76bb37d742453b48d3f1
push id31928
push userbmo:james@hoppipolla.co.uk
push dateTue, 11 Oct 2016 09:45:07 +0000
reviewersgps
bugs1308513
milestone52.0a1
Bug 1308513 - Support running wpt mach command without an objdir, r=gps If we don't have an objdir require that binary paths are explicitly passed in as command line arguments. This should allow us to use the mach commands on infrastructure including for one-click loaners. MozReview-Commit-ID: 7r1S5WmvFnn
testing/web-platform/mach_commands.py
--- a/testing/web-platform/mach_commands.py
+++ b/testing/web-platform/mach_commands.py
@@ -3,18 +3,20 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Integrates the web-platform-tests test runner with mach.
 
 from __future__ import absolute_import, unicode_literals, print_function
 
 import os
 import sys
+import textwrap
 
 from mozbuild.base import (
+    BuildEnvironmentNotFoundException,
     MachCommandBase,
     MachCommandConditions as conditions,
     MozbuildObject,
 )
 
 from mach.decorators import (
     CommandProvider,
     Command,
@@ -27,42 +29,56 @@ class InvalidTestPathError(Exception):
 
 class WebPlatformTestsRunner(MozbuildObject):
     """Run web platform tests."""
 
     def setup_kwargs(self, kwargs):
         from wptrunner import wptcommandline
 
         build_path = os.path.join(self.topobjdir, 'build')
-        if build_path not in sys.path:
-            sys.path.append(build_path)
+        if os.path.exists(build_path):
+            have_objdir_build = True
+            if build_path not in sys.path:
+                sys.path.append(build_path)
+        else:
+            have_objdir_build = False
+
+        if have_objdir_build:
+            if kwargs["binary"] is None:
+                kwargs["binary"] = self.get_binary_path('app')
+
+            if kwargs["certutil_binary"] is None:
+                kwargs["certutil_binary"] = self.get_binary_path('certutil')
+        else:
+            if kwargs["binary"] is None or kwargs["certutil_binary"] is None:
+                print(textwrap.fill("No build found. Either run |mach build|, "
+                                    "or provide the path to a binary and "
+                                    "certutil explicitly using --binary and "
+                                    "--certutil-binary"))
+                sys.exit(1)
+
+        src_base = os.path.join(self.topsrcdir, 'testing', 'web-platform')
 
         if kwargs["config"] is None:
-            kwargs["config"] = os.path.join(self.topsrcdir, 'testing', 'web-platform', 'wptrunner.ini')
-
-        if kwargs["binary"] is None:
-            kwargs["binary"] = self.get_binary_path('app')
+            kwargs["config"] = os.path.join(src_base, 'wptrunner.ini')
 
         if kwargs["prefs_root"] is None:
-            kwargs["prefs_root"] = os.path.join(self.topobjdir, '_tests', 'web-platform', "prefs")
-
-        if kwargs["certutil_binary"] is None:
-            kwargs["certutil_binary"] = self.get_binary_path('certutil')
+            kwargs["prefs_root"] = os.path.join(self.topsrcdir, 'testing', 'profiles')
 
         here = os.path.split(__file__)[0]
 
         if kwargs["ssl_type"] in (None, "pregenerated"):
             if kwargs["ca_cert_path"] is None:
-                kwargs["ca_cert_path"] = os.path.join(here, "certs", "cacert.pem")
+                kwargs["ca_cert_path"] = os.path.join(src_base, "certs", "cacert.pem")
 
             if kwargs["host_key_path"] is None:
-                kwargs["host_key_path"] = os.path.join(here, "certs", "web-platform.test.key")
+                kwargs["host_key_path"] = os.path.join(src_base, "certs", "web-platform.test.key")
 
             if kwargs["host_cert_path"] is None:
-                kwargs["host_cert_path"] = os.path.join(here, "certs", "web-platform.test.pem")
+                kwargs["host_cert_path"] = os.path.join(src_base, "certs", "web-platform.test.pem")
 
         kwargs["capture_stdio"] = True
 
         kwargs = wptcommandline.check_args(kwargs)
 
     def run_tests(self, **kwargs):
         from wptrunner import wptrunner
 
@@ -288,17 +304,16 @@ def create_parser_manifest_update():
 
 @CommandProvider
 class MachCommands(MachCommandBase):
     def setup(self):
         self._activate_virtualenv()
 
     @Command("web-platform-tests",
              category="testing",
-             conditions=[conditions.is_firefox],
              parser=create_parser_wpt)
     def run_web_platform_tests(self, **params):
         self.setup()
 
         if "test_objects" in params:
             for item in params["test_objects"]:
                 params["include"].append(item["name"])
             del params["test_objects"]
@@ -307,17 +322,16 @@ class MachCommands(MachCommandBase):
 
         if params["list_test_groups"]:
             return wpt_runner.list_test_groups(**params)
         else:
             return wpt_runner.run_tests(**params)
 
     @Command("wpt",
              category="testing",
-             conditions=[conditions.is_firefox],
              parser=create_parser_wpt)
     def run_wpt(self, **params):
         return self.run_web_platform_tests(**params)
 
     @Command("web-platform-tests-update",
              category="testing",
              parser=create_parser_update)
     def update_web_platform_tests(self, **params):