Bug 1273633: support per-branch config in the decision task; r=garndt
authorDustin J. Mitchell <dustin@mozilla.com>
Tue, 17 May 2016 21:27:11 +0000
changeset 322454 3fb747099412c45b769155857ba937467aa608de
parent 322453 ee5bdc58edab47abddbb6ea6fc6474a46316a8b2
child 322455 3159e9934a588b3827573598334c3d6a8d11daa0
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgarndt
bugs1273633
milestone49.0a1
Bug 1273633: support per-branch config in the decision task; r=garndt MozReview-Commit-ID: LXQIaSzPpr4
.taskcluster.yml
taskcluster/taskgraph/decision.py
taskcluster/taskgraph/parameters.py
--- a/.taskcluster.yml
+++ b/.taskcluster.yml
@@ -89,17 +89,16 @@ tasks:
           - /bin/bash
           - -cx
           - >
             mkdir -p /home/worker/artifacts &&
             checkout-gecko workspace &&
             cd workspace/gecko &&
             ln -s /home/worker/artifacts artifacts &&
             ./mach taskgraph decision
-            --target-tasks-method=try_option_syntax
             --pushlog-id='{{pushlog_id}}'
             --project='{{project}}'
             --message='{{comment}}'
             --owner='{{owner}}'
             --level='{{level}}'
             --base-repository='https://hg.mozilla.org/mozilla-central'
             --head-repository='{{{url}}}'
             --head-ref='{{revision}}'
--- a/taskcluster/taskgraph/decision.py
+++ b/taskcluster/taskgraph/decision.py
@@ -8,21 +8,36 @@ from __future__ import absolute_import, 
 
 import os
 import json
 import logging
 import yaml
 
 from .generator import TaskGraphGenerator
 from .create import create_tasks
-from .parameters import get_decision_parameters
+from .parameters import Parameters
 from .target_tasks import get_method
 
 ARTIFACTS_DIR = 'artifacts'
 
+logger = logging.getLogger(__name__)
+
+# For each project, this gives a set of parameters specific to the project.
+# See `taskcluster/docs/parameters.rst` for information on parameters.
+PER_PROJECT_PARAMETERS = {
+    'try': {
+        'target_tasks_method': 'try_option_syntax',
+    },
+
+    # the default parameters are used for projects that do not match above.
+    'default': {
+        'target_tasks_method': 'all_tasks',
+    }
+}
+
 
 def taskgraph_decision(log, options):
     """
     Run the decision task.  This function implements `mach taskgraph decision`,
     and is responsible for
 
      * processing decision task command-line options into parameters
      * running task-graph generation exactly the same way the other `mach
@@ -59,16 +74,48 @@ def taskgraph_decision(log, options):
     write_artifact('task-graph.json',
                    taskgraph_to_json(tgg.optimized_task_graph),
                    log)
 
     # actually create the graph
     create_tasks(tgg.optimized_task_graph)
 
 
+def get_decision_parameters(options):
+    """
+    Load parameters from the command-line options for 'taskgraph decision'.
+    This also applies per-project parameters, based on the given project.
+
+    """
+    parameters = {n: options[n] for n in [
+        'base_repository',
+        'head_repository',
+        'head_rev',
+        'head_ref',
+        'revision_hash',
+        'message',
+        'project',
+        'pushlog_id',
+        'owner',
+        'level',
+        'target_tasks_method',
+    ] if n in options}
+
+    project = parameters['project']
+    try:
+        parameters.update(PER_PROJECT_PARAMETERS[project])
+    except KeyError:
+        logger.warning("using default project parameters; add {} to "
+              "PER_PROJECT_PARAMETERS in {} to customize behavior "
+              "for this project".format(project, __file__))
+        parameters.update(PER_PROJECT_PARAMETERS['default'])
+
+    return Parameters(parameters)
+
+
 def taskgraph_to_json(taskgraph):
     tasks = taskgraph.tasks
 
     def tojson(task):
         return {
             'task': task.task,
             'attributes': task.attributes,
             'dependencies': []
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -29,26 +29,8 @@ def load_parameters_file(options):
         return Parameters()
     with open(filename) as f:
         if filename.endswith('.yml'):
             return Parameters(**yaml.safe_load(f))
         elif filename.endswith('.json'):
             return Parameters(**json.load(f))
         else:
             raise TypeError("Parameters file `{}` is not JSON or YAML".format(filename))
-
-def get_decision_parameters(options):
-    """
-    Load parameters from the command-line options for 'taskgraph decision'.
-    """
-    return Parameters({n: options[n] for n in [
-        'base_repository',
-        'head_repository',
-        'head_rev',
-        'head_ref',
-        'revision_hash',
-        'message',
-        'project',
-        'pushlog_id',
-        'owner',
-        'level',
-        'target_tasks_method',
-    ] if n in options})