Bug 1318200 - Filter Stylo platforms when Servo isn't available; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Thu, 17 Nov 2016 17:10:01 -0800
changeset 441390 98a31bdc375aa153c3d78a062fa0a54d56666c9b
parent 441327 4e499341a65666cf20149c0dd0d95f1766f6a59f
child 537545 3c83109706e36fde10f1e7d79a5acc4a5d7621dd
push id36413
push userbmo:gps@mozilla.com
push dateFri, 18 Nov 2016 20:34:48 +0000
reviewersdustin
bugs1318200
milestone53.0a1
Bug 1318200 - Filter Stylo platforms when Servo isn't available; r?dustin Stylo automation doesn't work unless Servo is present in the source directory. This commit introduces a "check_servo" filter that prunes tasks requiring Servo. Currently, this is implemented as a test against platforms that are unique to Servo. The use of relative path checking to find the topsrcdir is a bit unfortunate. But we use this pattern elsewhere in this code. MozReview-Commit-ID: IRtd53tudJW
taskcluster/taskgraph/decision.py
taskcluster/taskgraph/filter_tasks.py
taskcluster/taskgraph/test/test_filters.py
--- a/taskcluster/taskgraph/decision.py
+++ b/taskcluster/taskgraph/decision.py
@@ -121,16 +121,17 @@ def get_decision_parameters(options):
         'level',
         'triggered_by',
         'target_tasks_method',
     ] if n in options}
 
     # Define default filter list, as most configurations shouldn't need
     # custom filters.
     parameters['filters'] = [
+        'check_servo',
         'target_tasks_method',
     ]
 
     # owner must be an email, but sometimes (e.g., for ffxbld) it is not, in which
     # case, fake it
     if '@' not in parameters['owner']:
         parameters['owner'] += '@noreply.mozilla.org'
 
--- a/taskcluster/taskgraph/filter_tasks.py
+++ b/taskcluster/taskgraph/filter_tasks.py
@@ -1,18 +1,24 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, unicode_literals
 
+import logging
+import os
+
 from . import (
     target_tasks,
 )
 
+logger = logging.getLogger(__name__)
+
+GECKO = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
 
 filter_task_functions = {}
 
 
 def filter_task(name):
     """Generator to declare a task filter function."""
     def wrap(func):
         filter_task_functions[name] = func
@@ -25,8 +31,29 @@ def filter_target_tasks(graph, parameter
     """Proxy filter to use legacy target tasks code.
 
     This should go away once target_tasks are converted to filters.
     """
 
     attr = parameters.get('target_tasks_method', 'all_tasks')
     fn = target_tasks.get_method(attr)
     return fn(graph, parameters)
+
+
+@filter_task('check_servo')
+def filter_servo(graph, parameters):
+    """Filters out tasks requiring Servo if Servo isn't present."""
+    if os.path.exists(os.path.join(GECKO, 'servo')):
+        return graph.tasks.keys()
+
+    logger.info('servo/ directory not present; removing tasks requiring it')
+
+    SERVO_PLATFORMS = {
+        'linux64-stylo',
+    }
+
+    def fltr(task):
+        if task.attributes.get('build_platform') in SERVO_PLATFORMS:
+            return False
+
+        return True
+
+    return [l for l, t in graph.tasks.iteritems() if fltr(t)]
new file mode 100644
--- /dev/null
+++ b/taskcluster/taskgraph/test/test_filters.py
@@ -0,0 +1,53 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, unicode_literals
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from mozunit import main
+
+from .. import filter_tasks
+from ..graph import (
+    Graph,
+)
+from ..taskgraph import (
+    TaskGraph,
+)
+from .util import (
+    TestTask,
+)
+
+
+class TestServoFilter(unittest.TestCase):
+    def setUp(self):
+        self._tmpdir = tempfile.mkdtemp()
+        filter_tasks.GECKO = self._tmpdir
+
+    def tearDown(self):
+        shutil.rmtree(self._tmpdir)
+
+    def test_basic(self):
+        graph = TaskGraph(tasks={
+            'a': TestTask(kind='build', label='a',
+                          attributes={'build_platform': 'linux64'}),
+            'b': TestTask(kind='build', label='b',
+                          attributes={'build_platform': 'linux64-stylo'}),
+            'c': TestTask(kind='desktop-test', label='c', attributes={}),
+        }, graph=Graph(nodes={'a', 'b', 'c'}, edges=set()))
+
+        # Missing servo/ directory should prune tasks requiring Servo.
+        self.assertEqual(set(filter_tasks.filter_servo(graph, {})), {'a', 'c'})
+
+        # Servo tasks should be retained if servo/ present.
+        os.mkdir(os.path.join(self._tmpdir, 'servo'))
+        self.assertEqual(set(filter_tasks.filter_servo(graph, {})),
+                         {'a', 'b', 'c'})
+
+
+if __name__ == '__main__':
+    main()