Bug 1242083 - Add --setenv to the arguments accepted by mozharness to pass to the harness command, add a way to specify flavors an argument applies to. r=armenzg draft
authorChris Manchester <cmanchester@mozilla.com>
Thu, 04 Feb 2016 10:51:09 -0800
changeset 328945 3b77b7eb9cfe9cfe3d0b454a3e368b19661436b1
parent 328887 f53533d9eb771f3251921949ab2c888def70f41f
child 513879 f050438b85954cb10ff9c7e4b87881c532fbe180
push id10438
push usercmanchester@mozilla.com
push dateThu, 04 Feb 2016 18:51:24 +0000
reviewersarmenzg
bugs1242083
milestone47.0a1
Bug 1242083 - Add --setenv to the arguments accepted by mozharness to pass to the harness command, add a way to specify flavors an argument applies to. r=armenzg
testing/mozharness/mozharness/mozilla/testing/try_tools.py
--- a/testing/mozharness/mozharness/mozilla/testing/try_tools.py
+++ b/testing/mozharness/mozharness/mozilla/testing/try_tools.py
@@ -41,21 +41,29 @@ test_flavors = {
 
 class TryToolsMixin(TransferMixin):
     """Utility functions for an interface between try syntax and out test harnesses.
     Requires log and script mixins."""
 
     harness_extra_args = None
     try_test_paths = {}
     known_try_arguments = {
-        '--tag': {
+        '--tag': ({
             'action': 'append',
             'dest': 'tags',
             'default': None,
-        },
+        }, ('marionette', 'xpcshell', 'mochitest', 'browser-chrome',
+            'devtools-chrome', 'chrome', 'web-plaftform-tests')),
+        '--setenv': ({
+            'action': 'append',
+            'dest': 'setenv',
+            'default': [],
+            'metavar': 'NAME=VALUE',
+        }, ('mochitest', 'browser-chrome', 'devtools-chrome', 'chrome',
+            'crashtest', 'reftest')),
     }
 
     def _extract_try_message(self):
         msg = None
         if "try_message" in self.config and self.config["try_message"]:
             msg = self.config["try_message"]
         else:
             if self.buildbot_config['sourcestamp']['changes']:
@@ -119,63 +127,67 @@ class TryToolsMixin(TransferMixin):
                          ' and forward them to the underlying test harness command.'))
 
         label_dict = {}
         def label_from_val(val):
             if val in label_dict:
                 return label_dict[val]
             return '--%s' % val.replace('_', '-')
 
-        for label, opts in self.known_try_arguments.iteritems():
+        for label, (opts, _) in self.known_try_arguments.iteritems():
             if 'action' in opts and opts['action'] not in ('append', 'store',
                                                            'store_true', 'store_false'):
                 self.fatal('Try syntax does not support passing custom or store_const '
                            'arguments to the harness process.')
             if 'dest' in opts:
                 label_dict[opts['dest']] = label
 
             parser.add_argument(label, **opts)
 
         parser.add_argument('--try-test-paths', nargs='*')
         (args, _) = parser.parse_known_args(all_try_args)
         self.try_test_paths = self._group_test_paths(args.try_test_paths)
         del args.try_test_paths
 
-        out_args = []
+        out_args = defaultdict(list)
         # This is a pretty hacky way to echo arguments down to the harness.
         # Hopefully this can be improved once we have a configuration system
         # in tree for harnesses that relies less on a command line.
-        for (arg, value) in vars(args).iteritems():
+        for arg, value in vars(args).iteritems():
             if value:
                 label = label_from_val(arg)
-                if isinstance(value, bool):
-                    # A store_true or store_false argument.
-                    out_args.append(label)
-                elif isinstance(value, list):
-                    out_args.extend(['%s=%s' % (label, el) for el in value])
-                else:
-                    out_args.append('%s=%s' % (label, value))
+                _, flavors = self.known_try_arguments[label]
 
-        self.harness_extra_args = out_args
+                for f in flavors:
+                    if isinstance(value, bool):
+                        # A store_true or store_false argument.
+                        out_args[f].append(label)
+                    elif isinstance(value, list):
+                        out_args[f].extend(['%s=%s' % (label, el) for el in value])
+                    else:
+                        out_args[f].append('%s=%s' % (label, value))
+
+        self.harness_extra_args = dict(out_args)
 
     def _group_test_paths(self, args):
         rv = defaultdict(list)
 
         if args is None:
             return rv
 
         for item in args:
             suite, path = item.split(":", 1)
             rv[suite].append(path)
         return rv
 
     def try_args(self, flavor):
         """Get arguments, test_list derived from try syntax to apply to a command"""
-        # TODO: Detect and reject incompatible arguments
-        args = self.harness_extra_args[:] if self.harness_extra_args else []
+        args = []
+        if self.harness_extra_args:
+            args = self.harness_extra_args.get(flavor, [])[:]
 
         if self.try_test_paths.get(flavor):
             self.info('TinderboxPrint: Tests will be run from the following '
                       'files: %s.' % ','.join(self.try_test_paths[flavor]))
             args.extend(['--this-chunk=1', '--total-chunks=1'])
 
             path_func = test_flavors[flavor].get("path", lambda x:x)
             tests = [path_func(item) for item in self.try_test_paths[flavor]]