[go: nahoru, domu]

Encapsulate the xcode handling within the base builder function.

Currently, the xcode_cache enum contains declarations only for the xcode
cache itself and builders must specify the matching xcode_build_version
property. Additionally, the handling of inserting the cache and setting
the property needs to be performed in any wrapper function that wants to
set the xcode to a specific value. This change puts the handling in the
lowest level and groups all of the xcode details into a single struct so
that builders and wrapper functions can just specify the xcode value.

Change-Id: Ia90829bb9124f93d4dcc48c67321289288a4c06e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566616
Commit-Queue: Erik Staab <estaab@chromium.org>
Auto-Submit: Garrett Beaty <gbeaty@chromium.org>
Reviewed-by: Erik Staab <estaab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832433}
diff --git a/infra/config/lib/builders.star b/infra/config/lib/builders.star
index 58dd6ea..c18c66f91 100644
--- a/infra/config/lib/builders.star
+++ b/infra/config/lib/builders.star
@@ -123,21 +123,25 @@
     ),
 )
 
-def xcode_enum(cache_name, cache_path):
-    return swarming.cache(name = cache_name, path = cache_path)
+def xcode_enum(version):
+    return struct(
+        version = version,
+        cache_name = "xcode_ios_{}".format(version),
+        cache_path = "xcode_ios_{}.app".format(version),
+    )
 
 # Keep this in-sync with the versions of bots in //ios/build/bots/.
