blob: 39073aba389e7dba865e54a2814452e14652b096 [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 (
Ben Wagner1cefc092019-01-04 11:36:53 -050033 BUNDLE_RECIPES_NAME = "Housekeeper-PerCommit-BundleRecipes"
34 ISOLATE_GCLOUD_LINUX_NAME = "Housekeeper-PerCommit-IsolateGCloudLinux"
35 ISOLATE_GO_DEPS_NAME = "Housekeeper-PerCommit-IsolateGoDeps"
36 ISOLATE_SKIMAGE_NAME = "Housekeeper-PerCommit-IsolateSkImage"
37 ISOLATE_SKP_NAME = "Housekeeper-PerCommit-IsolateSKP"
38 ISOLATE_SVG_NAME = "Housekeeper-PerCommit-IsolateSVG"
39 ISOLATE_NDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidNDKLinux"
40 ISOLATE_SDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidSDKLinux"
41 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
Eric Boren8b3f9e62017-04-04 09:06:16 -040042
Ben Wagner1676ec22018-04-06 17:39:06 -040043 DEFAULT_OS_DEBIAN = "Debian-9.4"
44 DEFAULT_OS_LINUX_GCE = DEFAULT_OS_DEBIAN
Ben Wagnere8d2a452018-08-06 10:00:54 -040045 DEFAULT_OS_MAC = "Mac-10.13.6"
Eric Boren170c39c2017-11-15 11:22:57 -050046 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
47 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070048
Eric Boreneb702382018-04-19 09:36:45 -040049 DEFAULT_PROJECT = "skia"
50
Ben Wagner297e86b2018-05-14 12:38:09 -040051 // Small is a 2-core machine.
52 // TODO(dogben): Would n1-standard-1 or n1-standard-2 be sufficient?
Ben Wagnere99a4b12018-05-04 11:18:01 -040053 MACHINE_TYPE_SMALL = "n1-highmem-2"
Ben Wagner297e86b2018-05-14 12:38:09 -040054 // Medium is a 16-core machine
55 MACHINE_TYPE_MEDIUM = "n1-standard-16"
56 // Large is a 64-core machine. (We use "highcpu" because we don't need more than 57GB memory for
57 // any of our tasks.)
Ben Wagnere99a4b12018-05-04 11:18:01 -040058 MACHINE_TYPE_LARGE = "n1-highcpu-64"
59
Eric Boren9599b0f2018-04-17 15:55:57 -040060 // Swarming output dirs.
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040061 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
62 OUTPUT_BUILD = "build"
63 OUTPUT_TEST = "test"
64 OUTPUT_PERF = "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -040065
borenetdb182c72016-09-30 12:53:12 -070066 // Name prefix for upload jobs.
67 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040068
69 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
70 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040071 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
72 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren84ae6412018-09-27 14:55:03 -040073 SERVICE_ACCOUNT_UPDATE_GO_DEPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040074 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
75 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
76 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040077 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
78 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070079)
80
81var (
82 // "Constants"
83
Eric Boren27225492017-02-01 15:56:55 -050084 // Top-level list of all jobs to run at each commit; loaded from
85 // jobs.json.
86 JOBS []string
87
Eric Boren27225492017-02-01 15:56:55 -050088 // General configuration information.
89 CONFIG struct {
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040090 GsBucketGm string `json:"gs_bucket_gm"`
91 GoldHashesURL string `json:"gold_hashes_url"`
92 GsBucketNano string `json:"gs_bucket_nano"`
93 GsBucketCalm string `json:"gs_bucket_calm"`
94 NoUpload []string `json:"no_upload"`
95 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070096 }
97
Eric Boreneb702382018-04-19 09:36:45 -040098 // alternateProject can be set in an init function to override the default project ID.
99 alternateProject string
100
Ben Wagner053d0462018-04-17 12:45:29 -0400101 // alternateServiceAccount can be set in an init function to override the normal service accounts.
102 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
103 // should be used, or uses sklog.Fatal to indicate a problem.
104 alternateServiceAccount func(serviceAccountEnum string) string
105
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400106 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
107 // dimensions for the given task.
108 alternateSwarmDimensions func(parts map[string]string) []string
109
Eric Borenfd4d60e2017-09-15 10:35:44 -0400110 // internalHardwareLabelFn can be set in an init function to provide an
111 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400112 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400113
borenetdb182c72016-09-30 12:53:12 -0700114 // Defines the structure of job names.
115 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500116
Eric Boren5cb5c742018-04-27 13:14:38 -0400117 // Named caches used by tasks.
118 CACHES_GIT = []*specs.Cache{
119 &specs.Cache{
120 Name: "git",
121 Path: "cache/git",
122 },
123 &specs.Cache{
124 Name: "git_cache",
125 Path: "cache/git_cache",
126 },
127 }
Ben Wagnerbb7d3812018-12-18 23:42:11 -0500128 CACHES_GO = []*specs.Cache{
129 &specs.Cache{
130 Name: "go_cache",
131 Path: "cache/go_cache",
132 },
133 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400134 CACHES_WORKDIR = []*specs.Cache{
135 &specs.Cache{
136 Name: "work",
137 Path: "cache/work",
138 },
139 }
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400140 CACHES_DOCKER = []*specs.Cache{
141 &specs.Cache{
142 Name: "docker",
143 Path: "cache/docker",
144 },
145 }
Ben Wagner702fe012018-06-15 09:19:13 -0400146 // Versions of the following copied from
147 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template_canary.json#42
148 // to test the fix for chromium:836196.
149 // (In the future we may want to use versions from
150 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template.json#42)
Eric Boren9599b0f2018-04-17 15:55:57 -0400151 // TODO(borenet): Roll these versions automatically!
152 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
153 &specs.CipdPackage{
154 Name: "infra/tools/luci/vpython/${platform}",
155 Path: "cipd_bin_packages",
Eric Borenb33f9eb2018-08-03 10:31:24 -0400156 Version: "git_revision:b6cdec8586c9f8d3d728b1bc0bd4331330ba66fc",
Eric Boren9599b0f2018-04-17 15:55:57 -0400157 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400158 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400159
Eric Borenaa037522018-06-18 16:02:15 -0400160 CIPD_PKGS_CPYTHON = []*specs.CipdPackage{
161 &specs.CipdPackage{
162 Name: "infra/python/cpython/${platform}",
163 Path: "cipd_bin_packages",
164 Version: "version:2.7.14.chromium14",
165 },
166 }
167
Eric Boren9599b0f2018-04-17 15:55:57 -0400168 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
169 &specs.CipdPackage{
170 Name: "infra/tools/luci/kitchen/${platform}",
171 Path: ".",
Eric Borenccb0a302019-01-10 08:34:11 -0500172 Version: "git_revision:074bb031426a238dd38b67314312d334d9d13ae7",
Eric Boren9599b0f2018-04-17 15:55:57 -0400173 },
174 &specs.CipdPackage{
Ben Wagnercd7ace22018-06-11 15:48:35 -0400175 Name: "infra/tools/luci-auth/${platform}",
Eric Boren9599b0f2018-04-17 15:55:57 -0400176 Path: "cipd_bin_packages",
Eric Borenccb0a302019-01-10 08:34:11 -0500177 Version: "git_revision:2c805f1c716f6c5ad2126b27ec88b8585a09481e",
Eric Boren9599b0f2018-04-17 15:55:57 -0400178 },
179 }, CIPD_PKGS_PYTHON...)
180
181 CIPD_PKGS_GIT = []*specs.CipdPackage{
182 &specs.CipdPackage{
183 Name: "infra/git/${platform}",
184 Path: "cipd_bin_packages",
Eric Borene42cef52018-06-20 07:11:38 -0400185 Version: "version:2.17.1.chromium15",
Eric Boren9599b0f2018-04-17 15:55:57 -0400186 },
187 &specs.CipdPackage{
188 Name: "infra/tools/git/${platform}",
189 Path: "cipd_bin_packages",
Eric Borenccb0a302019-01-10 08:34:11 -0500190 Version: "git_revision:c9c8a52bfeaf8bc00ece22fdfd447822c8fcad77",
Eric Boren9599b0f2018-04-17 15:55:57 -0400191 },
192 &specs.CipdPackage{
193 Name: "infra/tools/luci/git-credential-luci/${platform}",
194 Path: "cipd_bin_packages",
Eric Borenccb0a302019-01-10 08:34:11 -0500195 Version: "git_revision:2c805f1c716f6c5ad2126b27ec88b8585a09481e",
Eric Boren9599b0f2018-04-17 15:55:57 -0400196 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000197 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400198
Eric Boren9599b0f2018-04-17 15:55:57 -0400199 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
200 &specs.CipdPackage{
201 Name: "infra/gsutil",
202 Path: "cipd_bin_packages",
203 Version: "version:4.28",
204 },
205 }
206
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400207 CIPD_PKGS_XCODE = []*specs.CipdPackage{
208 // https://chromium.googlesource.com/chromium/tools/build/+/e19b7d9390e2bb438b566515b141ed2b9ed2c7c2/scripts/slave/recipe_modules/ios/api.py#317
209 // This package is really just an installer for XCode.
210 &specs.CipdPackage{
Ben Wagner66760792018-08-09 12:52:16 -0400211 Name: "infra/tools/mac_toolchain/${platform}",
212 Path: "mac_toolchain",
213 // When this is updated, also update
214 // https://skia.googlesource.com/skcms.git/+/f1e2b45d18facbae2dece3aca673fe1603077846/infra/bots/gen_tasks.go#56
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400215 Version: "git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a",
216 },
217 }
218
Eric Boren27225492017-02-01 15:56:55 -0500219 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500220 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.")
221 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
222 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500223 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700224)
225
Eric Boreneb702382018-04-19 09:36:45 -0400226// Build the LogDog annotation URL.
227func logdogAnnotationUrl() string {
228 project := DEFAULT_PROJECT
229 if alternateProject != "" {
230 project = alternateProject
231 }
232 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
233}
234
Eric Boren9599b0f2018-04-17 15:55:57 -0400235// Create a properties JSON string.
236func props(p map[string]string) string {
237 d := make(map[string]interface{}, len(p)+1)
238 for k, v := range p {
239 d[k] = interface{}(v)
240 }
241 d["$kitchen"] = struct {
242 DevShell bool `json:"devshell"`
243 GitAuth bool `json:"git_auth"`
244 }{
245 DevShell: true,
246 GitAuth: true,
247 }
248
249 j, err := json.Marshal(d)
250 if err != nil {
251 sklog.Fatal(err)
252 }
253 return strings.Replace(string(j), "\\u003c", "<", -1)
254}
255
256// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
257// recipe.
258func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
259 if serviceAccount != "" && alternateServiceAccount != nil {
260 serviceAccount = alternateServiceAccount(serviceAccount)
261 }
262 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
Eric Borenaa037522018-06-18 16:02:15 -0400263 if strings.Contains(name, "Win") {
264 cipd = append(cipd, CIPD_PKGS_CPYTHON...)
265 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400266 properties := map[string]string{
267 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
268 "buildername": name,
269 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400270 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400271 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
272 "patch_set": specs.PLACEHOLDER_PATCHSET,
273 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
274 "repository": specs.PLACEHOLDER_REPO,
275 "revision": specs.PLACEHOLDER_REVISION,
276 "swarm_out_dir": outputDir,
277 }
278 for k, v := range extraProps {
279 properties[k] = v
280 }
281 var outputs []string = nil
282 if outputDir != OUTPUT_NONE {
283 outputs = []string{outputDir}
284 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400285 task := &specs.TaskSpec{
286 Caches: []*specs.Cache{
287 &specs.Cache{
288 Name: "vpython",
289 Path: "cache/vpython",
290 },
291 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400292 CipdPackages: cipd,
293 Command: []string{
294 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
295 "-checkout-dir", "recipe_bundle",
296 "-mode", "swarming",
297 "-luci-system-account", "system",
298 "-cache-dir", "cache",
299 "-temp-dir", "tmp",
300 "-known-gerrit-host", "android.googlesource.com",
301 "-known-gerrit-host", "boringssl.googlesource.com",
302 "-known-gerrit-host", "chromium.googlesource.com",
303 "-known-gerrit-host", "dart.googlesource.com",
304 "-known-gerrit-host", "fuchsia.googlesource.com",
305 "-known-gerrit-host", "go.googlesource.com",
306 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400307 "-known-gerrit-host", "skia.googlesource.com",
308 "-known-gerrit-host", "webrtc.googlesource.com",
309 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
310 "-workdir", ".",
311 "-recipe", recipe,
312 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400313 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400314 },
315 Dependencies: []string{BUNDLE_RECIPES_NAME},
316 Dimensions: dimensions,
317 EnvPrefixes: map[string][]string{
Kevin Lubick37baac12018-10-09 16:25:27 -0400318 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
Eric Boren7c42e012018-08-20 09:45:02 -0400319 "VPYTHON_VIRTUALENV_ROOT": []string{"cache/vpython"},
Eric Boren9599b0f2018-04-17 15:55:57 -0400320 },
321 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400322 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400323 },
324 Isolate: relpath(isolate),
Ben Wagner73e2ced2018-12-17 12:44:30 -0500325 MaxAttempts: attempts(name),
Eric Boren9599b0f2018-04-17 15:55:57 -0400326 Outputs: outputs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400327 ServiceAccount: serviceAccount,
328 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400329 timeout(task, time.Hour)
330 return task
Eric Boren9599b0f2018-04-17 15:55:57 -0400331}
332
Eric Borenfd4d60e2017-09-15 10:35:44 -0400333// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400334func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400335 if internalHardwareLabelFn != nil {
336 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400337 }
338 return nil
339}
340
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400341// linuxGceDimensions are the Swarming dimensions for Linux GCE instances.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400342func linuxGceDimensions(machineType string) []string {
Eric Boren27225492017-02-01 15:56:55 -0500343 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400344 // Specify CPU to avoid running builds on bots with a more unique CPU.
345 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500346 "gpu:none",
Ben Wagner82a33422018-04-26 18:02:23 -0400347 // Currently all Linux GCE tasks run on 16-CPU machines.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400348 fmt.Sprintf("machine_type:%s", machineType),
Eric Boren170c39c2017-11-15 11:22:57 -0500349 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500350 fmt.Sprintf("pool:%s", CONFIG.Pool),
351 }
352}
353
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400354func wasmGceDimensions() []string {
355 // There's limited parallelism for WASM builds, so we can get away with the medium
356 // instance instead of the beefy large instance.
357 // Docker being intsalled is the most important part.
358 return append(linuxGceDimensions(MACHINE_TYPE_MEDIUM), "docker_installed:true")
359}
360
borenetdb182c72016-09-30 12:53:12 -0700361// deriveCompileTaskName returns the name of a compile task based on the given
362// job name.
363func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500364 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500365 return "Build-Debian9-GCC-x86_64-Release"
Yuqian Li4a577af2018-01-05 11:13:43 -0500366 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700367 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400368 ec := []string{}
369 if val := parts["extra_config"]; val != "" {
370 ec = strings.Split(val, "_")
Mike Kleinc24e0c12018-08-17 13:24:51 -0400371 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 -0400372 keep := make([]string, 0, len(ec))
373 for _, part := range ec {
374 if !util.In(part, ignore) {
375 keep = append(keep, part)
376 }
377 }
378 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400379 }
borenetdb182c72016-09-30 12:53:12 -0700380 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400381 if !util.In("Android", ec) {
382 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700383 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400384 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500385 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400386 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400387 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400388 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400389 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400390 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700391 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400392 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700393 task_os = "Mac"
394 } else if strings.Contains(task_os, "Win") {
395 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400396 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
397 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700398 }
Eric Boren50831302016-11-18 13:10:51 -0500399 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700400 "role": "Build",
401 "os": task_os,
402 "compiler": parts["compiler"],
403 "target_arch": parts["arch"],
404 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500405 }
Kevin Lubick92c91712018-08-09 10:00:02 -0400406 if strings.Contains(jobName, "PathKit") {
407 ec = []string{"PathKit"}
408 }
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400409 if strings.Contains(jobName, "CanvasKit") {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400410 if parts["cpu_or_gpu"] == "CPU" {
411 ec = []string{"CanvasKit_CPU"}
412 } else {
413 ec = []string{"CanvasKit"}
414 }
415
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400416 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400417 if len(ec) > 0 {
418 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500419 }
420 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700421 if err != nil {
422 glog.Fatal(err)
423 }
424 return name
Kevin Lubick49688432018-10-08 13:58:47 -0400425 } else if parts["role"] == "BuildStats" {
426 return strings.Replace(jobName, "BuildStats", "Build", 1)
borenetdb182c72016-09-30 12:53:12 -0700427 } else {
428 return jobName
429 }
430}
431
432// swarmDimensions generates swarming bot dimensions for the given task.
433func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400434 if alternateSwarmDimensions != nil {
435 return alternateSwarmDimensions(parts)
436 }
437 return defaultSwarmDimensions(parts)
438}
439
440// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
441func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700442 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500443 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700444 }
445 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400446 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400447 "Android": "Android",
448 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400449 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400450 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500451 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400452 "Ubuntu14": DEFAULT_OS_UBUNTU,
Eric Boren810c2b62017-07-11 08:11:15 -0400453 "Ubuntu17": "Ubuntu-17.04",
Ben Wagner2aa9a222018-11-06 13:45:40 -0500454 "Ubuntu18": "Ubuntu-18.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500455 "Win": DEFAULT_OS_WIN,
Ben Wagnerb62fc902019-01-03 15:50:55 -0500456 "Win10": "Windows-10-17763.195",
Kevin Lubick291547d2017-03-21 09:25:34 -0400457 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500458 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400459 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400460 "Win8": "Windows-8.1-SP0",
Stephan Altmueller0edb9822018-08-16 18:11:57 -0400461 "iOS": "iOS-11.4.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500462 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400463 if !ok {
464 glog.Fatalf("Entry %q not found in OS mapping.", os)
465 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500466 if os == "Win10" && parts["model"] == "Golo" {
Ben Wagnerf6148b62018-03-15 13:53:25 -0400467 // ChOps-owned machines have Windows 10 v1709, but a slightly different version than Skolo.
468 d["os"] = "Windows-10-16299.309"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500469 }
Ben Wagnere1c37a72018-04-24 16:59:48 -0400470 if d["os"] == DEFAULT_OS_WIN {
471 // TODO(dogben): Temporarily add image dimension during upgrade.
Ben Wagner7a879622018-07-18 10:14:23 -0400472 d["image"] = "windows-server-2016-dc-v20180710"
Ben Wagnere1c37a72018-04-24 16:59:48 -0400473 }
borenetdb182c72016-09-30 12:53:12 -0700474 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400475 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700476 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400477 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400478 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700479 // For Android, the device type is a better dimension
480 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400481 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400482 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500483 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500484 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagner17d18962018-09-13 15:05:15 -0400485 "GalaxyS7_G930FD": {"herolte", "R16NW_G930FXXS2ERH6"}, // This is Oreo.
Ben Wagner9e972312018-11-29 10:00:36 -0500486 "GalaxyS9": {"starlte", "R16NW_G960FXXU2BRJ8"}, // This is Oreo.
Ben Wagner8d8f45d2018-06-04 17:32:04 -0400487 "MotoG4": {"athene", "NPJS25.93-14.7-8"},
Ben Wagner7efa13d2018-08-28 15:52:38 -0400488 "NVIDIA_Shield": {"foster", "OPR6.170623.010"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500489 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500490 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500491 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner2a510c92018-04-11 12:36:56 -0400492 "NexusPlayer": {"fugu", "OPR2.170623.027"},
Kevin Lubick8fe1b042018-08-21 13:00:14 -0400493 "Pixel": {"sailfish", "PPR1.180610.009"},
Kevin Lubick1118cfd2018-08-24 10:24:54 -0400494 "Pixel2XL": {"taimen", "PPR1.180610.009"},
Ben Wagner36682782017-06-14 10:01:45 -0400495 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500496 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400497 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500498 }
Eric Boren4b254b92016-11-08 12:55:32 -0500499 d["device_type"] = deviceInfo[0]
500 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700501 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400502 device, ok := map[string]string{
Eric Boren792079cf2016-11-09 14:03:20 -0500503 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400504 "iPhone6": "iPhone7,2",
505 "iPhone7": "iPhone9,1",
506 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700507 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400508 if !ok {
509 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
510 }
511 d["device"] = device
Ben Wagnerd26e4462018-05-22 10:46:15 -0400512 } else if strings.Contains(parts["extra_config"], "SwiftShader") {
513 if parts["model"] != "GCE" || d["os"] != DEFAULT_OS_DEBIAN || parts["cpu_or_gpu_value"] != "SwiftShader" {
514 glog.Fatalf("Please update defaultSwarmDimensions for SwiftShader %s %s %s.", parts["os"], parts["model"], parts["cpu_or_gpu_value"])
515 }
516 d["cpu"] = "x86-64-Haswell_GCE"
517 d["os"] = DEFAULT_OS_LINUX_GCE
518 d["machine_type"] = MACHINE_TYPE_SMALL
Kevin Lubick35b87a52018-10-08 15:07:42 -0400519 } else if strings.Contains(parts["extra_config"], "SKQP") && parts["cpu_or_gpu_value"] == "Emulator" {
520 if parts["model"] != "NUC7i5BNK" || d["os"] != DEFAULT_OS_DEBIAN {
521 glog.Fatalf("Please update defaultSwarmDimensions for SKQP::Emulator %s %s.", parts["os"], parts["model"])
522 }
523 d["cpu"] = "x86-64-i5-7260U"
524 d["os"] = "Debian-9.4"
525 // KVM means Kernel-based Virtual Machine, that is, can this vm virtualize commands
526 // For us, this means, can we run an x86 android emulator on it.
527 // kjlubick tried running this on GCE, but it was a bit too slow on the large install.
528 // So, we run on bare metal machines in the Skolo (that should also have KVM).
529 d["kvm"] = "1"
530 d["docker_installed"] = "true"
borenetdb182c72016-09-30 12:53:12 -0700531 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400532 modelMapping, ok := map[string]map[string]string{
533 "AVX": {
Ben Wagner7ea54282018-08-22 14:07:48 -0400534 "Golo": "x86-64-E5-2670",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400535 },
536 "AVX2": {
Ben Wagner35eb7fa2018-08-06 11:27:17 -0400537 "GCE": "x86-64-Haswell_GCE",
538 "MacBookPro11.5": "x86-64-i7-4870HQ",
539 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400540 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400541 "AVX512": {
542 "GCE": "x86-64-Skylake_GCE",
543 },
borenetdb182c72016-09-30 12:53:12 -0700544 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400545 if !ok {
546 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
547 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400548 cpu, ok := modelMapping[parts["model"]]
549 if !ok {
550 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700551 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400552 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500553 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
554 d["os"] = DEFAULT_OS_LINUX_GCE
555 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400556 if parts["model"] == "GCE" && d["cpu"] == "x86-64-Haswell_GCE" {
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -0400557 d["machine_type"] = MACHINE_TYPE_MEDIUM
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500558 }
borenetdb182c72016-09-30 12:53:12 -0700559 } else {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400560 if strings.Contains(parts["extra_config"], "CanvasKit") {
561 // GPU is defined for the WebGL version of CanvasKit, but
562 // it can still run on a GCE instance.
563 return wasmGceDimensions()
564 } else if strings.Contains(parts["os"], "Win") {
Ben Wagner1d060782017-06-14 10:34:18 -0400565 gpu, ok := map[string]string{
Ben Wagnerf6148b62018-03-15 13:53:25 -0400566 "GT610": "10de:104a-23.21.13.9101",
Ben Wagnerf713dd12018-10-26 14:09:52 -0400567 "GTX660": "10de:11c0-25.21.14.1634",
568 "GTX960": "10de:1401-25.21.14.1634",
Greg Daniel900e5c82018-08-28 10:59:24 -0400569 "IntelHD4400": "8086:0a16-20.19.15.4963",
Ben Wagner7b069fa2018-12-03 13:02:01 -0500570 "IntelIris540": "8086:1926-25.20.100.6444",
Greg Daniel900e5c82018-08-28 10:59:24 -0400571 "IntelIris6100": "8086:162b-20.19.15.4963",
Ben Wagnerb73cb3f2019-01-04 13:18:10 -0500572 "IntelIris655": "8086:3ea5-25.20.100.6444",
Ben Wagner1f0fb092018-08-27 18:09:52 -0400573 "RadeonHD7770": "1002:683d-24.20.13001.1010",
574 "RadeonR9M470X": "1002:6646-24.20.13001.1010",
Ben Wagnerce7a16b2018-11-14 21:16:00 -0500575 "QuadroP400": "10de:1cb3-25.21.14.1678",
Ben Wagner1d060782017-06-14 10:34:18 -0400576 }[parts["cpu_or_gpu_value"]]
577 if !ok {
578 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
579 }
580 d["gpu"] = gpu
Eric Borenbb198fb2017-06-28 11:45:54 -0400581 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400582 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400583 // Intel drivers come from CIPD, so no need to specify the version here.
584 "IntelBayTrail": "8086:0f31",
585 "IntelHD2000": "8086:0102",
586 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500587 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400588 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400589 }[parts["cpu_or_gpu_value"]]
590 if !ok {
591 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
592 }
Ben Wagner2aa9a222018-11-06 13:45:40 -0500593 if parts["os"] == "Ubuntu18" && parts["cpu_or_gpu_value"] == "QuadroP400" {
594 // Ubuntu18 has a slightly newer GPU driver.
595 gpu = "10de:1cb3-390.87"
596 }
Ben Wagner1d060782017-06-14 10:34:18 -0400597 d["gpu"] = gpu
598 } else if strings.Contains(parts["os"], "Mac") {
599 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500600 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500601 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400602 "IntelIris5100": "8086:0a2e",
Ben Wagnereeeb3282018-05-15 16:45:42 -0400603 "RadeonHD8870M": "1002:6821-4.0.20-3.2.8",
Ben Wagner1d060782017-06-14 10:34:18 -0400604 }[parts["cpu_or_gpu_value"]]
605 if !ok {
606 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
607 }
608 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500609 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
610 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
611 // Run all tasks on Golo machines for now.
612 d["cpu"] = "x86-64-i7-4578U"
613 }
Ben Wagner1d060782017-06-14 10:34:18 -0400614 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500615 version, ok := map[string]string{
Kevin Lubickff8387f2018-05-01 10:43:35 -0400616 "MaliT604": "10575.22.0",
Kevin Lubicke114e592018-05-01 08:53:52 -0400617 "MaliT764": "10575.22.0",
Kevin Lubicke467d4e2018-05-01 13:12:58 -0400618 "MaliT860": "10575.22.0",
619 "PowerVRGX6250": "10575.22.0",
620 "TegraK1": "10575.22.0",
621 "IntelHDGraphics615": "10575.22.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400622 }[parts["cpu_or_gpu_value"]]
623 if !ok {
624 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
625 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500626 d["gpu"] = parts["cpu_or_gpu_value"]
627 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400628 } else {
629 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500630 }
borenetdb182c72016-09-30 12:53:12 -0700631 }
632 } else {
633 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400634 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubick8e9750d2018-10-09 09:36:35 -0400635 if strings.Contains(parts["extra_config"], "PathKit") || strings.Contains(parts["extra_config"], "CanvasKit") {
Kevin Lubick3d99b1e2018-10-16 10:15:01 -0400636 return wasmGceDimensions()
Kevin Lubickf14a3c02018-08-22 09:35:32 -0400637 }
Kevin Lubick3655e402018-10-12 16:58:52 -0400638 if parts["role"] == "BuildStats" {
639 // Doesn't require a lot of resources
640 return linuxGceDimensions(MACHINE_TYPE_MEDIUM)
641 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400642 // Use many-core machines for Build tasks.
643 return linuxGceDimensions(MACHINE_TYPE_LARGE)
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500644 } else if d["os"] == DEFAULT_OS_WIN {
645 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400646 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagnere99a4b12018-05-04 11:18:01 -0400647 // Use many-core machines for Build tasks.
648 d["machine_type"] = MACHINE_TYPE_LARGE
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500649 } else if d["os"] == DEFAULT_OS_MAC {
650 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400651 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400652 }
borenetdb182c72016-09-30 12:53:12 -0700653 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400654
borenetdb182c72016-09-30 12:53:12 -0700655 rv := make([]string, 0, len(d))
656 for k, v := range d {
657 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
658 }
659 sort.Strings(rv)
660 return rv
661}
662
Eric Boren7e3a3642017-06-14 15:25:31 -0400663// relpath returns the relative path to the given file from the config file.
664func relpath(f string) string {
665 _, filename, _, _ := runtime.Caller(0)
666 dir := path.Dir(filename)
667 rel := dir
668 if *cfgFile != "" {
669 rel = path.Dir(*cfgFile)
670 }
671 rv, err := filepath.Rel(rel, path.Join(dir, f))
672 if err != nil {
673 sklog.Fatal(err)
674 }
675 return rv
676}
677
Eric Boren8b3f9e62017-04-04 09:06:16 -0400678// bundleRecipes generates the task to bundle and isolate the recipes.
679func bundleRecipes(b *specs.TasksCfgBuilder) string {
Eric Boren63924422018-06-21 09:02:30 -0400680 pkgs := append([]*specs.CipdPackage{}, CIPD_PKGS_GIT...)
681 pkgs = append(pkgs, CIPD_PKGS_PYTHON...)
Eric Boren8b3f9e62017-04-04 09:06:16 -0400682 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren63924422018-06-21 09:02:30 -0400683 CipdPackages: pkgs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400684 Command: []string{
685 "/bin/bash", "skia/infra/bots/bundle_recipes.sh", specs.PLACEHOLDER_ISOLATED_OUTDIR,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400686 },
Ben Wagnere99a4b12018-05-04 11:18:01 -0400687 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400688 EnvPrefixes: map[string][]string{
689 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
690 },
Ben Wagnerc062b6b2018-07-24 17:10:46 -0400691 Isolate: relpath("swarm_recipe.isolate"),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400692 })
693 return BUNDLE_RECIPES_NAME
694}
695
Kevin Lubick07072942017-05-11 13:35:23 -0400696type isolateAssetCfg struct {
Eric Boren9599b0f2018-04-17 15:55:57 -0400697 cipdPkg string
698 path string
Kevin Lubick07072942017-05-11 13:35:23 -0400699}
700
701var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500702 ISOLATE_GCLOUD_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400703 cipdPkg: "gcloud_linux",
704 path: "gcloud_linux",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500705 },
Eric Boren9d834582018-08-03 14:29:03 -0400706 ISOLATE_GO_DEPS_NAME: {
707 cipdPkg: "go_deps",
708 path: "go_deps",
709 },
Kevin Lubick07072942017-05-11 13:35:23 -0400710 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400711 cipdPkg: "skimage",
712 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400713 },
714 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400715 cipdPkg: "skp",
716 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400717 },
718 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400719 cipdPkg: "svg",
720 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400721 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500722 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400723 cipdPkg: "android_ndk_linux",
724 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500725 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500726 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400727 cipdPkg: "android_sdk_linux",
728 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500729 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500730 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400731 cipdPkg: "win_toolchain",
Brian Osmanef3d04e2018-12-12 13:28:09 -0500732 path: "win_toolchain",
Kevin Lubick814b1492017-11-29 14:45:14 -0500733 },
Kevin Lubick07072942017-05-11 13:35:23 -0400734}
735
Eric Boren9599b0f2018-04-17 15:55:57 -0400736// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400737func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400738 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400739 b.MustAddTask(name, &specs.TaskSpec{
740 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400741 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400742 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400743 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400744 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400745 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400746 })
747 return name
748}
749
Kevin Lubick90189522017-05-15 08:30:27 -0400750// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
751// This allows us to save time on I/O bound bots, like the RPIs.
752func getIsolatedCIPDDeps(parts map[string]string) []string {
753 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400754 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
755 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400756 rpiOS := []string{"Android", "ChromeOS", "iOS"}
757
758 if o := parts["os"]; strings.Contains(o, "Chromecast") {
759 // Chromecasts don't have enough disk space to fit all of the content,
760 // so we do a subset of the skps.
761 deps = append(deps, ISOLATE_SKP_NAME)
762 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
763 // Skpbench only needs skps
764 deps = append(deps, ISOLATE_SKP_NAME)
765 } else if util.In(o, rpiOS) {
766 deps = append(deps, ISOLATE_SKP_NAME)
767 deps = append(deps, ISOLATE_SVG_NAME)
768 deps = append(deps, ISOLATE_SKIMAGE_NAME)
769 }
770
771 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400772}
773
Eric Boren5cb5c742018-04-27 13:14:38 -0400774// usesGit adds attributes to tasks which use git.
775func usesGit(t *specs.TaskSpec, name string) {
776 t.Caches = append(t.Caches, CACHES_GIT...)
777 if !strings.Contains(name, "NoDEPS") {
778 t.Caches = append(t.Caches, CACHES_WORKDIR...)
779 }
780 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
781}
782
Ben Wagnerbb7d3812018-12-18 23:42:11 -0500783// usesGo adds attributes to tasks which use go. Recipes should use
784// "with api.context(env=api.infra.go_env)".
785// (Not needed for tasks that just want to run Go code from the infra repo -- instead use go_deps.)
786func usesGo(b *specs.TasksCfgBuilder, t *specs.TaskSpec) {
787 t.Caches = append(t.Caches, CACHES_GO...)
788 t.CipdPackages = append(t.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
789 t.Dependencies = append(t.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
790}
791
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400792// usesDocker adds attributes to tasks which use docker.
793func usesDocker(t *specs.TaskSpec, name string) {
Kevin Lubick40654f22019-01-02 09:50:19 -0500794 if strings.Contains(name, "EMCC") || strings.Contains(name, "SKQP") || strings.Contains(name, "LottieWeb") {
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400795 t.Caches = append(t.Caches, CACHES_DOCKER...)
796 }
797}
798
Eric Boren5cb5c742018-04-27 13:14:38 -0400799// timeout sets the timeout(s) for this task.
800func timeout(task *specs.TaskSpec, timeout time.Duration) {
801 task.ExecutionTimeout = timeout
802 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
803}
804
Ben Wagner73e2ced2018-12-17 12:44:30 -0500805// attempts returns the desired MaxAttempts for this task.
806func attempts(name string) int {
807 if strings.Contains(name, "Android_Framework") {
808 // The reason for this has been lost to time.
809 return 1
810 }
811 if !(strings.HasPrefix(name, "Build-") || strings.HasPrefix(name, "Upload-")) {
812 for _, extraConfig := range []string{"ASAN", "MSAN", "TSAN", "UBSAN", "Valgrind"} {
813 if strings.Contains(name, extraConfig) {
814 // Sanitizers often find non-deterministic issues that retries would hide.
815 return 1
816 }
817 }
818 }
819 // Retry by default to hide random bot/hardware failures.
820 return 2
821}
822
borenetdb182c72016-09-30 12:53:12 -0700823// compile generates a compile task. Returns the name of the last task in the
824// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700825func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400826 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400827 usesGit(task, name)
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400828 usesDocker(task, name)
borenetdb182c72016-09-30 12:53:12 -0700829
830 // Android bots require a toolchain.
831 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500832 if parts["extra_config"] == "Android_Framework" {
833 // Do not need a toolchain when building the
834 // Android Framework.
835 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400836 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400837 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400838 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
839 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400840 task.CipdPackages = append(task.CipdPackages, pkg)
Kevin Lubick35b87a52018-10-08 15:07:42 -0400841 } else if !strings.Contains(name, "SKQP") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400842 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
borenetdb182c72016-09-30 12:53:12 -0700843 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500844 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400845 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
846 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400847 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400848 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400849 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400850 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400851 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400852 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
853 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400854 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400855 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500856 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400857 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500858 }
Mike Klein66fec0e2018-11-07 11:27:56 -0500859 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400860 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500861 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400862 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
863 if parts["compiler"] != "GCC" {
864 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
865 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400866 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400867 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400868 if strings.Contains(name, "SwiftShader") {
869 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
870 }
Ben Wagner55a7d222018-06-28 20:41:04 -0400871 if strings.Contains(name, "OpenCL") {
872 task.CipdPackages = append(task.CipdPackages,
873 b.MustGetCipdPackageFromAsset("opencl_headers"),
874 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
875 )
876 }
Mike Klein27dcee12016-11-09 16:31:42 -0500877 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400878 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400879 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400880 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400881 }
Ben Wagner30a4e3d2018-08-07 16:58:15 -0400882 if strings.Contains(name, "OpenCL") {
883 task.CipdPackages = append(task.CipdPackages,
884 b.MustGetCipdPackageFromAsset("opencl_headers"),
885 )
886 }
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400887 } else if strings.Contains(name, "Mac") {
888 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_XCODE...)
889 task.Caches = append(task.Caches, &specs.Cache{
890 Name: "xcode",
891 Path: "cache/Xcode.app",
892 })
893 if strings.Contains(name, "CommandBuffer") {
894 timeout(task, 2*time.Hour)
895 }
896 if strings.Contains(name, "MoltenVK") {
897 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("moltenvk"))
898 }
Chris Dalton2b937f52018-05-17 10:17:10 -0600899 }
900
Eric Borenbd2e1f12018-04-17 11:28:46 +0000901 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400902 b.MustAddTask(name, task)
903
Eric Boren8615fe52016-12-12 14:30:12 -0500904 // All compile tasks are runnable as their own Job. Assert that the Job
905 // is listed in JOBS.
906 if !util.In(name, JOBS) {
907 glog.Fatalf("Job %q is missing from the JOBS list!", name)
908 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500909
910 // Upload the skiaserve binary only for Linux Android compile bots.
911 // See skbug.com/7399 for context.
912 if parts["configuration"] == "Release" &&
913 parts["extra_config"] == "Android" &&
914 !strings.Contains(parts["os"], "Win") &&
915 !strings.Contains(parts["os"], "Mac") {
916 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400917 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 -0400918 task.Dependencies = append(task.Dependencies, name)
919 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500920 return uploadName
921 }
922
borenetdb182c72016-09-30 12:53:12 -0700923 return name
924}
925
926// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
927// task in the generated chain of tasks, which the Job should add as a
928// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000929func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry5a12d052018-05-15 17:19:42 -0400930 dims := []string{
931 "pool:SkiaCT",
932 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
933 }
934 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400935 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Ben Wagnerbb7d3812018-12-18 23:42:11 -0500936 usesGo(b, task)
Eric Boren5cb5c742018-04-27 13:14:38 -0400937 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400938 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700939 return name
940}
941
Eric Boren84ae6412018-09-27 14:55:03 -0400942// updateGoDEPS generates an UpdateGoDEPS task. Returns the name of the last
943// task in the generated chain of tasks, which the Job should add as a
944// dependency.
945func updateGoDEPS(b *specs.TasksCfgBuilder, name string) string {
946 dims := linuxGceDimensions(MACHINE_TYPE_LARGE)
947 task := kitchenTask(name, "update_go_deps", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPDATE_GO_DEPS, dims, nil, OUTPUT_NONE)
948 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Ben Wagnerbb7d3812018-12-18 23:42:11 -0500949 usesGo(b, task)
Eric Boren84ae6412018-09-27 14:55:03 -0400950 b.MustAddTask(name, task)
951 return name
952}
953
Eric Borenf7928b42017-07-28 07:35:28 -0400954// checkGeneratedFiles verifies that no generated SKSL files have been edited
955// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000956func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400957 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 -0400958 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400959 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400960 return name
961}
962
borenetdb182c72016-09-30 12:53:12 -0700963// housekeeper generates a Housekeeper task. Returns the name of the last task
964// in the generated chain of tasks, which the Job should add as a dependency.
Kevin Lubick37baac12018-10-09 16:25:27 -0400965func housekeeper(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400966 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400967 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400968 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700969 return name
970}
971
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500972// bookmaker generates a Bookmaker task. Returns the name of the last task
973// in the generated chain of tasks, which the Job should add as a dependency.
974func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400975 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400976 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400977 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Ben Wagner43588022018-12-18 23:16:07 -0500978 task.Dependencies = append(task.Dependencies, compileTaskName, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren5cb5c742018-04-27 13:14:38 -0400979 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400980 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500981 return name
982}
983
Ravi Mistry5e967422018-02-01 13:38:13 -0500984// androidFrameworkCompile generates an Android Framework Compile task. Returns
985// the name of the last task in the generated chain of tasks, which the Job
986// should add as a dependency.
987func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400988 task := kitchenTask(name, "android_compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400989 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400990 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500991 return name
992}
993
borenet2dbbfa52016-10-14 06:32:09 -0700994// infra generates an infra_tests task. Returns the name of the last task in the
995// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000996func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400997 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400998 usesGit(task, name)
Ben Wagnerbb7d3812018-12-18 23:42:11 -0500999 usesGo(b, task)
Eric Boren9599b0f2018-04-17 15:55:57 -04001000 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -07001001 return name
1002}
1003
Kevin Lubick49688432018-10-08 13:58:47 -04001004func buildstats(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string) string {
1005 task := kitchenTask(name, "compute_buildstats", "swarm_recipe.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
1006 task.Dependencies = append(task.Dependencies, compileTaskName)
Kevin Lubick6ca0d8a2018-10-09 13:31:33 -04001007 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("bloaty"))
Kevin Lubick49688432018-10-08 13:58:47 -04001008 b.MustAddTask(name, task)
1009
Kevin Lubick8875baf2018-10-18 13:35:04 -04001010 // Upload release results (for tracking in perf)
1011 // We have some jobs that are FYI (e.g. Debug-CanvasKit)
1012 if strings.Contains(name, "Release") {
1013 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
1014 extraProps := map[string]string{
1015 "gs_bucket": CONFIG.GsBucketNano,
1016 }
1017 uploadTask := kitchenTask(name, "upload_buildstats_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_NANO, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
1018 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1019 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1020 b.MustAddTask(uploadName, uploadTask)
1021 return uploadName
Kevin Lubick49688432018-10-08 13:58:47 -04001022 }
Kevin Lubick49688432018-10-08 13:58:47 -04001023
1024 return name
1025}
1026
Yuqian Li4a577af2018-01-05 11:13:43 -05001027func getParentRevisionName(compileTaskName string, parts map[string]string) string {
1028 if parts["extra_config"] == "" {
1029 return compileTaskName + "-ParentRevision"
1030 } else {
1031 return compileTaskName + "_ParentRevision"
1032 }
1033}
1034
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001035// calmbench generates a calmbench task. Returns the name of the last task in the
1036// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -04001037func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
1038 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -04001039 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001040 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001041 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1042 // Specify "rack" dimension for consistent test results.
1043 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1044 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001045 if parts["os"] == "Ubuntu18" {
1046 task.Dimensions = append(task.Dimensions, "rack:2")
1047 } else {
1048 task.Dimensions = append(task.Dimensions, "rack:1")
1049 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001050 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001051 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001052
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001053 // Upload results if necessary.
1054 if strings.Contains(name, "Release") && doUpload(name) {
1055 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001056 extraProps := map[string]string{
1057 "gs_bucket": CONFIG.GsBucketCalm,
1058 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001059 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 -04001060 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1061 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1062 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001063 return uploadName
1064 }
1065
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001066 return name
1067}
1068
borenetdb182c72016-09-30 12:53:12 -07001069// doUpload indicates whether the given Job should upload its results.
1070func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -05001071 for _, s := range CONFIG.NoUpload {
1072 m, err := regexp.MatchString(s, name)
1073 if err != nil {
1074 glog.Fatal(err)
1075 }
1076 if m {
borenetdb182c72016-09-30 12:53:12 -07001077 return false
1078 }
1079 }
1080 return true
1081}
1082
1083// test generates a Test task. Returns the name of the last task in the
1084// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001085func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001086 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001087 if strings.Contains(name, "SKQP") {
1088 recipe = "skqp_test"
Kevin Lubick35b87a52018-10-08 15:07:42 -04001089 if strings.Contains(name, "Emulator") {
1090 recipe = "test_skqp_emulator"
1091 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001092 } else if strings.Contains(name, "OpenCL") {
1093 // TODO(dogben): Longer term we may not want this to be called a "Test" task, but until we start
1094 // running hs_bench or kx, it will be easier to fit into the current job name schema.
1095 recipe = "compute_test"
Kevin Lubick92c91712018-08-09 10:00:02 -04001096 } else if strings.Contains(name, "PathKit") {
1097 recipe = "test_pathkit"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001098 } else if strings.Contains(name, "CanvasKit") {
1099 recipe = "test_canvaskit"
Kevin Lubick82999c02018-08-28 10:52:18 -04001100 } else if strings.Contains(name, "LottieWeb") {
1101 recipe = "test_lottie_web"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001102 }
Stephan Altmüller64cc5762018-08-02 08:51:38 +02001103 extraProps := map[string]string{
1104 "gold_hashes_url": CONFIG.GoldHashesURL,
1105 }
Eric Boreneb702382018-04-19 09:36:45 -04001106 iid := internalHardwareLabel(parts)
1107 if iid != nil {
1108 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
1109 }
Kevin Lubick92c91712018-08-09 10:00:02 -04001110 isolate := "test_skia_bundled.isolate"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001111 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "Emulator") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick92c91712018-08-09 10:00:02 -04001112 isolate = "swarm_recipe.isolate"
1113 }
1114 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -04001115 task.CipdPackages = append(task.CipdPackages, pkgs...)
Eric Boren8c172ba2018-07-19 13:27:49 -04001116 if strings.Contains(name, "Lottie") {
1117 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("lottie-samples"))
1118 }
Kevin Lubick82999c02018-08-28 10:52:18 -04001119 if !strings.Contains(name, "LottieWeb") {
1120 // Test.+LottieWeb doesn't require anything in Skia to be compiled.
1121 task.Dependencies = append(task.Dependencies, compileTaskName)
1122 }
1123
Eric Boren9599b0f2018-04-17 15:55:57 -04001124 if strings.Contains(name, "Android_ASAN") {
1125 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +00001126 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001127 if strings.Contains(name, "SKQP") {
Kevin Lubick35b87a52018-10-08 15:07:42 -04001128 if !strings.Contains(name, "Emulator") {
1129 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
1130 }
Eric Boren8b3f9e62017-04-04 09:06:16 -04001131 }
Kevin Lubick90189522017-05-15 08:30:27 -04001132 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001133 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -04001134 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001135 task.Expiration = 20 * time.Hour
Ben Wagner73e2ced2018-12-17 12:44:30 -05001136
Eric Boren5cb5c742018-04-27 13:14:38 -04001137 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001138 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001139 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001140 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001141 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1142 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001143 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001144 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001145 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1146 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001147 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001148 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001149 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001150
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001151 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
1152 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -07001153 if doUpload(name) {
1154 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001155 extraProps := map[string]string{
1156 "gs_bucket": CONFIG.GsBucketGm,
1157 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001158 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 -04001159 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1160 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1161 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001162 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001163 }
1164
1165 return name
1166}
1167
borenetdb182c72016-09-30 12:53:12 -07001168// perf generates a Perf task. Returns the name of the last task in the
1169// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001170func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001171 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001172 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001173 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001174 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001175 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubick556350d2018-10-12 15:21:17 -04001176 } else if strings.Contains(name, "PathKit") {
1177 recipe = "perf_pathkit"
Kevin Lubickf2a146c2018-10-17 14:59:35 -04001178 } else if strings.Contains(name, "CanvasKit") {
1179 recipe = "perf_canvaskit"
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001180 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001181 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1182 task.CipdPackages = append(task.CipdPackages, pkgs...)
1183 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001184 task.Expiration = 20 * time.Hour
Eric Boren5cb5c742018-04-27 13:14:38 -04001185 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001186 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001187 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001188 }
1189
Eric Boren4b254b92016-11-08 12:55:32 -05001190 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001191 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001192 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001193 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1194 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001195 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001196 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001197 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1198 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001199 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001200 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001201 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001202 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001203 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001204 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001205 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1206 // Specify "rack" dimension for consistent test results.
1207 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1208 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001209 if parts["os"] == "Ubuntu18" {
1210 task.Dimensions = append(task.Dimensions, "rack:2")
1211 } else {
1212 task.Dimensions = append(task.Dimensions, "rack:1")
1213 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001214 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001215 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001216
borenetdb182c72016-09-30 12:53:12 -07001217 // Upload results if necessary.
1218 if strings.Contains(name, "Release") && doUpload(name) {
1219 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001220 extraProps := map[string]string{
1221 "gs_bucket": CONFIG.GsBucketNano,
1222 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001223 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 -04001224 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1225 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1226 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001227 return uploadName
1228 }
1229 return name
1230}
1231
Eric Borenb66099b2018-04-25 15:09:22 -04001232// Run the presubmit.
1233func presubmit(b *specs.TasksCfgBuilder, name string) string {
1234 extraProps := map[string]string{
1235 "category": "cq",
1236 "patch_gerrit_url": "https://skia-review.googlesource.com",
1237 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001238 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001239 "reason": "CQ",
1240 "repo_name": "skia",
1241 }
Ben Wagner297e86b2018-05-14 12:38:09 -04001242 // Use MACHINE_TYPE_LARGE because it seems to save time versus MEDIUM and we want presubmit to be
1243 // fast.
Ben Wagnere99a4b12018-05-04 11:18:01 -04001244 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001245
1246 replaceArg := func(key, value string) {
1247 found := false
1248 for idx, arg := range task.Command {
1249 if arg == key {
1250 task.Command[idx+1] = value
1251 found = true
1252 }
1253 }
1254 if !found {
1255 task.Command = append(task.Command, key, value)
1256 }
1257 }
1258 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1259 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001260 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001261 task.Dependencies = []string{} // No bundled recipes for this one.
1262 b.MustAddTask(name, task)
1263 return name
1264}
1265
borenetdb182c72016-09-30 12:53:12 -07001266// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001267func process(b *specs.TasksCfgBuilder, name string) {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001268 var priority float64 // Leave as default for most jobs.
borenetdb182c72016-09-30 12:53:12 -07001269 deps := []string{}
1270
Eric Boren8b3f9e62017-04-04 09:06:16 -04001271 // Bundle Recipes.
1272 if name == BUNDLE_RECIPES_NAME {
1273 deps = append(deps, bundleRecipes(b))
1274 }
1275
Kevin Lubick07072942017-05-11 13:35:23 -04001276 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001277 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1278 deps = append(deps, isolateCIPDAsset(b, name))
1279 }
1280
borenetdb182c72016-09-30 12:53:12 -07001281 parts, err := jobNameSchema.ParseJobName(name)
1282 if err != nil {
1283 glog.Fatal(err)
1284 }
1285
1286 // RecreateSKPs.
1287 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001288 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001289 }
1290
Eric Boren84ae6412018-09-27 14:55:03 -04001291 // Update Go DEPS.
1292 if strings.Contains(name, "UpdateGoDEPS") {
1293 deps = append(deps, updateGoDEPS(b, name))
1294 }
1295
borenet2dbbfa52016-10-14 06:32:09 -07001296 // Infra tests.
1297 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001298 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001299 }
1300
borenetdb182c72016-09-30 12:53:12 -07001301 // Compile bots.
1302 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001303 if parts["extra_config"] == "Android_Framework" {
1304 // Android Framework compile tasks use a different recipe.
1305 deps = append(deps, androidFrameworkCompile(b, name))
1306 } else {
1307 deps = append(deps, compile(b, name, parts))
1308 }
borenetdb182c72016-09-30 12:53:12 -07001309 }
1310
Eric Borenf5a90e82016-11-15 15:18:20 -05001311 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001312 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001313 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1314 if err != nil {
1315 glog.Fatal(err)
1316 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001317 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1318 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1319 if err != nil {
1320 glog.Fatal(err)
1321 }
1322
Eric Boren628e78b2016-11-17 11:33:27 -05001323 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001324 if parts["role"] != "Build" &&
Eric Boren84ae6412018-09-27 14:55:03 -04001325 name != "Housekeeper-Nightly-UpdateGoDEPS" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001326 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001327 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001328 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001329 name != "Housekeeper-OnDemand-Presubmit" &&
Kevin Lubick37baac12018-10-09 16:25:27 -04001330 name != "Housekeeper-PerCommit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001331 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001332 !strings.Contains(name, "RecreateSKPs") &&
Kevin Lubick82999c02018-08-28 10:52:18 -04001333 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") &&
1334 !strings.Contains(name, "LottieWeb") {
boreneted20a702016-10-20 11:04:31 -07001335 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001336 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001337 compile(b, compileParentName, compileParentParts)
1338 }
borenet52383432016-10-17 10:17:53 -07001339 }
borenetdb182c72016-09-30 12:53:12 -07001340
Eric Borenf7928b42017-07-28 07:35:28 -04001341 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001342 if name == "Housekeeper-PerCommit" {
Kevin Lubick37baac12018-10-09 16:25:27 -04001343 deps = append(deps, housekeeper(b, name))
borenetdb182c72016-09-30 12:53:12 -07001344 }
Eric Borenf7928b42017-07-28 07:35:28 -04001345 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001346 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001347 }
Eric Borenb66099b2018-04-25 15:09:22 -04001348 if name == "Housekeeper-OnDemand-Presubmit" {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001349 priority = 1
Eric Borenb66099b2018-04-25 15:09:22 -04001350 deps = append(deps, presubmit(b, name))
1351 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001352 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001353 deps = append(deps, bookmaker(b, name, compileTaskName))
1354 }
borenetdb182c72016-09-30 12:53:12 -07001355
1356 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001357
1358 pkgs := []*specs.CipdPackage{}
1359
Kevin Lubick90189522017-05-15 08:30:27 -04001360 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001361 pkgs = []*specs.CipdPackage{
1362 b.MustGetCipdPackageFromAsset("skimage"),
1363 b.MustGetCipdPackageFromAsset("skp"),
1364 b.MustGetCipdPackageFromAsset("svg"),
1365 }
borenetdb182c72016-09-30 12:53:12 -07001366 }
Kevin Lubick90189522017-05-15 08:30:27 -04001367
Ben Wagner5655ba42017-10-02 10:48:32 -04001368 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1369 if strings.Contains(name, "SAN") {
1370 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1371 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001372 if strings.Contains(name, "Vulkan") {
1373 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1374 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001375 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
Kevin Lubick1b5ece02018-09-11 17:09:28 -04001376 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("mesa_intel_driver_linux"))
Kevin Lubick0a51b482017-02-06 12:45:29 -05001377 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001378 if strings.Contains(name, "OpenCL") {
1379 pkgs = append(pkgs,
1380 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
1381 b.MustGetCipdPackageFromAsset("opencl_intel_neo_linux"),
1382 )
1383 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001384 }
Ben Wagner299b8822018-03-09 13:42:56 -05001385 if strings.Contains(name, "ProcDump") {
1386 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1387 }
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001388 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick82999c02018-08-28 10:52:18 -04001389 // Docker-based tests that don't need the standard CIPD assets
Kevin Lubick92c91712018-08-09 10:00:02 -04001390 pkgs = []*specs.CipdPackage{}
1391 }
borenetdb182c72016-09-30 12:53:12 -07001392
1393 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001394 if parts["role"] == "Test" {
Ravi Mistryeea245c2018-10-09 10:31:11 -04001395 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001396 }
1397
1398 // Perf bots.
Ravi Mistryeea245c2018-10-09 10:31:11 -04001399 if parts["role"] == "Perf" {
boreneted20a702016-10-20 11:04:31 -07001400 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001401 }
1402
Yuqian Li4a577af2018-01-05 11:13:43 -05001403 // Calmbench bots.
1404 if parts["role"] == "Calmbench" {
1405 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1406 }
1407
Kevin Lubick49688432018-10-08 13:58:47 -04001408 // BuildStats bots. This computes things like binary size.
1409 if parts["role"] == "BuildStats" {
1410 deps = append(deps, buildstats(b, name, parts, compileTaskName))
1411 }
1412
borenetdb182c72016-09-30 12:53:12 -07001413 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001414 j := &specs.JobSpec{
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001415 Priority: priority,
borenetdb182c72016-09-30 12:53:12 -07001416 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001417 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001418 }
Eric Borenba937a42017-07-31 10:41:15 -04001419 if strings.Contains(name, "-Nightly-") {
1420 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryeea245c2018-10-09 10:31:11 -04001421 } else if strings.Contains(name, "-Weekly-") {
Eric Borenba937a42017-07-31 10:41:15 -04001422 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001423 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001424 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001425 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001426 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001427 }
Eric Boren8615fe52016-12-12 14:30:12 -05001428 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001429}
1430
Eric Boren27225492017-02-01 15:56:55 -05001431func loadJson(flag *string, defaultFlag string, val interface{}) {
1432 if *flag == "" {
1433 *flag = defaultFlag
1434 }
1435 b, err := ioutil.ReadFile(*flag)
1436 if err != nil {
1437 glog.Fatal(err)
1438 }
1439 if err := json.Unmarshal(b, val); err != nil {
1440 glog.Fatal(err)
1441 }
1442}
1443
borenetdb182c72016-09-30 12:53:12 -07001444// Regenerate the tasks.json file.
1445func main() {
boreneted20a702016-10-20 11:04:31 -07001446 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001447 b.SetAssetsDir(*assetsDir)
1448 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1449
1450 // Load the jobs from a JSON file.
1451 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1452
Eric Boren27225492017-02-01 15:56:55 -05001453 // Load general config information from a JSON file.
1454 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1455
borenetdb182c72016-09-30 12:53:12 -07001456 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001457 if *builderNameSchemaFile == "" {
1458 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1459 }
1460 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001461 if err != nil {
1462 glog.Fatal(err)
1463 }
1464 jobNameSchema = schema
1465
borenetdb182c72016-09-30 12:53:12 -07001466 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001467 for _, name := range JOBS {
1468 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001469 }
1470
boreneted20a702016-10-20 11:04:31 -07001471 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001472}
1473
1474// TODO(borenet): The below really belongs in its own file, probably next to the
1475// builder_name_schema.json file.
1476
Eric Boren8ff86a62018-04-17 14:11:23 -04001477// schema is a sub-struct of JobNameSchema.
1478type schema struct {
1479 Keys []string `json:"keys"`
1480 OptionalKeys []string `json:"optional_keys"`
1481 RecurseRoles []string `json:"recurse_roles"`
1482}
1483
borenetdb182c72016-09-30 12:53:12 -07001484// JobNameSchema is a struct used for (de)constructing Job names in a
1485// predictable format.
1486type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001487 Schema map[string]*schema `json:"builder_name_schema"`
1488 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001489}
1490
1491// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1492// file.
1493func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1494 var rv JobNameSchema
1495 f, err := os.Open(jsonFile)
1496 if err != nil {
1497 return nil, err
1498 }
1499 defer util.Close(f)
1500 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1501 return nil, err
1502 }
1503 return &rv, nil
1504}
1505
1506// ParseJobName splits the given Job name into its component parts, according
1507// to the schema.
1508func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001509 popFront := func(items []string) (string, []string, error) {
1510 if len(items) == 0 {
1511 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1512 }
1513 return items[0], items[1:], nil
1514 }
1515
1516 result := map[string]string{}
1517
1518 var parse func(int, string, []string) ([]string, error)
1519 parse = func(depth int, role string, parts []string) ([]string, error) {
1520 s, ok := s.Schema[role]
1521 if !ok {
1522 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1523 }
1524 if depth == 0 {
1525 result["role"] = role
1526 } else {
1527 result[fmt.Sprintf("sub-role-%d", depth)] = role
1528 }
1529 var err error
1530 for _, key := range s.Keys {
1531 var value string
1532 value, parts, err = popFront(parts)
1533 if err != nil {
1534 return nil, err
1535 }
1536 result[key] = value
1537 }
1538 for _, subRole := range s.RecurseRoles {
1539 if len(parts) > 0 && parts[0] == subRole {
1540 parts, err = parse(depth+1, parts[0], parts[1:])
1541 if err != nil {
1542 return nil, err
1543 }
1544 }
1545 }
1546 for _, key := range s.OptionalKeys {
1547 if len(parts) > 0 {
1548 var value string
1549 value, parts, err = popFront(parts)
1550 if err != nil {
1551 return nil, err
1552 }
1553 result[key] = value
1554 }
1555 }
1556 if len(parts) > 0 {
1557 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1558 }
1559 return parts, nil
1560 }
1561
borenetdb182c72016-09-30 12:53:12 -07001562 split := strings.Split(n, s.Sep)
1563 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001564 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001565 }
1566 role := split[0]
1567 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001568 _, err := parse(0, role, split)
1569 return result, err
borenetdb182c72016-09-30 12:53:12 -07001570}
1571
1572// MakeJobName assembles the given parts of a Job name, according to the schema.
1573func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001574 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001575
1576 var process func(int, map[string]string) (map[string]string, error)
1577 process = func(depth int, parts map[string]string) (map[string]string, error) {
1578 roleKey := "role"
1579 if depth != 0 {
1580 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001581 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001582 role, ok := parts[roleKey]
1583 if !ok {
1584 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1585 }
1586
1587 s, ok := s.Schema[role]
1588 if !ok {
1589 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1590 }
1591 rvParts = append(rvParts, role)
1592 delete(parts, roleKey)
1593
1594 for _, key := range s.Keys {
1595 value, ok := parts[key]
1596 if !ok {
1597 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1598 }
1599 rvParts = append(rvParts, value)
1600 delete(parts, key)
1601 }
1602
1603 if len(s.RecurseRoles) > 0 {
1604 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1605 subRole, ok := parts[subRoleKey]
1606 if !ok {
1607 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1608 }
1609 rvParts = append(rvParts, subRole)
1610 delete(parts, subRoleKey)
1611 found := false
1612 for _, recurseRole := range s.RecurseRoles {
1613 if recurseRole == subRole {
1614 found = true
1615 var err error
1616 parts, err = process(depth+1, parts)
1617 if err != nil {
1618 return nil, err
1619 }
1620 break
1621 }
1622 }
1623 if !found {
1624 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1625 }
1626 }
1627 for _, key := range s.OptionalKeys {
1628 if value, ok := parts[key]; ok {
1629 rvParts = append(rvParts, value)
1630 delete(parts, key)
1631 }
1632 }
1633 if len(parts) > 0 {
1634 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1635 }
1636 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001637 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001638
1639 // Copy the parts map, so that we can modify at will.
1640 partsCpy := make(map[string]string, len(parts))
1641 for k, v := range parts {
1642 partsCpy[k] = v
1643 }
1644 if _, err := process(0, partsCpy); err != nil {
1645 return "", err
borenetdb182c72016-09-30 12:53:12 -07001646 }
1647 return strings.Join(rvParts, s.Sep), nil
1648}