Bug 1413928 - [tryselect] Add a new 'path' template r=maja_zf
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 15 Jan 2018 16:05:37 -0500
changeset 454003 f1a0ec3a91778f800154b874e7f900f00825df20
parent 454002 0c677fb018bee767363215edb0b6d0cb4ffb8111
child 454004 959c0a8a3459fb37a301569cecb9dab96a9f5645
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1413928
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1413928 - [tryselect] Add a new 'path' template r=maja_zf This sets the MOZHARNESS_TEST_PATHS environment variables for all tasks. When specifying paths, this will cause many test tasks to only run the tests under that directory as opposed to the normal default. MozReview-Commit-ID: IHRXXi5mB4G
tools/tryselect/templates.py
tools/tryselect/test/test_templates.py
--- a/tools/tryselect/templates.py
+++ b/tools/tryselect/templates.py
@@ -5,22 +5,25 @@
 """
 Templates provide a way of modifying the task definition of selected
 tasks. They live under taskcluster/taskgraph/templates.
 """
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
+import sys
 from abc import ABCMeta, abstractmethod
 from argparse import Action
 
+import mozpack.path as mozpath
 from mozbuild.base import BuildEnvironmentNotFoundException, MozbuildObject
 
 here = os.path.abspath(os.path.dirname(__file__))
+build = MozbuildObject.from_environment(cwd=here)
 
 
 class Template(object):
     __metaclass__ = ABCMeta
 
     @abstractmethod
     def add_arguments(self, parser):
         pass
@@ -43,27 +46,50 @@ class Artifact(Template):
         if artifact:
             return {
                 'artifact': {'enabled': '1'}
             }
 
         if no_artifact:
             return
 
-        build = MozbuildObject.from_environment(cwd=here)
         try:
             if build.substs.get("MOZ_ARTIFACT_BUILDS"):
                 print("Artifact builds enabled, pass --no-artifact to disable")
                 return {
                     'artifact': {'enabled': '1'}
                 }
         except BuildEnvironmentNotFoundException:
             pass
 
 
+class Path(Template):
+
+    def add_arguments(self, parser):
+        parser.add_argument('paths', nargs='*',
+                            help='Run tasks containing tests under the specified path(s).')
+
+    def context(self, paths, **kwargs):
+        if not paths:
+            return
+
+        for p in paths:
+            if not os.path.exists(p):
+                print("error: '{}' is not a valid path.".format(p), file=sys.stderr)
+                sys.exit(1)
+
+        paths = [mozpath.relpath(mozpath.join(os.getcwd(), p), build.topsrcdir) for p in paths]
+        return {
+            'env': {
+                # can't use os.pathsep as machine splitting could be a different platform
+                'MOZHARNESS_TEST_PATHS': ':'.join(paths),
+            }
+        }
+
+
 class Environment(Template):
 
     def add_arguments(self, parser):
         parser.add_argument('--env', action='append', default=None,
                             help='Set an environment variable, of the form FOO=BAR. '
                                  'Can be passed in multiple times.')
 
     def context(self, env, **kwargs):
@@ -102,11 +128,12 @@ class Rebuild(Template):
 
         return {
             'rebuild': rebuild,
         }
 
 
 all_templates = {
     'artifact': Artifact,
+    'path': Path,
     'env': Environment,
     'rebuild': Rebuild,
 }
--- a/tools/tryselect/test/test_templates.py
+++ b/tools/tryselect/test/test_templates.py
@@ -18,16 +18,23 @@ TEMPLATE_TESTS = {
     'artifact': [
         (['--no-artifact'], None),
         (['--artifact'], {'artifact': {'enabled': '1'}}),
     ],
     'env': [
         ([], None),
         (['--env', 'foo=bar', '--env', 'num=10'], {'env': {'foo': 'bar', 'num': '10'}}),
     ],
+    'path': [
+        ([], None),
+        (['dom/indexedDB'], {'env': {'MOZHARNESS_TEST_PATHS': 'dom/indexedDB'}}),
+        (['dom/indexedDB', 'testing'],
+         {'env': {'MOZHARNESS_TEST_PATHS': 'dom/indexedDB:testing'}}),
+        (['invalid/path'], SystemExit),
+    ],
     'rebuild': [
         ([], None),
         (['--rebuild', '10'], {'rebuild': 10}),
         (['--rebuild', '1'], SystemExit),
         (['--rebuild', '21'], SystemExit),
     ],
 }