-xcode_cache = struct(
+xcode = struct(
     # in use by webrtc mac builders
-    x11c29 = xcode_enum("xcode_ios_11c29", "xcode_ios_11c29.app"),
+    x11c29 = xcode_enum("11c29"),
     # in use by ci/ios-simulator-cronet and try/ios-simulator-cronet
-    x11e146 = xcode_enum("xcode_ios_11e146", "xcode_ios_11e146.app"),
+    x11e146 = xcode_enum("11e146"),
     # in use by ios-webkit-tot
-    x11e608cwk = xcode_enum("xcode_ios_11e608cwk", "xcode_ios_11e608cwk.app"),
+    x11e608cwk = xcode_enum("11e608cwk"),
     # (current default) xc12 gm seed
-    x12a7209 = xcode_enum("xcode_ios_12a7209", "xcode_ios_12a7209.app"),
+    x12a7209 = xcode_enum("12a7209"),
     # latest Xcode 12 beta version.
-    x12b5044c = xcode_enum("xcode_ios_12b5044c", "xcode_ios_12b5044c.app"),
+    x12b5044c = xcode_enum("12b5044c"),
 )
 
 ################################################################################
@@ -265,6 +269,7 @@
     os = None,
     project_trigger_overrides = None,
     pool = None,
+    xcode = None,
     ssd = args.COMPUTE,
     use_clang_coverage = False,
     use_java_coverage = False,
@@ -300,6 +305,7 @@
         builder_group = args.DEFAULT,
         pool = args.DEFAULT,
         ssd = args.DEFAULT,
+        xcode = args.DEFAULT,
         project_trigger_overrides = args.DEFAULT,
         configure_kitchen = args.DEFAULT,
         goma_backend = args.DEFAULT,
@@ -368,6 +374,13 @@
         If True, emits a 'ssd:1' dimension. If False, emits a 'ssd:0' parameter.
         By default, considered False if builderless is considered True and
         otherwise None.
+      * xcode - a member of the `xcode` enum indicating the xcode version the
+        builder requires. Emits a cache declaration of the form
+        ```{
+          name: <xcode.cache_name>
+          path: <xcode.cache_path>
+        }```. Also emits a 'xcode_build_version:<xcode.version>' property if the
+        property is not already set.
       * project_trigger_overrides - a dict mapping the LUCI projects declared in
         recipe BotSpecs to the LUCI project to use when triggering builders. When
         this builder triggers another builder, if the BotSpec for that builder has
@@ -539,6 +552,13 @@
     triggered_by = defaults.get_value("triggered_by", triggered_by)
     if triggered_by != args.COMPUTE:
         kwargs["triggered_by"] = triggered_by
+    xcode = defaults.get_value("xcode", xcode)
+    if xcode:
+        kwargs["caches"] = (kwargs.get("caches") or []) + [swarming.cache(
+            name = xcode.cache_name,
+            path = xcode.cache_path,
+        )]
+        properties.setdefault("xcode_build_version", xcode.version)
 
     return branches.builder(
         name = name,
@@ -568,5 +588,5 @@
     defaults = defaults,
     goma = goma,
     os = os,
-    xcode_cache = xcode_cache,
+    xcode = xcode,
 )
diff --git a/infra/config/lib/ci.star b/infra/config/lib/ci.star
index 822c1a9..dda3112 100644
--- a/infra/config/lib/ci.star
+++ b/infra/config/lib/ci.star
@@ -667,25 +667,17 @@
 def fyi_ios_builder(
         *,
         name,
-        caches = None,
         executable = "recipe:chromium",
         goma_backend = builders.goma.backend.RBE_PROD,
         os = builders.os.MAC_10_15,
-        properties = None,
+        xcode = builders.xcode.x12a7209,
         **kwargs):
-    # Default cache and properties sync
-    caches = caches or [builders.xcode_cache.x12a7209]
-
-    properties = properties or {}
-    properties.setdefault("xcode_build_version", "12a7209")
-
     return fyi_builder(
         name = name,
-        caches = caches,
         cores = None,
         executable = executable,
         os = os,
-        properties = properties,
+        xcode = xcode,
         **kwargs
     )
 
@@ -876,23 +868,16 @@
 def mac_ios_builder(
         *,
         name,
-        caches = None,
         executable = "recipe:chromium",
         goma_backend = builders.goma.backend.RBE_PROD,
-        properties = None,
+        xcode = builders.xcode.x12a7209,
         **kwargs):
-    caches = caches or [builders.xcode_cache.x12a7209]
-
-    properties = properties or {}
-    properties.setdefault("xcode_build_version", "12a7209")
-
     return mac_builder(
         name = name,
-        caches = caches,
         goma_backend = goma_backend,
         executable = executable,
         os = builders.os.MAC_10_15,
-        properties = properties,
+        xcode = xcode,
         **kwargs
     )
 
diff --git a/infra/config/lib/try.star b/infra/config/lib/try.star
index 5291558..ae4ef10 100644
--- a/infra/config/lib/try.star
+++ b/infra/config/lib/try.star
@@ -350,26 +350,19 @@
 def chromium_mac_ios_builder(
         *,
         name,
-        caches = None,
         executable = "recipe:chromium_trybot",
         goma_backend = builders.goma.backend.RBE_PROD,
         os = builders.os.MAC_10_15,
-        properties = None,
+        xcode = builders.xcode.x12a7209,
         **kwargs):
-    caches = caches or [builders.xcode_cache.x12a7209]
-
-    properties = properties or {}
-    properties.setdefault("xcode_build_version", "12a7209")
-
     return try_builder(
         name = name,
         builder_group = "tryserver.chromium.mac",
-        caches = caches,
         cores = None,
         executable = executable,
         goma_backend = goma_backend,
         os = os,
-        properties = properties,
+        xcode = xcode,
         **kwargs
     )
 
diff --git a/infra/config/subprojects/chromium/ci.star b/infra/config/subprojects/chromium/ci.star
index 8fac0a3..3132c09 100644
--- a/infra/config/subprojects/chromium/ci.star
+++ b/infra/config/subprojects/chromium/ci.star
@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 
 load("//lib/branches.star", "branches")
-load("//lib/builders.star", "builder_name", "cpu", "goma", "os", "xcode_cache")
+load("//lib/builders.star", "builder_name", "cpu", "goma", "os", "xcode")
 load("//lib/ci.star", "ci")
 load("//console-header.star", "HEADER")
 load("//project.star", "settings")
@@ -1645,33 +1645,27 @@
 ci.clang_builder(
     name = "ToTiOS",
     builderless = False,
-    caches = [xcode_cache.x12a7209],
     console_view_entry = ci.console_view_entry(
         category = "iOS|public",
         short_name = "sim",
     ),
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
     ssd = True,
+    xcode = xcode.x12a7209,
 )
 
 ci.clang_builder(
     name = "ToTiOSDevice",
     builderless = False,
-    caches = [xcode_cache.x12a7209],
     console_view_entry = ci.console_view_entry(
         category = "iOS|public",
         short_name = "dev",
     ),
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
     ssd = True,
+    xcode = xcode.x12a7209,
 )
 
 ci.clang_mac_builder(
@@ -3011,7 +3005,6 @@
 
 ci.fyi_coverage_builder(
     name = "ios-simulator-code-coverage",
-    caches = [xcode_cache.x12a7209],
     console_view_entry = ci.console_view_entry(
         category = "code_coverage",
         short_name = "ios",
@@ -3021,9 +3014,7 @@
     use_clang_coverage = True,
     coverage_exclude_sources = "ios_test_files_and_test_utils",
     coverage_test_types = ["overall", "unit"],
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 ci.fyi_coverage_builder(
@@ -3092,16 +3083,13 @@
 ci.fyi_ios_builder(
     name = "ios-simulator-cronet",
     branch_selector = branches.STANDARD_MILESTONE,
-    caches = [xcode_cache.x11e146],
     console_view_entry = ci.console_view_entry(
         category = "cronet",
     ),
     cq_mirrors_console_view = "mirrors",
     main_console_view = main_console_if_on_branch(),
     notifies = ["cronet"],
-    properties = {
-        "xcode_build_version": "11e146",
-    },
+    xcode = xcode.x11e146,
 )
 
 ci.fyi_ios_builder(
@@ -3114,16 +3102,13 @@
 
 ci.fyi_ios_builder(
     name = "ios-webkit-tot",
-    caches = [xcode_cache.x11e608cwk],
     console_view_entry = ci.console_view_entry(
         category = "iOS",
         short_name = "wk",
     ),
-    properties = {
-        "xcode_build_version": "11e608cwk",
-    },
     schedule = "0 1-23/6 * * *",
     triggered_by = [],
+    xcode = xcode.x11e608cwk,
 )
 
 ci.fyi_ios_builder(
@@ -3168,10 +3153,7 @@
         category = "iOS|iOS14",
         short_name = "sdk14",
     ),
-    caches = [xcode_cache.x12b5044c],
-    properties = {
-        "xcode_build_version": "12b5044c",
-    },
+    xcode = xcode.x12b5044c,
 )
 
 ci.fyi_mac_builder(
diff --git a/infra/config/subprojects/chromium/try.star b/infra/config/subprojects/chromium/try.star
index 5c117cf..a4e3a38 100644
--- a/infra/config/subprojects/chromium/try.star
+++ b/infra/config/subprojects/chromium/try.star
@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 
 load("//lib/branches.star", "branches")
-load("//lib/builders.star", "cpu", "goma", "os", "xcode_cache")
+load("//lib/builders.star", "cpu", "goma", "os", "xcode")
 load("//lib/try.star", "try_")
 load("//project.star", "settings")
 
@@ -1348,11 +1348,7 @@
 try_.chromium_mac_ios_builder(
     name = "ios-simulator-cronet",
     branch_selector = branches.STANDARD_MILESTONE,
-    caches = [xcode_cache.x11e146],
     main_list_view = "try",
-    properties = {
-        "xcode_build_version": "11e146",
-    },
     tryjob = try_.job(
         location_regexp = [
             ".+/[+]/components/cronet/.+",
@@ -1363,6 +1359,7 @@
             ".+/[+]/components/cronet/android/.+",
         ],
     ),
+    xcode = xcode.x11e146,
 )
 
 try_.chromium_mac_ios_builder(
@@ -1415,10 +1412,7 @@
 
 try_.chromium_mac_ios_builder(
     name = "ios14-sdk-simulator",
-    caches = [xcode_cache.x12b5044c],
-    properties = {
-        "xcode_build_version": "12b5044c",
-    },
+    xcode = xcode.x12b5044c,
 )
 
 try_.chromium_updater_mac_builder(
diff --git a/infra/config/subprojects/goma/goma.star b/infra/config/subprojects/goma/goma.star
index d6727063..83dc774 100644
--- a/infra/config/subprojects/goma/goma.star
+++ b/infra/config/subprojects/goma/goma.star
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-load("//lib/builders.star", "builder", "cpu", "defaults", "goma", "os", "xcode_cache")
+load("//lib/builders.star", "builder", "cpu", "defaults", "goma", "os", "xcode")
 
 luci.bucket(
     name = "goma",
@@ -110,12 +110,9 @@
 
 fyi_goma_canary_builder(
     name = "ios-device-goma-canary-clobber",
-    caches = [xcode_cache.x12a7209],
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 fyi_goma_canary_builder(
@@ -185,12 +182,9 @@
 
 fyi_goma_rbe_canary_builder(
     name = "ios-device-goma-rbe-canary-clobber",
-    caches = [xcode_cache.x12a7209],
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 fyi_goma_rbe_canary_builder(
@@ -270,12 +264,9 @@
 
 fyi_goma_latest_client_builder(
     name = "ios-device-goma-latest-clobber",
-    caches = [xcode_cache.x12a7209],
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 fyi_goma_latest_client_builder(
@@ -359,12 +350,9 @@
 
 fyi_goma_rbe_latest_client_builder(
     name = "ios-device-goma-rbe-latest-clobber",
-    caches = [xcode_cache.x12a7209],
     cores = None,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 fyi_goma_rbe_latest_client_builder(
@@ -477,12 +465,9 @@
 
 goma_mac_builder(
     name = "Chromium iOS Goma RBE ToT",
-    caches = [xcode_cache.x12a7209],
     goma_backend = goma.backend.RBE_TOT,
     os = os.MAC_10_15,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 goma_mac_builder(
diff --git a/infra/config/subprojects/webrtc/webrtc.fyi.star b/infra/config/subprojects/webrtc/webrtc.fyi.star
index 72ec798..ea28b1a2 100644
--- a/infra/config/subprojects/webrtc/webrtc.fyi.star
+++ b/infra/config/subprojects/webrtc/webrtc.fyi.star
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-load("//lib/builders.star", "builder", "cpu", "defaults", "goma", "os", "xcode_cache")
+load("//lib/builders.star", "builder", "cpu", "defaults", "goma", "os", "xcode")
 
 luci.bucket(
     name = "webrtc.fyi",
@@ -139,22 +139,16 @@
 
 builder(
     name = "WebRTC Chromium FYI ios-device",
-    caches = [xcode_cache.x12a7209],
     executable = "recipe:webrtc/chromium_ios",
     goma_backend = goma.backend.RBE_PROD,
     os = os.MAC_ANY,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )
 
 builder(
     name = "WebRTC Chromium FYI ios-simulator",
-    caches = [xcode_cache.x12a7209],
     executable = "recipe:webrtc/chromium_ios",
     goma_backend = goma.backend.RBE_PROD,
     os = os.MAC_ANY,
-    properties = {
-        "xcode_build_version": "12a7209",
-    },
+    xcode = xcode.x12a7209,
 )