blob: cbca8e4deb9cd744afc30627104620d74d1160dc [file] [log] [blame]
borenetdb182c72016-09-30 12:53:12 -07001// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7/*
8 Generate the tasks.json file.
9*/
10
11import (
borenetdb182c72016-09-30 12:53:12 -070012 "encoding/json"
Eric Boren27225492017-02-01 15:56:55 -050013 "flag"
borenetdb182c72016-09-30 12:53:12 -070014 "fmt"
Eric Boren27225492017-02-01 15:56:55 -050015 "io/ioutil"
borenetdb182c72016-09-30 12:53:12 -070016 "os"
17 "path"
Eric Boren7e3a3642017-06-14 15:25:31 -040018 "path/filepath"
Eric Boren27225492017-02-01 15:56:55 -050019 "regexp"
Eric Boren7e3a3642017-06-14 15:25:31 -040020 "runtime"
borenetdb182c72016-09-30 12:53:12 -070021 "sort"
Kevin Lubick32f318b2017-10-17 13:40:52 -040022 "strconv"
borenetdb182c72016-09-30 12:53:12 -070023 "strings"
Eric Boren4b254b92016-11-08 12:55:32 -050024 "time"
borenetdb182c72016-09-30 12:53:12 -070025
Eric Borencb0b98b2018-06-08 08:25:57 -040026 "github.com/golang/glog"
Eric Boren7e3a3642017-06-14 15:25:31 -040027 "go.skia.org/infra/go/sklog"
borenetdb182c72016-09-30 12:53:12 -070028 "go.skia.org/infra/go/util"
29 "go.skia.org/infra/task_scheduler/go/specs"
30)
31
32const (
Kevin Lubick814b1492017-11-29 14:45:14 -050033 BUNDLE_RECIPES_NAME = "Housekeeper-PerCommit-BundleRecipes"
Stephan Altmueller88df8d22018-03-07 14:44:44 -050034 ISOLATE_GCLOUD_LINUX_NAME = "Housekeeper-PerCommit-IsolateGCloudLinux"
Eric Boren9d834582018-08-03 14:29:03 -040035 ISOLATE_GO_DEPS_NAME = "Housekeeper-PerCommit-IsolateGoDeps"
Stephan Altmueller88df8d22018-03-07 14:44:44 -050036 ISOLATE_GO_LINUX_NAME = "Housekeeper-PerCommit-IsolateGoLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050037 ISOLATE_SKIMAGE_NAME = "Housekeeper-PerCommit-IsolateSkImage"
38 ISOLATE_SKP_NAME = "Housekeeper-PerCommit-IsolateSKP"
39 ISOLATE_SVG_NAME = "Housekeeper-PerCommit-IsolateSVG"
40 ISOLATE_NDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidNDKLinux"
Stephan Altmueller2a552172018-02-20 11:40:25 -050041 ISOLATE_SDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidSDKLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050042 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
43 ISOLATE_WIN_VULKAN_SDK_NAME = "Housekeeper-PerCommit-IsolateWinVulkanSDK"
Eric Boren8b3f9e62017-04-04 09:06:16 -040044
Ben Wagner1676ec22018-04-06 17:39:06 -040045 DEFAULT_OS_DEBIAN = "Debian-9.4"
46 DEFAULT_OS_LINUX_GCE = DEFAULT_OS_DEBIAN
Ben Wagnere8d2a452018-08-06 10:00:54 -040047 DEFAULT_OS_MAC = "Mac-10.13.6"
Eric Boren170c39c2017-11-15 11:22:57 -050048 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
49 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070050
Eric Boreneb702382018-04-19 09:36:45 -040051 DEFAULT_PROJECT = "skia"
52
Ben Wagner297e86b2018-05-14 12:38:09 -040053 // Small is a 2-core machine.
54 // TODO(dogben): Would n1-standard-1 or n1-standard-2 be sufficient?
Ben Wagnere99a4b12018-05-04 11:18:01 -040055 MACHINE_TYPE_SMALL = "n1-highmem-2"
Ben Wagner297e86b2018-05-14 12:38:09 -040056 // Medium is a 16-core machine
57 MACHINE_TYPE_MEDIUM = "n1-standard-16"
58 // Large is a 64-core machine. (We use "highcpu" because we don't need more than 57GB memory for
59 // any of our tasks.)
Ben Wagnere99a4b12018-05-04 11:18:01 -040060 MACHINE_TYPE_LARGE = "n1-highcpu-64"
61
Eric Boren9599b0f2018-04-17 15:55:57 -040062 // Swarming output dirs.
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040063 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
64 OUTPUT_BUILD = "build"
65 OUTPUT_TEST = "test"
66 OUTPUT_PERF = "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -040067
borenetdb182c72016-09-30 12:53:12 -070068 // Name prefix for upload jobs.
69 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040070
71 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
72 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040073 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
74 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren84ae6412018-09-27 14:55:03 -040075 SERVICE_ACCOUNT_UPDATE_GO_DEPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040076 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
77 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
78 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040079 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
80 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070081)
82
83var (
84 // "Constants"
85
Eric Boren27225492017-02-01 15:56:55 -050086 // Top-level list of all jobs to run at each commit; loaded from
87 // jobs.json.
88 JOBS []string
89
Eric Boren27225492017-02-01 15:56:55 -050090 // General configuration information.
91 CONFIG struct {
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040092 GsBucketGm string `json:"gs_bucket_gm"`
93 GoldHashesURL string `json:"gold_hashes_url"`
94 GsBucketNano string `json:"gs_bucket_nano"`
95 GsBucketCalm string `json:"gs_bucket_calm"`
96 NoUpload []string `json:"no_upload"`
97 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070098 }
99
Eric Boreneb702382018-04-19 09:36:45 -0400100 // alternateProject can be set in an init function to override the default project ID.
101 alternateProject string
102
Ben Wagner053d0462018-04-17 12:45:29 -0400103 // alternateServiceAccount can be set in an init function to override the normal service accounts.
104 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
105 // should be used, or uses sklog.Fatal to indicate a problem.
106 alternateServiceAccount func(serviceAccountEnum string) string
107
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400108 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
109 // dimensions for the given task.
110 alternateSwarmDimensions func(parts map[string]string) []string
111
Eric Borenfd4d60e2017-09-15 10:35:44 -0400112 // internalHardwareLabelFn can be set in an init function to provide an
113 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400114 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400115
borenetdb182c72016-09-30 12:53:12 -0700116 // Defines the structure of job names.
117 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500118
Eric Boren5cb5c742018-04-27 13:14:38 -0400119 // Named caches used by tasks.
120 CACHES_GIT = []*specs.Cache{
121 &specs.Cache{
122 Name: "git",
123 Path: "cache/git",
124 },
125 &specs.Cache{
126 Name: "git_cache",
127 Path: "cache/git_cache",
128 },
129 }
130 CACHES_WORKDIR = []*specs.Cache{
131 &specs.Cache{
132 Name: "work",
133 Path: "cache/work",
134 },
135 }
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400136 CACHES_DOCKER = []*specs.Cache{
137 &specs.Cache{
138 Name: "docker",
139 Path: "cache/docker",
140 },
141 }
Ben Wagner702fe012018-06-15 09:19:13 -0400142 // Versions of the following copied from
143 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template_canary.json#42
144 // to test the fix for chromium:836196.
145 // (In the future we may want to use versions from
146 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template.json#42)
Eric Boren9599b0f2018-04-17 15:55:57 -0400147 // TODO(borenet): Roll these versions automatically!
148 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
149 &specs.CipdPackage{
150 Name: "infra/tools/luci/vpython/${platform}",
151 Path: "cipd_bin_packages",
Eric Borenb33f9eb2018-08-03 10:31:24 -0400152 Version: "git_revision:b6cdec8586c9f8d3d728b1bc0bd4331330ba66fc",
Eric Boren9599b0f2018-04-17 15:55:57 -0400153 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400154 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400155
Eric Borenaa037522018-06-18 16:02:15 -0400156 CIPD_PKGS_CPYTHON = []*specs.CipdPackage{
157 &specs.CipdPackage{
158 Name: "infra/python/cpython/${platform}",
159 Path: "cipd_bin_packages",
160 Version: "version:2.7.14.chromium14",
161 },
162 }
163
Eric Boren9599b0f2018-04-17 15:55:57 -0400164 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
165 &specs.CipdPackage{
166 Name: "infra/tools/luci/kitchen/${platform}",
167 Path: ".",
Ben Wagner702fe012018-06-15 09:19:13 -0400168 Version: "git_revision:546aae39f1fb9dce9add528e2011afa574535ecd",
Eric Boren9599b0f2018-04-17 15:55:57 -0400169 },
170 &specs.CipdPackage{
Ben Wagnercd7ace22018-06-11 15:48:35 -0400171 Name: "infra/tools/luci-auth/${platform}",
Eric Boren9599b0f2018-04-17 15:55:57 -0400172 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400173 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400174 },
175 }, CIPD_PKGS_PYTHON...)
176
177 CIPD_PKGS_GIT = []*specs.CipdPackage{
178 &specs.CipdPackage{
179 Name: "infra/git/${platform}",
180 Path: "cipd_bin_packages",
Eric Borene42cef52018-06-20 07:11:38 -0400181 Version: "version:2.17.1.chromium15",
Eric Boren9599b0f2018-04-17 15:55:57 -0400182 },
183 &specs.CipdPackage{
184 Name: "infra/tools/git/${platform}",
185 Path: "cipd_bin_packages",
Eric Boren3f13bcb2018-06-15 07:39:36 -0400186 Version: "git_revision:0ae21738597e5601ba90372315145fec18582fc4",
Eric Boren9599b0f2018-04-17 15:55:57 -0400187 },
188 &specs.CipdPackage{
189 Name: "infra/tools/luci/git-credential-luci/${platform}",
190 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400191 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400192 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000193 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400194
Eric Boren9599b0f2018-04-17 15:55:57 -0400195 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
196 &specs.CipdPackage{
197 Name: "infra/gsutil",
198 Path: "cipd_bin_packages",
199 Version: "version:4.28",
200 },
201 }
202
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400203 CIPD_PKGS_XCODE = []*specs.CipdPackage{
204 // https://chromium.googlesource.com/chromium/tools/build/+/e19b7d9390e2bb438b566515b141ed2b9ed2c7c2/scripts/slave/recipe_modules/ios/api.py#317
205 // This package is really just an installer for XCode.
206 &specs.CipdPackage{
Ben Wagner66760792018-08-09 12:52:16 -0400207 Name: "infra/tools/mac_toolchain/${platform}",
208 Path: "mac_toolchain",
209 // When this is updated, also update
210 // https://skia.googlesource.com/skcms.git/+/f1e2b45d18facbae2dece3aca673fe1603077846/infra/bots/gen_tasks.go#56
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400211 Version: "git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a",
212 },
213 }
214
Eric Boren27225492017-02-01 15:56:55 -0500215 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500216 builderNameSchemaFile = flag.String("builder_name_schema", "", "Path to the builder_name_schema.json file. If not specified, uses infra/bots/recipe_modules/builder_name_schema/builder_name_schema.json from this repo.")
217 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
218 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500219 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700220)
221
Eric Boreneb702382018-04-19 09:36:45 -0400222// Build the LogDog annotation URL.
223func logdogAnnotationUrl() string {
224 project := DEFAULT_PROJECT
225 if alternateProject != "" {
226 project = alternateProject
227 }
228 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
229}
230
Eric Boren9599b0f2018-04-17 15:55:57 -0400231// Create a properties JSON string.
232func props(p map[string]string) string {
233 d := make(map[string]interface{}, len(p)+1)
234 for k, v := range p {
235 d[k] = interface{}(v)
236 }
237 d["$kitchen"] = struct {
238 DevShell bool `json:"devshell"`
239 GitAuth bool `json:"git_auth"`
240 }{
241 DevShell: true,
242 GitAuth: true,
243 }
244
245 j, err := json.Marshal(d)
246 if err != nil {
247 sklog.Fatal(err)
248 }
249 return strings.Replace(string(j), "\\u003c", "<", -1)
250}
251
252// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
253// recipe.
254func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
255 if serviceAccount != "" && alternateServiceAccount != nil {
256 serviceAccount = alternateServiceAccount(serviceAccount)
257 }
258 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
Eric Borenaa037522018-06-18 16:02:15 -0400259 if strings.Contains(name, "Win") {
260 cipd = append(cipd, CIPD_PKGS_CPYTHON...)
261 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400262 properties := map[string]string{
263 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
264 "buildername": name,
265 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400266 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400267 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
268 "patch_set": specs.PLACEHOLDER_PATCHSET,
269 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
270 "repository": specs.PLACEHOLDER_REPO,
271 "revision": specs.PLACEHOLDER_REVISION,
272 "swarm_out_dir": outputDir,
273 }
274 for k, v := range extraProps {
275 properties[k] = v
276 }
277 var outputs []string = nil
278 if outputDir != OUTPUT_NONE {
279 outputs = []string{outputDir}
280 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400281 task := &specs.TaskSpec{
282 Caches: []*specs.Cache{
283 &specs.Cache{
284 Name: "vpython",
285 Path: "cache/vpython",
286 },
287 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400288 CipdPackages: cipd,
289 Command: []string{
290 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
291 "-checkout-dir", "recipe_bundle",
292 "-mode", "swarming",
293 "-luci-system-account", "system",
294 "-cache-dir", "cache",
295 "-temp-dir", "tmp",
296 "-known-gerrit-host", "android.googlesource.com",
297 "-known-gerrit-host", "boringssl.googlesource.com",
298 "-known-gerrit-host", "chromium.googlesource.com",
299 "-known-gerrit-host", "dart.googlesource.com",
300 "-known-gerrit-host", "fuchsia.googlesource.com",
301 "-known-gerrit-host", "go.googlesource.com",
302 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400303 "-known-gerrit-host", "skia.googlesource.com",
304 "-known-gerrit-host", "webrtc.googlesource.com",
305 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
306 "-workdir", ".",
307 "-recipe", recipe,
308 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400309 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400310 },
311 Dependencies: []string{BUNDLE_RECIPES_NAME},
312 Dimensions: dimensions,
313 EnvPrefixes: map[string][]string{
Kevin Lubick37baac12018-10-09 16:25:27 -0400314 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
Eric Boren7c42e012018-08-20 09:45:02 -0400315 "VPYTHON_VIRTUALENV_ROOT": []string{"cache/vpython"},
Eric Boren9599b0f2018-04-17 15:55:57 -0400316 },
317 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400318 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400319 },
320 Isolate: relpath(isolate),
321 Outputs: outputs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400322 ServiceAccount: serviceAccount,
323 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400324 timeout(task, time.Hour)
325 return task
Eric Boren9599b0f2018-04-17 15:55:57 -0400326}
327
Eric Borenfd4d60e2017-09-15 10:35:44 -0400328// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400329func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400330 if internalHardwareLabelFn != nil {
331 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400332 }
333 return nil
334}
335
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400336// linuxGceDimensions are the Swarming dimensions for Linux GCE instances.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400337func linuxGceDimensions(machineType string) []string {
Eric Boren27225492017-02-01 15:56:55 -0500338 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400339 // Specify CPU to avoid running builds on bots with a more unique CPU.
340 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500341 "gpu:none",
Ben Wagner82a33422018-04-26 18:02:23 -0400342 // Currently all Linux GCE tasks run on 16-CPU machines.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400343 fmt.Sprintf("machine_type:%s", machineType),
Eric Boren170c39c2017-11-15 11:22:57 -0500344 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500345 fmt.Sprintf("pool:%s", CONFIG.Pool),
346 }
347}
348
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400349func wasmGceDimensions() []string {
350 // There's limited parallelism for WASM builds, so we can get away with the medium
351 // instance instead of the beefy large instance.
352 // Docker being intsalled is the most important part.
353 return append(linuxGceDimensions(MACHINE_TYPE_MEDIUM), "docker_installed:true")
354}
355
borenetdb182c72016-09-30 12:53:12 -0700356// deriveCompileTaskName returns the name of a compile task based on the given
357// job name.
358func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500359 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500360 return "Build-Debian9-GCC-x86_64-Release"
Yuqian Li4a577af2018-01-05 11:13:43 -0500361 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700362 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400363 ec := []string{}
364 if val := parts["extra_config"]; val != "" {
365 ec = strings.Split(val, "_")
Mike Kleinc24e0c12018-08-17 13:24:51 -0400366 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR", "FSAA", "FAAA", "FDAA", "NativeFonts", "GDI", "NoGPUThreads", "ProcDump", "DDL1", "DDL3", "T8888", "DDLTotal", "DDLRecord", "9x9", "BonusConfigs"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400367 keep := make([]string, 0, len(ec))
368 for _, part := range ec {
369 if !util.In(part, ignore) {
370 keep = append(keep, part)
371 }
372 }
373 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400374 }
borenetdb182c72016-09-30 12:53:12 -0700375 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400376 if !util.In("Android", ec) {
377 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700378 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400379 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500380 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400381 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400382 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400383 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400384 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400385 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700386 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400387 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700388 task_os = "Mac"
389 } else if strings.Contains(task_os, "Win") {
390 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400391 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
392 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700393 }
Eric Boren50831302016-11-18 13:10:51 -0500394 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700395 "role": "Build",
396 "os": task_os,
397 "compiler": parts["compiler"],
398 "target_arch": parts["arch"],
399 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500400 }
Kevin Lubick92c91712018-08-09 10:00:02 -0400401 if strings.Contains(jobName, "PathKit") {
402 ec = []string{"PathKit"}
403 }
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400404 if strings.Contains(jobName, "CanvasKit") {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400405 if parts["cpu_or_gpu"] == "CPU" {
406 ec = []string{"CanvasKit_CPU"}
407 } else {
408 ec = []string{"CanvasKit"}
409 }
410
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400411 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400412 if len(ec) > 0 {
413 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500414 }
415 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700416 if err != nil {
417 glog.Fatal(err)
418 }
419 return name
Kevin Lubick49688432018-10-08 13:58:47 -0400420 } else if parts["role"] == "BuildStats" {
421 return strings.Replace(jobName, "BuildStats", "Build", 1)
borenetdb182c72016-09-30 12:53:12 -0700422 } else {
423 return jobName
424 }
425}
426
427// swarmDimensions generates swarming bot dimensions for the given task.
428func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400429 if alternateSwarmDimensions != nil {
430 return alternateSwarmDimensions(parts)
431 }
432 return defaultSwarmDimensions(parts)
433}
434
435// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
436func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700437 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500438 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700439 }
440 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400441 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400442 "Android": "Android",
443 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400444 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400445 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500446 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400447 "Ubuntu14": DEFAULT_OS_UBUNTU,
Eric Boren810c2b62017-07-11 08:11:15 -0400448 "Ubuntu17": "Ubuntu-17.04",
Ben Wagner2aa9a222018-11-06 13:45:40 -0500449 "Ubuntu18": "Ubuntu-18.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500450 "Win": DEFAULT_OS_WIN,
Ben Wagner95dec692018-11-21 13:20:48 -0500451 "Win10": "Windows-10-17134.407",
Kevin Lubick291547d2017-03-21 09:25:34 -0400452 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500453 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400454 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400455 "Win8": "Windows-8.1-SP0",
Stephan Altmueller0edb9822018-08-16 18:11:57 -0400456 "iOS": "iOS-11.4.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500457 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400458 if !ok {
459 glog.Fatalf("Entry %q not found in OS mapping.", os)
460 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500461 if os == "Win10" && parts["model"] == "Golo" {
Ben Wagnerf6148b62018-03-15 13:53:25 -0400462 // ChOps-owned machines have Windows 10 v1709, but a slightly different version than Skolo.
463 d["os"] = "Windows-10-16299.309"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500464 }
Ben Wagnere1c37a72018-04-24 16:59:48 -0400465 if d["os"] == DEFAULT_OS_WIN {
466 // TODO(dogben): Temporarily add image dimension during upgrade.
Ben Wagner7a879622018-07-18 10:14:23 -0400467 d["image"] = "windows-server-2016-dc-v20180710"
Ben Wagnere1c37a72018-04-24 16:59:48 -0400468 }
borenetdb182c72016-09-30 12:53:12 -0700469 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400470 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700471 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400472 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400473 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700474 // For Android, the device type is a better dimension
475 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400476 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400477 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500478 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500479 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagner17d18962018-09-13 15:05:15 -0400480 "GalaxyS7_G930FD": {"herolte", "R16NW_G930FXXS2ERH6"}, // This is Oreo.
Ben Wagner9e972312018-11-29 10:00:36 -0500481 "GalaxyS9": {"starlte", "R16NW_G960FXXU2BRJ8"}, // This is Oreo.
Ben Wagner8d8f45d2018-06-04 17:32:04 -0400482 "MotoG4": {"athene", "NPJS25.93-14.7-8"},
Ben Wagner7efa13d2018-08-28 15:52:38 -0400483 "NVIDIA_Shield": {"foster", "OPR6.170623.010"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500484 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500485 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500486 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner2a510c92018-04-11 12:36:56 -0400487 "NexusPlayer": {"fugu", "OPR2.170623.027"},
Kevin Lubick8fe1b042018-08-21 13:00:14 -0400488 "Pixel": {"sailfish", "PPR1.180610.009"},
Kevin Lubick1118cfd2018-08-24 10:24:54 -0400489 "Pixel2XL": {"taimen", "PPR1.180610.009"},
Ben Wagner36682782017-06-14 10:01:45 -0400490 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500491 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400492 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500493 }
Eric Boren4b254b92016-11-08 12:55:32 -0500494 d["device_type"] = deviceInfo[0]
495 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700496 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400497 device, ok := map[string]string{
Eric Boren792079cf2016-11-09 14:03:20 -0500498 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400499 "iPhone6": "iPhone7,2",
500 "iPhone7": "iPhone9,1",
501 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700502 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400503 if !ok {
504 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
505 }
506 d["device"] = device
Ben Wagnerd26e4462018-05-22 10:46:15 -0400507 } else if strings.Contains(parts["extra_config"], "SwiftShader") {
508 if parts["model"] != "GCE" || d["os"] != DEFAULT_OS_DEBIAN || parts["cpu_or_gpu_value"] != "SwiftShader" {
509 glog.Fatalf("Please update defaultSwarmDimensions for SwiftShader %s %s %s.", parts["os"], parts["model"], parts["cpu_or_gpu_value"])
510 }
511 d["cpu"] = "x86-64-Haswell_GCE"
512 d["os"] = DEFAULT_OS_LINUX_GCE
513 d["machine_type"] = MACHINE_TYPE_SMALL
Kevin Lubick35b87a52018-10-08 15:07:42 -0400514 } else if strings.Contains(parts["extra_config"], "SKQP") && parts["cpu_or_gpu_value"] == "Emulator" {
515 if parts["model"] != "NUC7i5BNK" || d["os"] != DEFAULT_OS_DEBIAN {
516 glog.Fatalf("Please update defaultSwarmDimensions for SKQP::Emulator %s %s.", parts["os"], parts["model"])
517 }
518 d["cpu"] = "x86-64-i5-7260U"
519 d["os"] = "Debian-9.4"
520 // KVM means Kernel-based Virtual Machine, that is, can this vm virtualize commands
521 // For us, this means, can we run an x86 android emulator on it.
522 // kjlubick tried running this on GCE, but it was a bit too slow on the large install.
523 // So, we run on bare metal machines in the Skolo (that should also have KVM).
524 d["kvm"] = "1"
525 d["docker_installed"] = "true"
borenetdb182c72016-09-30 12:53:12 -0700526 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400527 modelMapping, ok := map[string]map[string]string{
528 "AVX": {
Ben Wagner7ea54282018-08-22 14:07:48 -0400529 "Golo": "x86-64-E5-2670",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400530 },
531 "AVX2": {
Ben Wagner35eb7fa2018-08-06 11:27:17 -0400532 "GCE": "x86-64-Haswell_GCE",
533 "MacBookPro11.5": "x86-64-i7-4870HQ",
534 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400535 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400536 "AVX512": {
537 "GCE": "x86-64-Skylake_GCE",
538 },
borenetdb182c72016-09-30 12:53:12 -0700539 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400540 if !ok {
541 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
542 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400543 cpu, ok := modelMapping[parts["model"]]
544 if !ok {
545 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700546 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400547 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500548 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
549 d["os"] = DEFAULT_OS_LINUX_GCE
550 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400551 if parts["model"] == "GCE" && d["cpu"] == "x86-64-Haswell_GCE" {
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -0400552 d["machine_type"] = MACHINE_TYPE_MEDIUM
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500553 }
borenetdb182c72016-09-30 12:53:12 -0700554 } else {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400555 if strings.Contains(parts["extra_config"], "CanvasKit") {
556 // GPU is defined for the WebGL version of CanvasKit, but
557 // it can still run on a GCE instance.
558 return wasmGceDimensions()
559 } else if strings.Contains(parts["os"], "Win") {
Ben Wagner1d060782017-06-14 10:34:18 -0400560 gpu, ok := map[string]string{
Ben Wagnerf6148b62018-03-15 13:53:25 -0400561 "GT610": "10de:104a-23.21.13.9101",
Ben Wagnerf713dd12018-10-26 14:09:52 -0400562 "GTX660": "10de:11c0-25.21.14.1634",
563 "GTX960": "10de:1401-25.21.14.1634",
Greg Daniel900e5c82018-08-28 10:59:24 -0400564 "IntelHD4400": "8086:0a16-20.19.15.4963",
Ben Wagner32eb0222018-10-30 16:33:30 -0400565 "IntelIris540": "8086:1926-25.20.100.6326",
Greg Daniel900e5c82018-08-28 10:59:24 -0400566 "IntelIris6100": "8086:162b-20.19.15.4963",
Ben Wagner1f0fb092018-08-27 18:09:52 -0400567 "RadeonHD7770": "1002:683d-24.20.13001.1010",
568 "RadeonR9M470X": "1002:6646-24.20.13001.1010",
Ben Wagnerce7a16b2018-11-14 21:16:00 -0500569 "QuadroP400": "10de:1cb3-25.21.14.1678",
Ben Wagner1d060782017-06-14 10:34:18 -0400570 }[parts["cpu_or_gpu_value"]]
571 if !ok {
572 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
573 }
574 d["gpu"] = gpu
Eric Borenbb198fb2017-06-28 11:45:54 -0400575 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400576 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400577 // Intel drivers come from CIPD, so no need to specify the version here.
578 "IntelBayTrail": "8086:0f31",
579 "IntelHD2000": "8086:0102",
580 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500581 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400582 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400583 }[parts["cpu_or_gpu_value"]]
584 if !ok {
585 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
586 }
Ben Wagner2aa9a222018-11-06 13:45:40 -0500587 if parts["os"] == "Ubuntu18" && parts["cpu_or_gpu_value"] == "QuadroP400" {
588 // Ubuntu18 has a slightly newer GPU driver.
589 gpu = "10de:1cb3-390.87"
590 }
Ben Wagner1d060782017-06-14 10:34:18 -0400591 d["gpu"] = gpu
592 } else if strings.Contains(parts["os"], "Mac") {
593 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500594 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500595 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400596 "IntelIris5100": "8086:0a2e",
Ben Wagnereeeb3282018-05-15 16:45:42 -0400597 "RadeonHD8870M": "1002:6821-4.0.20-3.2.8",
Ben Wagner1d060782017-06-14 10:34:18 -0400598 }[parts["cpu_or_gpu_value"]]
599 if !ok {
600 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
601 }
602 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500603 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
604 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
605 // Run all tasks on Golo machines for now.
606 d["cpu"] = "x86-64-i7-4578U"
607 }
Ben Wagner1d060782017-06-14 10:34:18 -0400608 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500609 version, ok := map[string]string{
Kevin Lubickff8387f2018-05-01 10:43:35 -0400610 "MaliT604": "10575.22.0",
Kevin Lubicke114e592018-05-01 08:53:52 -0400611 "MaliT764": "10575.22.0",
Kevin Lubicke467d4e2018-05-01 13:12:58 -0400612 "MaliT860": "10575.22.0",
613 "PowerVRGX6250": "10575.22.0",
614 "TegraK1": "10575.22.0",
615 "IntelHDGraphics615": "10575.22.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400616 }[parts["cpu_or_gpu_value"]]
617 if !ok {
618 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
619 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500620 d["gpu"] = parts["cpu_or_gpu_value"]
621 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400622 } else {
623 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500624 }
borenetdb182c72016-09-30 12:53:12 -0700625 }
626 } else {
627 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400628 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400629 if strings.Contains(parts["extra_config"], "PathKit") || strings.Contains(parts["extra_config"], "CanvasKit") {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400630 return wasmGceDimensions()
Kevin Lubickf14a3c02018-08-22 09:35:32 -0400631 }
Kevin Lubick3655e402018-10-12 16:58:52 -0400632 if parts["role"] == "BuildStats" {
633 // Doesn't require a lot of resources
634 return linuxGceDimensions(MACHINE_TYPE_MEDIUM)
635 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400636 // Use many-core machines for Build tasks.
637 return linuxGceDimensions(MACHINE_TYPE_LARGE)
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500638 } else if d["os"] == DEFAULT_OS_WIN {
639 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400640 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagnere99a4b12018-05-04 11:18:01 -0400641 // Use many-core machines for Build tasks.
642 d["machine_type"] = MACHINE_TYPE_LARGE
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500643 } else if d["os"] == DEFAULT_OS_MAC {
644 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400645 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400646 }
borenetdb182c72016-09-30 12:53:12 -0700647 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400648
borenetdb182c72016-09-30 12:53:12 -0700649 rv := make([]string, 0, len(d))
650 for k, v := range d {
651 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
652 }
653 sort.Strings(rv)
654 return rv
655}
656
Eric Boren7e3a3642017-06-14 15:25:31 -0400657// relpath returns the relative path to the given file from the config file.
658func relpath(f string) string {
659 _, filename, _, _ := runtime.Caller(0)
660 dir := path.Dir(filename)
661 rel := dir
662 if *cfgFile != "" {
663 rel = path.Dir(*cfgFile)
664 }
665 rv, err := filepath.Rel(rel, path.Join(dir, f))
666 if err != nil {
667 sklog.Fatal(err)
668 }
669 return rv
670}
671
Eric Boren8b3f9e62017-04-04 09:06:16 -0400672// bundleRecipes generates the task to bundle and isolate the recipes.
673func bundleRecipes(b *specs.TasksCfgBuilder) string {
Eric Boren63924422018-06-21 09:02:30 -0400674 pkgs := append([]*specs.CipdPackage{}, CIPD_PKGS_GIT...)
675 pkgs = append(pkgs, CIPD_PKGS_PYTHON...)
Eric Boren8b3f9e62017-04-04 09:06:16 -0400676 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren63924422018-06-21 09:02:30 -0400677 CipdPackages: pkgs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400678 Command: []string{
679 "/bin/bash", "skia/infra/bots/bundle_recipes.sh", specs.PLACEHOLDER_ISOLATED_OUTDIR,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400680 },
Ben Wagnere99a4b12018-05-04 11:18:01 -0400681 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400682 EnvPrefixes: map[string][]string{
683 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
684 },
Ben Wagnerc062b6b2018-07-24 17:10:46 -0400685 Isolate: relpath("swarm_recipe.isolate"),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400686 })
687 return BUNDLE_RECIPES_NAME
688}
689
Kevin Lubick07072942017-05-11 13:35:23 -0400690type isolateAssetCfg struct {
Eric Boren9599b0f2018-04-17 15:55:57 -0400691 cipdPkg string
692 path string
Kevin Lubick07072942017-05-11 13:35:23 -0400693}
694
695var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500696 ISOLATE_GCLOUD_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400697 cipdPkg: "gcloud_linux",
698 path: "gcloud_linux",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500699 },
Eric Boren9d834582018-08-03 14:29:03 -0400700 ISOLATE_GO_DEPS_NAME: {
701 cipdPkg: "go_deps",
702 path: "go_deps",
703 },
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500704 ISOLATE_GO_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400705 cipdPkg: "go",
706 path: "go",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500707 },
Kevin Lubick07072942017-05-11 13:35:23 -0400708 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400709 cipdPkg: "skimage",
710 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400711 },
712 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400713 cipdPkg: "skp",
714 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400715 },
716 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400717 cipdPkg: "svg",
718 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400719 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500720 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400721 cipdPkg: "android_ndk_linux",
722 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500723 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500724 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400725 cipdPkg: "android_sdk_linux",
726 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500727 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500728 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400729 cipdPkg: "win_toolchain",
730 path: "t",
Kevin Lubick814b1492017-11-29 14:45:14 -0500731 },
732 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400733 cipdPkg: "win_vulkan_sdk",
734 path: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500735 },
Kevin Lubick07072942017-05-11 13:35:23 -0400736}
737
Eric Boren9599b0f2018-04-17 15:55:57 -0400738// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400739func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400740 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400741 b.MustAddTask(name, &specs.TaskSpec{
742 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400743 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400744 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400745 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400746 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400747 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400748 })
749 return name
750}
751
Kevin Lubick90189522017-05-15 08:30:27 -0400752// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
753// This allows us to save time on I/O bound bots, like the RPIs.
754func getIsolatedCIPDDeps(parts map[string]string) []string {
755 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400756 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
757 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400758 rpiOS := []string{"Android", "ChromeOS", "iOS"}
759
760 if o := parts["os"]; strings.Contains(o, "Chromecast") {
761 // Chromecasts don't have enough disk space to fit all of the content,
762 // so we do a subset of the skps.
763 deps = append(deps, ISOLATE_SKP_NAME)
764 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
765 // Skpbench only needs skps
766 deps = append(deps, ISOLATE_SKP_NAME)
767 } else if util.In(o, rpiOS) {
768 deps = append(deps, ISOLATE_SKP_NAME)
769 deps = append(deps, ISOLATE_SVG_NAME)
770 deps = append(deps, ISOLATE_SKIMAGE_NAME)
771 }
772
773 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400774}
775
Eric Boren5cb5c742018-04-27 13:14:38 -0400776// usesGit adds attributes to tasks which use git.
777func usesGit(t *specs.TaskSpec, name string) {
778 t.Caches = append(t.Caches, CACHES_GIT...)
779 if !strings.Contains(name, "NoDEPS") {
780 t.Caches = append(t.Caches, CACHES_WORKDIR...)
781 }
782 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
783}
784
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400785// usesDocker adds attributes to tasks which use docker.
786func usesDocker(t *specs.TaskSpec, name string) {
787 // currently, just the WASM (using EMCC) builder uses Docker.
788 if strings.Contains(name, "EMCC") {
789 t.Caches = append(t.Caches, CACHES_DOCKER...)
790 }
791}
792
Eric Boren5cb5c742018-04-27 13:14:38 -0400793// timeout sets the timeout(s) for this task.
794func timeout(task *specs.TaskSpec, timeout time.Duration) {
795 task.ExecutionTimeout = timeout
796 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
797}
798
borenetdb182c72016-09-30 12:53:12 -0700799// compile generates a compile task. Returns the name of the last task in the
800// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700801func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400802 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400803 usesGit(task, name)
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400804 usesDocker(task, name)
borenetdb182c72016-09-30 12:53:12 -0700805
806 // Android bots require a toolchain.
807 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500808 if parts["extra_config"] == "Android_Framework" {
809 // Do not need a toolchain when building the
810 // Android Framework.
811 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400812 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400813 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400814 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
815 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400816 task.CipdPackages = append(task.CipdPackages, pkg)
Kevin Lubick35b87a52018-10-08 15:07:42 -0400817 } else if !strings.Contains(name, "SKQP") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400818 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
borenetdb182c72016-09-30 12:53:12 -0700819 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500820 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400821 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
822 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400823 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400824 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400825 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400826 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400827 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400828 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
829 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400830 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400831 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500832 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400833 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500834 }
Mike Klein66fec0e2018-11-07 11:27:56 -0500835 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400836 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500837 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400838 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
839 if parts["compiler"] != "GCC" {
840 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
841 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400842 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400843 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400844 if strings.Contains(name, "SwiftShader") {
845 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
846 }
Ben Wagner55a7d222018-06-28 20:41:04 -0400847 if strings.Contains(name, "OpenCL") {
848 task.CipdPackages = append(task.CipdPackages,
849 b.MustGetCipdPackageFromAsset("opencl_headers"),
850 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
851 )
852 }
Mike Klein27dcee12016-11-09 16:31:42 -0500853 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400854 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400855 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400856 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400857 }
borenetdb182c72016-09-30 12:53:12 -0700858 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400859 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700860 }
Ben Wagner30a4e3d2018-08-07 16:58:15 -0400861 if strings.Contains(name, "OpenCL") {
862 task.CipdPackages = append(task.CipdPackages,
863 b.MustGetCipdPackageFromAsset("opencl_headers"),
864 )
865 }
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400866 } else if strings.Contains(name, "Mac") {
867 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_XCODE...)
868 task.Caches = append(task.Caches, &specs.Cache{
869 Name: "xcode",
870 Path: "cache/Xcode.app",
871 })
872 if strings.Contains(name, "CommandBuffer") {
873 timeout(task, 2*time.Hour)
874 }
875 if strings.Contains(name, "MoltenVK") {
876 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("moltenvk"))
877 }
Chris Dalton2b937f52018-05-17 10:17:10 -0600878 }
879
Eric Boren2b667d62018-10-22 10:55:15 -0400880 task.MaxAttempts = 2
Ben Wagneradeb75d2018-04-19 21:48:55 -0400881
Eric Borenbd2e1f12018-04-17 11:28:46 +0000882 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400883 b.MustAddTask(name, task)
884
Eric Boren8615fe52016-12-12 14:30:12 -0500885 // All compile tasks are runnable as their own Job. Assert that the Job
886 // is listed in JOBS.
887 if !util.In(name, JOBS) {
888 glog.Fatalf("Job %q is missing from the JOBS list!", name)
889 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500890
891 // Upload the skiaserve binary only for Linux Android compile bots.
892 // See skbug.com/7399 for context.
893 if parts["configuration"] == "Release" &&
894 parts["extra_config"] == "Android" &&
895 !strings.Contains(parts["os"], "Win") &&
896 !strings.Contains(parts["os"], "Mac") {
897 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400898 task := kitchenTask(uploadName, "upload_skiaserve", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_BINARY, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren9599b0f2018-04-17 15:55:57 -0400899 task.Dependencies = append(task.Dependencies, name)
900 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500901 return uploadName
902 }
903
borenetdb182c72016-09-30 12:53:12 -0700904 return name
905}
906
907// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
908// task in the generated chain of tasks, which the Job should add as a
909// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000910func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry5a12d052018-05-15 17:19:42 -0400911 dims := []string{
912 "pool:SkiaCT",
913 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
914 }
915 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400916 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400917 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400918 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren5cb5c742018-04-27 13:14:38 -0400919 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400920 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700921 return name
922}
923
Eric Boren84ae6412018-09-27 14:55:03 -0400924// updateGoDEPS generates an UpdateGoDEPS task. Returns the name of the last
925// task in the generated chain of tasks, which the Job should add as a
926// dependency.
927func updateGoDEPS(b *specs.TasksCfgBuilder, name string) string {
928 dims := linuxGceDimensions(MACHINE_TYPE_LARGE)
929 task := kitchenTask(name, "update_go_deps", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPDATE_GO_DEPS, dims, nil, OUTPUT_NONE)
930 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
931 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
932 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
933 b.MustAddTask(name, task)
934 return name
935}
936
Eric Borenf7928b42017-07-28 07:35:28 -0400937// checkGeneratedFiles verifies that no generated SKSL files have been edited
938// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000939func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400940 task := kitchenTask(name, "check_generated_files", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400941 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400942 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400943 return name
944}
945
borenetdb182c72016-09-30 12:53:12 -0700946// housekeeper generates a Housekeeper task. Returns the name of the last task
947// in the generated chain of tasks, which the Job should add as a dependency.
Kevin Lubick37baac12018-10-09 16:25:27 -0400948func housekeeper(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400949 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400950 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400951 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9599b0f2018-04-17 15:55:57 -0400952 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700953 return name
954}
955
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500956// bookmaker generates a Bookmaker task. Returns the name of the last task
957// in the generated chain of tasks, which the Job should add as a dependency.
958func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400959 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400960 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400961 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400962 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
963 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400964 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400965 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500966 return name
967}
968
Ravi Mistry5e967422018-02-01 13:38:13 -0500969// androidFrameworkCompile generates an Android Framework Compile task. Returns
970// the name of the last task in the generated chain of tasks, which the Job
971// should add as a dependency.
972func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400973 task := kitchenTask(name, "android_compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400974 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -0400975 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400976 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500977 return name
978}
979
borenet2dbbfa52016-10-14 06:32:09 -0700980// infra generates an infra_tests task. Returns the name of the last task in the
981// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000982func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400983 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400984 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400985 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400986 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren9599b0f2018-04-17 15:55:57 -0400987 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -0700988 return name
989}
990
Kevin Lubick49688432018-10-08 13:58:47 -0400991func buildstats(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string) string {
992 task := kitchenTask(name, "compute_buildstats", "swarm_recipe.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
993 task.Dependencies = append(task.Dependencies, compileTaskName)
Kevin Lubick6ca0d8a2018-10-09 13:31:33 -0400994 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("bloaty"))
Kevin Lubick49688432018-10-08 13:58:47 -0400995 b.MustAddTask(name, task)
996
Kevin Lubick8875baf2018-10-18 13:35:04 -0400997 // Upload release results (for tracking in perf)
998 // We have some jobs that are FYI (e.g. Debug-CanvasKit)
999 if strings.Contains(name, "Release") {
1000 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
1001 extraProps := map[string]string{
1002 "gs_bucket": CONFIG.GsBucketNano,
1003 }
1004 uploadTask := kitchenTask(name, "upload_buildstats_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_NANO, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
1005 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1006 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1007 b.MustAddTask(uploadName, uploadTask)
1008 return uploadName
Kevin Lubick49688432018-10-08 13:58:47 -04001009 }
Kevin Lubick49688432018-10-08 13:58:47 -04001010
1011 return name
1012}
1013
Yuqian Li4a577af2018-01-05 11:13:43 -05001014func getParentRevisionName(compileTaskName string, parts map[string]string) string {
1015 if parts["extra_config"] == "" {
1016 return compileTaskName + "-ParentRevision"
1017 } else {
1018 return compileTaskName + "_ParentRevision"
1019 }
1020}
1021
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001022// calmbench generates a calmbench task. Returns the name of the last task in the
1023// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -04001024func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
1025 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -04001026 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001027 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
1028 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Eric Boren2b667d62018-10-22 10:55:15 -04001029 task.MaxAttempts = 2
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001030 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1031 // Specify "rack" dimension for consistent test results.
1032 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1033 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001034 if parts["os"] == "Ubuntu18" {
1035 task.Dimensions = append(task.Dimensions, "rack:2")
1036 } else {
1037 task.Dimensions = append(task.Dimensions, "rack:1")
1038 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001039 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001040 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001041
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001042 // Upload results if necessary.
1043 if strings.Contains(name, "Release") && doUpload(name) {
1044 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001045 extraProps := map[string]string{
1046 "gs_bucket": CONFIG.GsBucketCalm,
1047 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001048 uploadTask := kitchenTask(name, "upload_calmbench_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_CALMBENCH, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
Eric Boren9599b0f2018-04-17 15:55:57 -04001049 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1050 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1051 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001052 return uploadName
1053 }
1054
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001055 return name
1056}
1057
borenetdb182c72016-09-30 12:53:12 -07001058// doUpload indicates whether the given Job should upload its results.
1059func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -05001060 for _, s := range CONFIG.NoUpload {
1061 m, err := regexp.MatchString(s, name)
1062 if err != nil {
1063 glog.Fatal(err)
1064 }
1065 if m {
borenetdb182c72016-09-30 12:53:12 -07001066 return false
1067 }
1068 }
1069 return true
1070}
1071
1072// test generates a Test task. Returns the name of the last task in the
1073// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001074func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001075 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001076 if strings.Contains(name, "SKQP") {
1077 recipe = "skqp_test"
Kevin Lubick35b87a52018-10-08 15:07:42 -04001078 if strings.Contains(name, "Emulator") {
1079 recipe = "test_skqp_emulator"
1080 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001081 } else if strings.Contains(name, "OpenCL") {
1082 // TODO(dogben): Longer term we may not want this to be called a "Test" task, but until we start
1083 // running hs_bench or kx, it will be easier to fit into the current job name schema.
1084 recipe = "compute_test"
Kevin Lubick92c91712018-08-09 10:00:02 -04001085 } else if strings.Contains(name, "PathKit") {
1086 recipe = "test_pathkit"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001087 } else if strings.Contains(name, "CanvasKit") {
1088 recipe = "test_canvaskit"
Kevin Lubick82999c02018-08-28 10:52:18 -04001089 } else if strings.Contains(name, "LottieWeb") {
1090 recipe = "test_lottie_web"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001091 }
Stephan Altmüller64cc5762018-08-02 08:51:38 +02001092 extraProps := map[string]string{
1093 "gold_hashes_url": CONFIG.GoldHashesURL,
1094 }
Eric Boreneb702382018-04-19 09:36:45 -04001095 iid := internalHardwareLabel(parts)
1096 if iid != nil {
1097 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
1098 }
Kevin Lubick92c91712018-08-09 10:00:02 -04001099 isolate := "test_skia_bundled.isolate"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001100 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "Emulator") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick92c91712018-08-09 10:00:02 -04001101 isolate = "swarm_recipe.isolate"
1102 }
1103 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -04001104 task.CipdPackages = append(task.CipdPackages, pkgs...)
Eric Boren8c172ba2018-07-19 13:27:49 -04001105 if strings.Contains(name, "Lottie") {
1106 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("lottie-samples"))
1107 }
Kevin Lubick82999c02018-08-28 10:52:18 -04001108 if !strings.Contains(name, "LottieWeb") {
1109 // Test.+LottieWeb doesn't require anything in Skia to be compiled.
1110 task.Dependencies = append(task.Dependencies, compileTaskName)
1111 }
1112
Eric Boren9599b0f2018-04-17 15:55:57 -04001113 if strings.Contains(name, "Android_ASAN") {
1114 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +00001115 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001116 if strings.Contains(name, "SKQP") {
Kevin Lubick35b87a52018-10-08 15:07:42 -04001117 if !strings.Contains(name, "Emulator") {
1118 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
1119 }
Eric Boren8b3f9e62017-04-04 09:06:16 -04001120 }
Kevin Lubick90189522017-05-15 08:30:27 -04001121 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001122 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -04001123 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001124 task.Expiration = 20 * time.Hour
Eric Boren2b667d62018-10-22 10:55:15 -04001125 task.MaxAttempts = 2
Eric Boren5cb5c742018-04-27 13:14:38 -04001126 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001127 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001128 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001129 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001130 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1131 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001132 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001133 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001134 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1135 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001136 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001137 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001138 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001139
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001140 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
1141 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -07001142 if doUpload(name) {
1143 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001144 extraProps := map[string]string{
1145 "gs_bucket": CONFIG.GsBucketGm,
1146 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001147 uploadTask := kitchenTask(name, "upload_dm_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_GM, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
Eric Boren9599b0f2018-04-17 15:55:57 -04001148 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1149 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1150 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001151 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001152 }
1153
1154 return name
1155}
1156
borenetdb182c72016-09-30 12:53:12 -07001157// perf generates a Perf task. Returns the name of the last task in the
1158// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001159func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001160 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001161 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001162 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001163 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001164 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubick556350d2018-10-12 15:21:17 -04001165 } else if strings.Contains(name, "PathKit") {
1166 recipe = "perf_pathkit"
Kevin Lubickf2a146c2018-10-17 14:59:35 -04001167 } else if strings.Contains(name, "CanvasKit") {
1168 recipe = "perf_canvaskit"
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001169 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001170 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1171 task.CipdPackages = append(task.CipdPackages, pkgs...)
1172 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001173 task.Expiration = 20 * time.Hour
Eric Boren2b667d62018-10-22 10:55:15 -04001174 task.MaxAttempts = 2
Eric Boren5cb5c742018-04-27 13:14:38 -04001175 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001176 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001177 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001178 }
1179
Eric Boren4b254b92016-11-08 12:55:32 -05001180 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001181 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001182 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001183 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1184 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001185 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001186 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001187 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1188 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001189 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001190 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001191 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001192 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001193 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001194 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001195 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1196 // Specify "rack" dimension for consistent test results.
1197 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1198 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001199 if parts["os"] == "Ubuntu18" {
1200 task.Dimensions = append(task.Dimensions, "rack:2")
1201 } else {
1202 task.Dimensions = append(task.Dimensions, "rack:1")
1203 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001204 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001205 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001206
borenetdb182c72016-09-30 12:53:12 -07001207 // Upload results if necessary.
1208 if strings.Contains(name, "Release") && doUpload(name) {
1209 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001210 extraProps := map[string]string{
1211 "gs_bucket": CONFIG.GsBucketNano,
1212 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001213 uploadTask := kitchenTask(name, "upload_nano_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_NANO, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
Eric Boren9599b0f2018-04-17 15:55:57 -04001214 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1215 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1216 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001217 return uploadName
1218 }
1219 return name
1220}
1221
Eric Borenb66099b2018-04-25 15:09:22 -04001222// Run the presubmit.
1223func presubmit(b *specs.TasksCfgBuilder, name string) string {
1224 extraProps := map[string]string{
1225 "category": "cq",
1226 "patch_gerrit_url": "https://skia-review.googlesource.com",
1227 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001228 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001229 "reason": "CQ",
1230 "repo_name": "skia",
1231 }
Ben Wagner297e86b2018-05-14 12:38:09 -04001232 // Use MACHINE_TYPE_LARGE because it seems to save time versus MEDIUM and we want presubmit to be
1233 // fast.
Ben Wagnere99a4b12018-05-04 11:18:01 -04001234 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001235
1236 replaceArg := func(key, value string) {
1237 found := false
1238 for idx, arg := range task.Command {
1239 if arg == key {
1240 task.Command[idx+1] = value
1241 found = true
1242 }
1243 }
1244 if !found {
1245 task.Command = append(task.Command, key, value)
1246 }
1247 }
1248 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1249 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001250 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001251 task.Dependencies = []string{} // No bundled recipes for this one.
1252 b.MustAddTask(name, task)
1253 return name
1254}
1255
borenetdb182c72016-09-30 12:53:12 -07001256// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001257func process(b *specs.TasksCfgBuilder, name string) {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001258 var priority float64 // Leave as default for most jobs.
borenetdb182c72016-09-30 12:53:12 -07001259 deps := []string{}
1260
Eric Boren8b3f9e62017-04-04 09:06:16 -04001261 // Bundle Recipes.
1262 if name == BUNDLE_RECIPES_NAME {
1263 deps = append(deps, bundleRecipes(b))
1264 }
1265
Kevin Lubick07072942017-05-11 13:35:23 -04001266 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001267 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1268 deps = append(deps, isolateCIPDAsset(b, name))
1269 }
1270
borenetdb182c72016-09-30 12:53:12 -07001271 parts, err := jobNameSchema.ParseJobName(name)
1272 if err != nil {
1273 glog.Fatal(err)
1274 }
1275
1276 // RecreateSKPs.
1277 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001278 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001279 }
1280
Eric Boren84ae6412018-09-27 14:55:03 -04001281 // Update Go DEPS.
1282 if strings.Contains(name, "UpdateGoDEPS") {
1283 deps = append(deps, updateGoDEPS(b, name))
1284 }
1285
borenet2dbbfa52016-10-14 06:32:09 -07001286 // Infra tests.
1287 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001288 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001289 }
1290
borenetdb182c72016-09-30 12:53:12 -07001291 // Compile bots.
1292 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001293 if parts["extra_config"] == "Android_Framework" {
1294 // Android Framework compile tasks use a different recipe.
1295 deps = append(deps, androidFrameworkCompile(b, name))
1296 } else {
1297 deps = append(deps, compile(b, name, parts))
1298 }
borenetdb182c72016-09-30 12:53:12 -07001299 }
1300
Eric Borenf5a90e82016-11-15 15:18:20 -05001301 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001302 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001303 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1304 if err != nil {
1305 glog.Fatal(err)
1306 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001307 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1308 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1309 if err != nil {
1310 glog.Fatal(err)
1311 }
1312
Eric Boren628e78b2016-11-17 11:33:27 -05001313 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001314 if parts["role"] != "Build" &&
Eric Boren84ae6412018-09-27 14:55:03 -04001315 name != "Housekeeper-Nightly-UpdateGoDEPS" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001316 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001317 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001318 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001319 name != "Housekeeper-OnDemand-Presubmit" &&
Kevin Lubick37baac12018-10-09 16:25:27 -04001320 name != "Housekeeper-PerCommit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001321 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001322 !strings.Contains(name, "RecreateSKPs") &&
Kevin Lubick82999c02018-08-28 10:52:18 -04001323 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") &&
1324 !strings.Contains(name, "LottieWeb") {
boreneted20a702016-10-20 11:04:31 -07001325 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001326 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001327 compile(b, compileParentName, compileParentParts)
1328 }
borenet52383432016-10-17 10:17:53 -07001329 }
borenetdb182c72016-09-30 12:53:12 -07001330
Eric Borenf7928b42017-07-28 07:35:28 -04001331 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001332 if name == "Housekeeper-PerCommit" {
Kevin Lubick37baac12018-10-09 16:25:27 -04001333 deps = append(deps, housekeeper(b, name))
borenetdb182c72016-09-30 12:53:12 -07001334 }
Eric Borenf7928b42017-07-28 07:35:28 -04001335 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001336 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001337 }
Eric Borenb66099b2018-04-25 15:09:22 -04001338 if name == "Housekeeper-OnDemand-Presubmit" {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001339 priority = 1
Eric Borenb66099b2018-04-25 15:09:22 -04001340 deps = append(deps, presubmit(b, name))
1341 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001342 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001343 deps = append(deps, bookmaker(b, name, compileTaskName))
1344 }
borenetdb182c72016-09-30 12:53:12 -07001345
1346 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001347
1348 pkgs := []*specs.CipdPackage{}
1349
Kevin Lubick90189522017-05-15 08:30:27 -04001350 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001351 pkgs = []*specs.CipdPackage{
1352 b.MustGetCipdPackageFromAsset("skimage"),
1353 b.MustGetCipdPackageFromAsset("skp"),
1354 b.MustGetCipdPackageFromAsset("svg"),
1355 }
borenetdb182c72016-09-30 12:53:12 -07001356 }
Kevin Lubick90189522017-05-15 08:30:27 -04001357
Ben Wagner5655ba42017-10-02 10:48:32 -04001358 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1359 if strings.Contains(name, "SAN") {
1360 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1361 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001362 if strings.Contains(name, "Vulkan") {
1363 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1364 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001365 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
Kevin Lubick1b5ece02018-09-11 17:09:28 -04001366 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("mesa_intel_driver_linux"))
Kevin Lubick0a51b482017-02-06 12:45:29 -05001367 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001368 if strings.Contains(name, "OpenCL") {
1369 pkgs = append(pkgs,
1370 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
1371 b.MustGetCipdPackageFromAsset("opencl_intel_neo_linux"),
1372 )
1373 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001374 }
Ben Wagner299b8822018-03-09 13:42:56 -05001375 if strings.Contains(name, "ProcDump") {
1376 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1377 }
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001378 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick82999c02018-08-28 10:52:18 -04001379 // Docker-based tests that don't need the standard CIPD assets
Kevin Lubick92c91712018-08-09 10:00:02 -04001380 pkgs = []*specs.CipdPackage{}
1381 }
borenetdb182c72016-09-30 12:53:12 -07001382
1383 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001384 if parts["role"] == "Test" {
Ravi Mistryeea245c2018-10-09 10:31:11 -04001385 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001386 }
1387
1388 // Perf bots.
Ravi Mistryeea245c2018-10-09 10:31:11 -04001389 if parts["role"] == "Perf" {
boreneted20a702016-10-20 11:04:31 -07001390 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001391 }
1392
Yuqian Li4a577af2018-01-05 11:13:43 -05001393 // Calmbench bots.
1394 if parts["role"] == "Calmbench" {
1395 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1396 }
1397
Kevin Lubick49688432018-10-08 13:58:47 -04001398 // BuildStats bots. This computes things like binary size.
1399 if parts["role"] == "BuildStats" {
1400 deps = append(deps, buildstats(b, name, parts, compileTaskName))
1401 }
1402
borenetdb182c72016-09-30 12:53:12 -07001403 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001404 j := &specs.JobSpec{
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001405 Priority: priority,
borenetdb182c72016-09-30 12:53:12 -07001406 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001407 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001408 }
Eric Borenba937a42017-07-31 10:41:15 -04001409 if strings.Contains(name, "-Nightly-") {
1410 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryeea245c2018-10-09 10:31:11 -04001411 } else if strings.Contains(name, "-Weekly-") {
Eric Borenba937a42017-07-31 10:41:15 -04001412 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001413 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001414 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001415 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001416 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001417 }
Eric Boren8615fe52016-12-12 14:30:12 -05001418 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001419}
1420
Eric Boren27225492017-02-01 15:56:55 -05001421func loadJson(flag *string, defaultFlag string, val interface{}) {
1422 if *flag == "" {
1423 *flag = defaultFlag
1424 }
1425 b, err := ioutil.ReadFile(*flag)
1426 if err != nil {
1427 glog.Fatal(err)
1428 }
1429 if err := json.Unmarshal(b, val); err != nil {
1430 glog.Fatal(err)
1431 }
1432}
1433
borenetdb182c72016-09-30 12:53:12 -07001434// Regenerate the tasks.json file.
1435func main() {
boreneted20a702016-10-20 11:04:31 -07001436 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001437 b.SetAssetsDir(*assetsDir)
1438 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1439
1440 // Load the jobs from a JSON file.
1441 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1442
Eric Boren27225492017-02-01 15:56:55 -05001443 // Load general config information from a JSON file.
1444 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1445
borenetdb182c72016-09-30 12:53:12 -07001446 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001447 if *builderNameSchemaFile == "" {
1448 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1449 }
1450 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001451 if err != nil {
1452 glog.Fatal(err)
1453 }
1454 jobNameSchema = schema
1455
borenetdb182c72016-09-30 12:53:12 -07001456 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001457 for _, name := range JOBS {
1458 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001459 }
1460
boreneted20a702016-10-20 11:04:31 -07001461 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001462}
1463
1464// TODO(borenet): The below really belongs in its own file, probably next to the
1465// builder_name_schema.json file.
1466
Eric Boren8ff86a62018-04-17 14:11:23 -04001467// schema is a sub-struct of JobNameSchema.
1468type schema struct {
1469 Keys []string `json:"keys"`
1470 OptionalKeys []string `json:"optional_keys"`
1471 RecurseRoles []string `json:"recurse_roles"`
1472}
1473
borenetdb182c72016-09-30 12:53:12 -07001474// JobNameSchema is a struct used for (de)constructing Job names in a
1475// predictable format.
1476type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001477 Schema map[string]*schema `json:"builder_name_schema"`
1478 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001479}
1480
1481// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1482// file.
1483func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1484 var rv JobNameSchema
1485 f, err := os.Open(jsonFile)
1486 if err != nil {
1487 return nil, err
1488 }
1489 defer util.Close(f)
1490 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1491 return nil, err
1492 }
1493 return &rv, nil
1494}
1495
1496// ParseJobName splits the given Job name into its component parts, according
1497// to the schema.
1498func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001499 popFront := func(items []string) (string, []string, error) {
1500 if len(items) == 0 {
1501 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1502 }
1503 return items[0], items[1:], nil
1504 }
1505
1506 result := map[string]string{}
1507
1508 var parse func(int, string, []string) ([]string, error)
1509 parse = func(depth int, role string, parts []string) ([]string, error) {
1510 s, ok := s.Schema[role]
1511 if !ok {
1512 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1513 }
1514 if depth == 0 {
1515 result["role"] = role
1516 } else {
1517 result[fmt.Sprintf("sub-role-%d", depth)] = role
1518 }
1519 var err error
1520 for _, key := range s.Keys {
1521 var value string
1522 value, parts, err = popFront(parts)
1523 if err != nil {
1524 return nil, err
1525 }
1526 result[key] = value
1527 }
1528 for _, subRole := range s.RecurseRoles {
1529 if len(parts) > 0 && parts[0] == subRole {
1530 parts, err = parse(depth+1, parts[0], parts[1:])
1531 if err != nil {
1532 return nil, err
1533 }
1534 }
1535 }
1536 for _, key := range s.OptionalKeys {
1537 if len(parts) > 0 {
1538 var value string
1539 value, parts, err = popFront(parts)
1540 if err != nil {
1541 return nil, err
1542 }
1543 result[key] = value
1544 }
1545 }
1546 if len(parts) > 0 {
1547 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1548 }
1549 return parts, nil
1550 }
1551
borenetdb182c72016-09-30 12:53:12 -07001552 split := strings.Split(n, s.Sep)
1553 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001554 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001555 }
1556 role := split[0]
1557 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001558 _, err := parse(0, role, split)
1559 return result, err
borenetdb182c72016-09-30 12:53:12 -07001560}
1561
1562// MakeJobName assembles the given parts of a Job name, according to the schema.
1563func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001564 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001565
1566 var process func(int, map[string]string) (map[string]string, error)
1567 process = func(depth int, parts map[string]string) (map[string]string, error) {
1568 roleKey := "role"
1569 if depth != 0 {
1570 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001571 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001572 role, ok := parts[roleKey]
1573 if !ok {
1574 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1575 }
1576
1577 s, ok := s.Schema[role]
1578 if !ok {
1579 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1580 }
1581 rvParts = append(rvParts, role)
1582 delete(parts, roleKey)
1583
1584 for _, key := range s.Keys {
1585 value, ok := parts[key]
1586 if !ok {
1587 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1588 }
1589 rvParts = append(rvParts, value)
1590 delete(parts, key)
1591 }
1592
1593 if len(s.RecurseRoles) > 0 {
1594 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1595 subRole, ok := parts[subRoleKey]
1596 if !ok {
1597 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1598 }
1599 rvParts = append(rvParts, subRole)
1600 delete(parts, subRoleKey)
1601 found := false
1602 for _, recurseRole := range s.RecurseRoles {
1603 if recurseRole == subRole {
1604 found = true
1605 var err error
1606 parts, err = process(depth+1, parts)
1607 if err != nil {
1608 return nil, err
1609 }
1610 break
1611 }
1612 }
1613 if !found {
1614 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1615 }
1616 }
1617 for _, key := range s.OptionalKeys {
1618 if value, ok := parts[key]; ok {
1619 rvParts = append(rvParts, value)
1620 delete(parts, key)
1621 }
1622 }
1623 if len(parts) > 0 {
1624 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1625 }
1626 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001627 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001628
1629 // Copy the parts map, so that we can modify at will.
1630 partsCpy := make(map[string]string, len(parts))
1631 for k, v := range parts {
1632 partsCpy[k] = v
1633 }
1634 if _, err := process(0, partsCpy); err != nil {
1635 return "", err
borenetdb182c72016-09-30 12:53:12 -07001636 }
1637 return strings.Join(rvParts, s.Sep), nil
1638}