Add support for appending list values in mixins.

Introduce a new $mixin_append key to mixins. Values in the $mixin_append
dictionary must be lists, and will be appended to any existing items in
the corresponding key of the test specification.

Bug: 879806
Change-Id: Ibd51c679df1944bcc9f34a4acba47ee39a5f871d
Reviewed-on: https://chromium-review.googlesource.com/c/1306352
Commit-Queue: Wez <[email protected]>
Reviewed-by: Stephen Martinis <[email protected]>
Cr-Commit-Position: refs/heads/master@{#603705}
diff --git a/testing/buildbot/generate_buildbot_json.py b/testing/buildbot/generate_buildbot_json.py
index 1d49acd..548ee01 100755
--- a/testing/buildbot/generate_buildbot_json.py
+++ b/testing/buildbot/generate_buildbot_json.py
@@ -756,9 +756,6 @@
     is then applied to every dimension set in the test.
 
     """
-    # TODO(martiniss): Maybe make lists extend, possibly on a case by case
-    # basis. Motivation is 'args', where you want a common base, and then
-    # different mixins adding different sets of args.
     new_test = copy.deepcopy(test)
     mixin = copy.deepcopy(mixin)
 
@@ -777,6 +774,23 @@
       new_test['swarming'].update(swarming_mixin)
       del mixin['swarming']
 
+    if '$mixin_append' in mixin:
+      # Values specified under $mixin_append should be appended to existing
+      # lists, rather than replacing them.
+      mixin_append = mixin['$mixin_append']
+      for key in mixin_append:
+        new_test.setdefault(key, [])
+        if not isinstance(mixin_append[key], list):
+          raise BBGenErr(
+              'Key "' + key + '" in $mixin_append must be a list.')
+        if not isinstance(new_test[key], list):
+          raise BBGenErr(
+              'Cannot apply $mixin_append to non-list "' + key + '".')
+        new_test[key].extend(mixin_append[key])
+      if 'args' in mixin_append:
+        new_test['args'] = self.maybe_fixup_args_array(new_test['args'])
+      del mixin['$mixin_append']
+
     new_test.update(mixin)
 
     return new_test