Bug 1275943 - Schedule tasks with a 'when' clause regardless of try syntax, r?dustin draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 10 Nov 2016 16:57:42 -0500
changeset 437738 f3debdbbc661dc69bf916d1a7ec0fc8b1b8a97e9
parent 437246 d38d06f85ef59c5dbb5d4a1a8d895957a78714de
child 536726 e2e0109f12b4bd60de395d14738ea67f6eb4255c
push id35512
push userahalberstadt@mozilla.com
push dateFri, 11 Nov 2016 16:03:12 +0000
reviewersdustin
bugs1275943
milestone52.0a1
Bug 1275943 - Schedule tasks with a 'when' clause regardless of try syntax, r?dustin One annoyance when working with lint based tasks, is that there is no way to get them running on try unless you also specify a "dummy" job in the try syntax. This is wasteful or requires an extra step to cancel it. Instead, I propose that any task that has "when" clause, should be considered no matter what the try syntax is, even if no try syntax exists. This way, these kinds of jobs can be tested by simply pushing directly to try (without a try syntax), and they will automatically run (assuming their "when" clause turns out to be true). I'm assuming that this makes sense to do for all tasks that have a "when" clause. Please let me know if there are any tasks that break this assumption. MozReview-Commit-ID: EhaTadctIwv
taskcluster/taskgraph/target_tasks.py
taskcluster/taskgraph/test/test_target_tasks.py
taskcluster/taskgraph/try_option_syntax.py
--- a/taskcluster/taskgraph/target_tasks.py
+++ b/taskcluster/taskgraph/target_tasks.py
@@ -35,17 +35,17 @@ def get_method(method):
 
 
 @_target_task('try_option_syntax')
 def target_tasks_try_option_syntax(full_task_graph, parameters):
     """Generate a list of target tasks based on try syntax in
     parameters['message'] and, for context, the full task graph."""
     options = try_option_syntax.TryOptionSyntax(parameters['message'], full_task_graph)
     target_tasks_labels = [t.label for t in full_task_graph.tasks.itervalues()
-                           if options.task_matches(t.attributes)]
+                           if options.task_matches(t)]
 
     # If the developer wants test jobs to be rebuilt N times we add that value here
     if int(options.trigger_tests) > 1:
         for l in target_tasks_labels:
             task = full_task_graph[l]
             if 'unittest_suite' in task.attributes:
                 task.attributes['task_duplicates'] = options.trigger_tests
 
--- a/taskcluster/taskgraph/test/test_target_tasks.py
+++ b/taskcluster/taskgraph/test/test_target_tasks.py
@@ -15,18 +15,18 @@ from mozunit import main
 
 
 class FakeTryOptionSyntax(object):
 
     def __init__(self, message, task_graph):
         self.trigger_tests = 0
         self.notifications = None
 
-    def task_matches(self, attributes):
-        return 'at-at' in attributes
+    def task_matches(self, task):
+        return 'at-at' in task.attributes
 
 
 class TestTargetTasks(unittest.TestCase):
 
     def default_matches(self, run_on_projects, project):
         method = target_tasks.get_method('default')
         graph = TaskGraph(tasks={
             'a': TestTask(kind='build', label='a',
--- a/taskcluster/taskgraph/try_option_syntax.py
+++ b/taskcluster/taskgraph/try_option_syntax.py
@@ -488,18 +488,18 @@ class TryOptionSyntax(object):
             if char == ' ' and in_brackets:
                 result += '\ '
                 continue
 
             result += char
 
         return result
 
-    def task_matches(self, attributes):
-        attr = attributes.get
+    def task_matches(self, task):
+        attr = task.attributes.get
 
         def check_run_on_projects():
             return set(['try', 'all']) & set(attr('run_on_projects', []))
 
         def match_test(try_spec, attr_name):
             if attr('build_type') not in self.build_types:
                 return False
             if self.platforms is not None:
@@ -517,16 +517,21 @@ class TryOptionSyntax(object):
             else:
                 return False
             if 'platforms' in test and attr('test_platform') not in test['platforms']:
                 return False
             if 'only_chunks' in test and attr('test_chunk') not in test['only_chunks']:
                 return False
             return True
 
+        # Tasks with a 'when' clause should be added to the target set regardless
+        # of try syntax, but they can still be optimized away later.
+        if getattr(task, 'when', None):
+            return True
+
         if attr('kind') in ('desktop-test', 'android-test'):
             return match_test(self.unittests, 'unittest_try_name')
         elif attr('kind') in JOB_KINDS:
             if self.jobs is None:
                 return True
             if attr('build_platform') in self.jobs:
                 return True
         elif attr('kind') in BUILD_KINDS: