Support swarming named caches in $mixin_append in testing/buildbot

The CL enables adding additional named caches in mixins, instead of
overriding the ones defined in tests. This is in preparation to support
caching iOS simulator runtimes, which will include named caches added at
both variant and waterfall level.

Also changed Xcode mixin to use this new functionality.

Bug: 1191260
Change-Id: I1a4906fabab075004b6e5889dd6dba8dfd0e583b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2883195
Commit-Queue: Zhaoyang Li <[email protected]>
Reviewed-by: Garrett Beaty <[email protected]>
Cr-Commit-Position: refs/heads/master@{#881110}
diff --git a/testing/buildbot/generate_buildbot_json.py b/testing/buildbot/generate_buildbot_json.py
index 3b4ddafb..1db29d1 100755
--- a/testing/buildbot/generate_buildbot_json.py
+++ b/testing/buildbot/generate_buildbot_json.py
@@ -1333,6 +1333,18 @@
       # Values specified under $mixin_append should be appended to existing
       # lists, rather than replacing them.
       mixin_append = mixin['$mixin_append']
+
+      # Append swarming named cache and delete swarming key, since it's under
+      # another layer of dict.
+      if 'named_caches' in mixin_append.get('swarming', {}):
+        new_test['swarming'].setdefault('named_caches', [])
+        new_test['swarming']['named_caches'].extend(
+            mixin_append['swarming']['named_caches'])
+        if len(mixin_append['swarming']) > 1:
+          raise BBGenErr('Only named_caches is supported under swarming key in '
+                         '$mixin_append, but there are: %s' %
+                         sorted(mixin_append['swarming'].keys()))
+        del mixin_append['swarming']
       for key in mixin_append:
         new_test.setdefault(key, [])
         if not isinstance(mixin_append[key], list):