Bug 1403342 - only set try-related parameters on the try branch; r=ahal
authorDustin J. Mitchell <dustin@mozilla.com>
Mon, 02 Oct 2017 19:13:22 +0000
changeset 679127 58baa3acd72d011c104f9edef7d07cbb74e25305
parent 679126 60115421ca851d2acd767609a85153fe4ff69d32
child 679128 5c8014361629ca5734aaa42afce360bc48411a39
push id84141
push userbmo:schien@mozilla.com
push dateThu, 12 Oct 2017 11:13:04 +0000
reviewersahal
bugs1403342
milestone58.0a1
Bug 1403342 - only set try-related parameters on the try branch; r=ahal Specifically, this avoids setting optimize_target_tasks to True unconditionally for non-try branches. MozReview-Commit-ID: HSJFLmqbMmZ
taskcluster/taskgraph/decision.py
taskcluster/taskgraph/test/test_decision.py
--- a/taskcluster/taskgraph/decision.py
+++ b/taskcluster/taskgraph/decision.py
@@ -194,47 +194,50 @@ def get_decision_parameters(options):
     parameters.setdefault('release_history', dict())
     if 'nightly' in parameters.get('target_tasks_method', ''):
         parameters['release_history'] = populate_release_history('Firefox', project)
 
     # if try_task_config.json is present, load it
     task_config_file = os.path.join(os.getcwd(), 'try_task_config.json')
 
     # load try settings
-    parameters['try_mode'] = None
-    if os.path.isfile(task_config_file):
-        parameters['try_mode'] = 'try_task_config'
-        with open(task_config_file, 'r') as fh:
-            parameters['try_task_config'] = json.load(fh)
-    else:
-        parameters['try_task_config'] = None
+    if project == 'try':
+        parameters['try_mode'] = None
+        if os.path.isfile(task_config_file):
+            parameters['try_mode'] = 'try_task_config'
+            with open(task_config_file, 'r') as fh:
+                parameters['try_task_config'] = json.load(fh)
+        else:
+            parameters['try_task_config'] = None
 
-    if 'try:' in parameters['message']:
-        parameters['try_mode'] = 'try_option_syntax'
-        args = parse_message(parameters['message'])
-        parameters['try_options'] = args
-    else:
-        parameters['try_options'] = None
+        if 'try:' in parameters['message']:
+            parameters['try_mode'] = 'try_option_syntax'
+            args = parse_message(parameters['message'])
+            parameters['try_options'] = args
+        else:
+            parameters['try_options'] = None
 
-    parameters['optimize_target_tasks'] = {
-        # The user has explicitly requested a set of jobs, so run them all
-        # regardless of optimization.  Their dependencies can be optimized,
-        # though.
-        'try_task_config': False,
+        if parameters['try_mode'] == 'try_option_syntax':
+            # Try option syntax is imprecise, so optimize away tasks even if they
+            # are selected by the syntax.
+            parameters['optimize_target_tasks'] = True
+        elif parameters['try_mode'] == 'try_task_config':
+            # The user has explicitly requested a set of jobs, so run them all
+            # regardless of optimization.  Their dependencies can be optimized,
+            # though.
+            parameters['optimize_target_tasks'] = False
+        else:
+            # For a try push with no task selection, apply the default optimization
+            # process to all of the tasks.
+            parameters['optimize_target_tasks'] = True
 
-        # Always perform optimization.  This makes it difficult to use try
-        # pushes to run a task that would otherwise be optimized, but is a
-        # compromise to avoid essentially disabling optimization in try.
-        # to run tasks that would otherwise be optimized, ues try_task_config.
-        'try_option_syntax': True,
-
-        # since no try jobs have been specified, the standard target task will
-        # be applied, and tasks should be optimized out of that.
-        None: True,
-    }[parameters['try_mode']]
+    else:
+        parameters['try_mode'] = None
+        parameters['try_task_config'] = None
+        parameters['try_options'] = None
 
     return Parameters(**parameters)
 
 
 def write_artifact(filename, data):
     logger.info('writing artifact file `{}`'.format(filename))
     if not os.path.isdir(ARTIFACTS_DIR):
         os.mkdir(ARTIFACTS_DIR)
--- a/taskcluster/taskgraph/test/test_decision.py
+++ b/taskcluster/taskgraph/test/test_decision.py
@@ -71,25 +71,27 @@ class TestGetDecisionParameters(unittest
 
     def test_no_email_owner(self):
         self.options['owner'] = 'ffxbld'
         params = decision.get_decision_parameters(self.options)
         self.assertEqual(params['owner'], 'ffxbld@noreply.mozilla.org')
 
     def test_try_options(self):
         self.options['message'] = 'try: -b do -t all'
+        self.options['project'] = 'try'
         params = decision.get_decision_parameters(self.options)
         self.assertEqual(params['try_mode'], 'try_option_syntax')
         self.assertEqual(params['try_options']['build_types'], 'do')
         self.assertEqual(params['try_options']['unittests'], 'all')
         self.assertEqual(params['try_task_config'], None)
 
     def test_try_task_config(self):
         ttc = {'tasks': ['a', 'b'], 'templates': {}}
         ttc_file = os.path.join(os.getcwd(), 'try_task_config.json')
+        self.options['project'] = 'try'
         with MockedOpen({ttc_file: json.dumps(ttc)}):
             params = decision.get_decision_parameters(self.options)
             self.assertEqual(params['try_mode'], 'try_task_config')
             self.assertEqual(params['try_options'], None)
             self.assertEqual(params['try_task_config'], ttc)
 
 
 if __name__ == '__main__':