blob: 5ec6e79adadbb7054466cd3a492b11e5e3a0c48c [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"
Kevin Lubick814b1492017-11-29 14:45:14 -050036 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"
Stephan Altmueller2a552172018-02-20 11:40:25 -050040 ISOLATE_SDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidSDKLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050041 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
42 ISOLATE_WIN_VULKAN_SDK_NAME = "Housekeeper-PerCommit-IsolateWinVulkanSDK"
Eric Boren8b3f9e62017-04-04 09:06:16 -040043
Ben Wagner1676ec22018-04-06 17:39:06 -040044 DEFAULT_OS_DEBIAN = "Debian-9.4"
45 DEFAULT_OS_LINUX_GCE = DEFAULT_OS_DEBIAN
Ben Wagnere8d2a452018-08-06 10:00:54 -040046 DEFAULT_OS_MAC = "Mac-10.13.6"
Eric Boren170c39c2017-11-15 11:22:57 -050047 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
48 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070049
Eric Boreneb702382018-04-19 09:36:45 -040050 DEFAULT_PROJECT = "skia"
51
Ben Wagner297e86b2018-05-14 12:38:09 -040052 // Small is a 2-core machine.
53 // TODO(dogben): Would n1-standard-1 or n1-standard-2 be sufficient?
Ben Wagnere99a4b12018-05-04 11:18:01 -040054 MACHINE_TYPE_SMALL = "n1-highmem-2"
Ben Wagner297e86b2018-05-14 12:38:09 -040055 // Medium is a 16-core machine
56 MACHINE_TYPE_MEDIUM = "n1-standard-16"
57 // Large is a 64-core machine. (We use "highcpu" because we don't need more than 57GB memory for
58 // any of our tasks.)
Ben Wagnere99a4b12018-05-04 11:18:01 -040059 MACHINE_TYPE_LARGE = "n1-highcpu-64"
60
Eric Boren9599b0f2018-04-17 15:55:57 -040061 // Swarming output dirs.
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040062 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
63 OUTPUT_BUILD = "build"
64 OUTPUT_TEST = "test"
65 OUTPUT_PERF = "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -040066
borenetdb182c72016-09-30 12:53:12 -070067 // Name prefix for upload jobs.
68 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040069
70 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
71 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040072 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
73 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren84ae6412018-09-27 14:55:03 -040074 SERVICE_ACCOUNT_UPDATE_GO_DEPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040075 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
76 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
77 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
Eric Boren9599b0f2018-04-17 15:55:57 -040078 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
79 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070080)
81
82var (
83 // "Constants"
84
Eric Boren27225492017-02-01 15:56:55 -050085 // Top-level list of all jobs to run at each commit; loaded from
86 // jobs.json.
87 JOBS []string
88
Eric Boren27225492017-02-01 15:56:55 -050089 // General configuration information.
90 CONFIG struct {
Kevin Lubick2f9c1cc2018-09-24 11:22:55 -040091 GsBucketGm string `json:"gs_bucket_gm"`
92 GoldHashesURL string `json:"gold_hashes_url"`
93 GsBucketNano string `json:"gs_bucket_nano"`
94 GsBucketCalm string `json:"gs_bucket_calm"`
95 NoUpload []string `json:"no_upload"`
96 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070097 }
98
Eric Boreneb702382018-04-19 09:36:45 -040099 // alternateProject can be set in an init function to override the default project ID.
100 alternateProject string
101
Ben Wagner053d0462018-04-17 12:45:29 -0400102 // alternateServiceAccount can be set in an init function to override the normal service accounts.
103 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
104 // should be used, or uses sklog.Fatal to indicate a problem.
105 alternateServiceAccount func(serviceAccountEnum string) string
106
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400107 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
108 // dimensions for the given task.
109 alternateSwarmDimensions func(parts map[string]string) []string
110
Eric Borenfd4d60e2017-09-15 10:35:44 -0400111 // internalHardwareLabelFn can be set in an init function to provide an
112 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400113 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400114
borenetdb182c72016-09-30 12:53:12 -0700115 // Defines the structure of job names.
116 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500117
Eric Boren5cb5c742018-04-27 13:14:38 -0400118 // Named caches used by tasks.
119 CACHES_GIT = []*specs.Cache{
120 &specs.Cache{
121 Name: "git",
122 Path: "cache/git",
123 },
124 &specs.Cache{
125 Name: "git_cache",
126 Path: "cache/git_cache",
127 },
128 }
129 CACHES_WORKDIR = []*specs.Cache{
130 &specs.Cache{
131 Name: "work",
132 Path: "cache/work",
133 },
134 }
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400135 CACHES_DOCKER = []*specs.Cache{
136 &specs.Cache{
137 Name: "docker",
138 Path: "cache/docker",
139 },
140 }
Ben Wagner702fe012018-06-15 09:19:13 -0400141 // Versions of the following copied from
142 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template_canary.json#42
143 // to test the fix for chromium:836196.
144 // (In the future we may want to use versions from
145 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template.json#42)
Eric Boren9599b0f2018-04-17 15:55:57 -0400146 // TODO(borenet): Roll these versions automatically!
147 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
148 &specs.CipdPackage{
149 Name: "infra/tools/luci/vpython/${platform}",
150 Path: "cipd_bin_packages",
Eric Borenb33f9eb2018-08-03 10:31:24 -0400151 Version: "git_revision:b6cdec8586c9f8d3d728b1bc0bd4331330ba66fc",
Eric Boren9599b0f2018-04-17 15:55:57 -0400152 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400153 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400154
Eric Borenaa037522018-06-18 16:02:15 -0400155 CIPD_PKGS_CPYTHON = []*specs.CipdPackage{
156 &specs.CipdPackage{
157 Name: "infra/python/cpython/${platform}",
158 Path: "cipd_bin_packages",
159 Version: "version:2.7.14.chromium14",
160 },
161 }
162
Eric Boren9599b0f2018-04-17 15:55:57 -0400163 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
164 &specs.CipdPackage{
165 Name: "infra/tools/luci/kitchen/${platform}",
166 Path: ".",
Ben Wagner702fe012018-06-15 09:19:13 -0400167 Version: "git_revision:546aae39f1fb9dce9add528e2011afa574535ecd",
Eric Boren9599b0f2018-04-17 15:55:57 -0400168 },
169 &specs.CipdPackage{
Ben Wagnercd7ace22018-06-11 15:48:35 -0400170 Name: "infra/tools/luci-auth/${platform}",
Eric Boren9599b0f2018-04-17 15:55:57 -0400171 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400172 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400173 },
174 }, CIPD_PKGS_PYTHON...)
175
176 CIPD_PKGS_GIT = []*specs.CipdPackage{
177 &specs.CipdPackage{
178 Name: "infra/git/${platform}",
179 Path: "cipd_bin_packages",
Eric Borene42cef52018-06-20 07:11:38 -0400180 Version: "version:2.17.1.chromium15",
Eric Boren9599b0f2018-04-17 15:55:57 -0400181 },
182 &specs.CipdPackage{
183 Name: "infra/tools/git/${platform}",
184 Path: "cipd_bin_packages",
Eric Boren3f13bcb2018-06-15 07:39:36 -0400185 Version: "git_revision:0ae21738597e5601ba90372315145fec18582fc4",
Eric Boren9599b0f2018-04-17 15:55:57 -0400186 },
187 &specs.CipdPackage{
188 Name: "infra/tools/luci/git-credential-luci/${platform}",
189 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400190 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400191 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000192 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400193
Eric Boren9599b0f2018-04-17 15:55:57 -0400194 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
195 &specs.CipdPackage{
196 Name: "infra/gsutil",
197 Path: "cipd_bin_packages",
198 Version: "version:4.28",
199 },
200 }
201
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400202 CIPD_PKGS_XCODE = []*specs.CipdPackage{
203 // https://chromium.googlesource.com/chromium/tools/build/+/e19b7d9390e2bb438b566515b141ed2b9ed2c7c2/scripts/slave/recipe_modules/ios/api.py#317
204 // This package is really just an installer for XCode.
205 &specs.CipdPackage{
Ben Wagner66760792018-08-09 12:52:16 -0400206 Name: "infra/tools/mac_toolchain/${platform}",
207 Path: "mac_toolchain",
208 // When this is updated, also update
209 // https://skia.googlesource.com/skcms.git/+/f1e2b45d18facbae2dece3aca673fe1603077846/infra/bots/gen_tasks.go#56
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400210 Version: "git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a",
211 },
212 }
213
Eric Boren27225492017-02-01 15:56:55 -0500214 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500215 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.")
216 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
217 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500218 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700219)
220
Eric Boreneb702382018-04-19 09:36:45 -0400221// Build the LogDog annotation URL.
222func logdogAnnotationUrl() string {
223 project := DEFAULT_PROJECT
224 if alternateProject != "" {
225 project = alternateProject
226 }
227 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
228}
229
Eric Boren9599b0f2018-04-17 15:55:57 -0400230// Create a properties JSON string.
231func props(p map[string]string) string {
232 d := make(map[string]interface{}, len(p)+1)
233 for k, v := range p {
234 d[k] = interface{}(v)
235 }
236 d["$kitchen"] = struct {
237 DevShell bool `json:"devshell"`
238 GitAuth bool `json:"git_auth"`
239 }{
240 DevShell: true,
241 GitAuth: true,
242 }
243
244 j, err := json.Marshal(d)
245 if err != nil {
246 sklog.Fatal(err)
247 }
248 return strings.Replace(string(j), "\\u003c", "<", -1)
249}
250
251// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
252// recipe.
253func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
254 if serviceAccount != "" && alternateServiceAccount != nil {
255 serviceAccount = alternateServiceAccount(serviceAccount)
256 }
257 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
Eric Borenaa037522018-06-18 16:02:15 -0400258 if strings.Contains(name, "Win") {
259 cipd = append(cipd, CIPD_PKGS_CPYTHON...)
260 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400261 properties := map[string]string{
262 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
263 "buildername": name,
264 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400265 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400266 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
267 "patch_set": specs.PLACEHOLDER_PATCHSET,
268 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
269 "repository": specs.PLACEHOLDER_REPO,
270 "revision": specs.PLACEHOLDER_REVISION,
271 "swarm_out_dir": outputDir,
272 }
273 for k, v := range extraProps {
274 properties[k] = v
275 }
276 var outputs []string = nil
277 if outputDir != OUTPUT_NONE {
278 outputs = []string{outputDir}
279 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400280 task := &specs.TaskSpec{
281 Caches: []*specs.Cache{
282 &specs.Cache{
283 Name: "vpython",
284 Path: "cache/vpython",
285 },
286 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400287 CipdPackages: cipd,
288 Command: []string{
289 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
290 "-checkout-dir", "recipe_bundle",
291 "-mode", "swarming",
292 "-luci-system-account", "system",
293 "-cache-dir", "cache",
294 "-temp-dir", "tmp",
295 "-known-gerrit-host", "android.googlesource.com",
296 "-known-gerrit-host", "boringssl.googlesource.com",
297 "-known-gerrit-host", "chromium.googlesource.com",
298 "-known-gerrit-host", "dart.googlesource.com",
299 "-known-gerrit-host", "fuchsia.googlesource.com",
300 "-known-gerrit-host", "go.googlesource.com",
301 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400302 "-known-gerrit-host", "skia.googlesource.com",
303 "-known-gerrit-host", "webrtc.googlesource.com",
304 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
305 "-workdir", ".",
306 "-recipe", recipe,
307 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400308 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400309 },
310 Dependencies: []string{BUNDLE_RECIPES_NAME},
311 Dimensions: dimensions,
312 EnvPrefixes: map[string][]string{
Kevin Lubick37baac12018-10-09 16:25:27 -0400313 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
Eric Boren7c42e012018-08-20 09:45:02 -0400314 "VPYTHON_VIRTUALENV_ROOT": []string{"cache/vpython"},
Eric Boren9599b0f2018-04-17 15:55:57 -0400315 },
316 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400317 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400318 },
319 Isolate: relpath(isolate),
Ben Wagner73e2ced2018-12-17 12:44:30 -0500320 MaxAttempts: attempts(name),
Eric Boren9599b0f2018-04-17 15:55:57 -0400321 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 Wagnera2785cc2018-12-03 17:51:29 -0500451 "Win10": "Windows-10-17134.441",
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 Wagner7b069fa2018-12-03 13:02:01 -0500565 "IntelIris540": "8086:1926-25.20.100.6444",
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 },
Kevin Lubick07072942017-05-11 13:35:23 -0400704 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400705 cipdPkg: "skimage",
706 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400707 },
708 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400709 cipdPkg: "skp",
710 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400711 },
712 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400713 cipdPkg: "svg",
714 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400715 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500716 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400717 cipdPkg: "android_ndk_linux",
718 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500719 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500720 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400721 cipdPkg: "android_sdk_linux",
722 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500723 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500724 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400725 cipdPkg: "win_toolchain",
Brian Osmanef3d04e2018-12-12 13:28:09 -0500726 path: "win_toolchain",
Kevin Lubick814b1492017-11-29 14:45:14 -0500727 },
728 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400729 cipdPkg: "win_vulkan_sdk",
730 path: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500731 },
Kevin Lubick07072942017-05-11 13:35:23 -0400732}
733
Eric Boren9599b0f2018-04-17 15:55:57 -0400734// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400735func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400736 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400737 b.MustAddTask(name, &specs.TaskSpec{
738 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400739 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400740 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400741 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400742 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400743 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400744 })
745 return name
746}
747
Kevin Lubick90189522017-05-15 08:30:27 -0400748// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
749// This allows us to save time on I/O bound bots, like the RPIs.
750func getIsolatedCIPDDeps(parts map[string]string) []string {
751 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400752 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
753 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400754 rpiOS := []string{"Android", "ChromeOS", "iOS"}
755
756 if o := parts["os"]; strings.Contains(o, "Chromecast") {
757 // Chromecasts don't have enough disk space to fit all of the content,
758 // so we do a subset of the skps.
759 deps = append(deps, ISOLATE_SKP_NAME)
760 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
761 // Skpbench only needs skps
762 deps = append(deps, ISOLATE_SKP_NAME)
763 } else if util.In(o, rpiOS) {
764 deps = append(deps, ISOLATE_SKP_NAME)
765 deps = append(deps, ISOLATE_SVG_NAME)
766 deps = append(deps, ISOLATE_SKIMAGE_NAME)
767 }
768
769 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400770}
771
Eric Boren5cb5c742018-04-27 13:14:38 -0400772// usesGit adds attributes to tasks which use git.
773func usesGit(t *specs.TaskSpec, name string) {
774 t.Caches = append(t.Caches, CACHES_GIT...)
775 if !strings.Contains(name, "NoDEPS") {
776 t.Caches = append(t.Caches, CACHES_WORKDIR...)
777 }
778 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
779}
780
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400781// usesDocker adds attributes to tasks which use docker.
782func usesDocker(t *specs.TaskSpec, name string) {
783 // currently, just the WASM (using EMCC) builder uses Docker.
784 if strings.Contains(name, "EMCC") {
785 t.Caches = append(t.Caches, CACHES_DOCKER...)
786 }
787}
788
Eric Boren5cb5c742018-04-27 13:14:38 -0400789// timeout sets the timeout(s) for this task.
790func timeout(task *specs.TaskSpec, timeout time.Duration) {
791 task.ExecutionTimeout = timeout
792 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
793}
794
Ben Wagner73e2ced2018-12-17 12:44:30 -0500795// attempts returns the desired MaxAttempts for this task.
796func attempts(name string) int {
797 if strings.Contains(name, "Android_Framework") {
798 // The reason for this has been lost to time.
799 return 1
800 }
801 if !(strings.HasPrefix(name, "Build-") || strings.HasPrefix(name, "Upload-")) {
802 for _, extraConfig := range []string{"ASAN", "MSAN", "TSAN", "UBSAN", "Valgrind"} {
803 if strings.Contains(name, extraConfig) {
804 // Sanitizers often find non-deterministic issues that retries would hide.
805 return 1
806 }
807 }
808 }
809 // Retry by default to hide random bot/hardware failures.
810 return 2
811}
812
borenetdb182c72016-09-30 12:53:12 -0700813// compile generates a compile task. Returns the name of the last task in the
814// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700815func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400816 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400817 usesGit(task, name)
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400818 usesDocker(task, name)
borenetdb182c72016-09-30 12:53:12 -0700819
820 // Android bots require a toolchain.
821 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500822 if parts["extra_config"] == "Android_Framework" {
823 // Do not need a toolchain when building the
824 // Android Framework.
825 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400826 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400827 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400828 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
829 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400830 task.CipdPackages = append(task.CipdPackages, pkg)
Kevin Lubick35b87a52018-10-08 15:07:42 -0400831 } else if !strings.Contains(name, "SKQP") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400832 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
borenetdb182c72016-09-30 12:53:12 -0700833 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500834 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400835 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
836 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400837 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400838 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400839 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400840 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400841 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400842 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
843 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400844 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400845 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500846 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400847 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500848 }
Mike Klein66fec0e2018-11-07 11:27:56 -0500849 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400850 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500851 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400852 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
853 if parts["compiler"] != "GCC" {
854 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
855 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400856 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400857 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400858 if strings.Contains(name, "SwiftShader") {
859 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
860 }
Ben Wagner55a7d222018-06-28 20:41:04 -0400861 if strings.Contains(name, "OpenCL") {
862 task.CipdPackages = append(task.CipdPackages,
863 b.MustGetCipdPackageFromAsset("opencl_headers"),
864 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
865 )
866 }
Mike Klein27dcee12016-11-09 16:31:42 -0500867 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400868 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400869 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400870 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400871 }
borenetdb182c72016-09-30 12:53:12 -0700872 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400873 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700874 }
Ben Wagner30a4e3d2018-08-07 16:58:15 -0400875 if strings.Contains(name, "OpenCL") {
876 task.CipdPackages = append(task.CipdPackages,
877 b.MustGetCipdPackageFromAsset("opencl_headers"),
878 )
879 }
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400880 } else if strings.Contains(name, "Mac") {
881 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_XCODE...)
882 task.Caches = append(task.Caches, &specs.Cache{
883 Name: "xcode",
884 Path: "cache/Xcode.app",
885 })
886 if strings.Contains(name, "CommandBuffer") {
887 timeout(task, 2*time.Hour)
888 }
889 if strings.Contains(name, "MoltenVK") {
890 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("moltenvk"))
891 }
Chris Dalton2b937f52018-05-17 10:17:10 -0600892 }
893
Eric Borenbd2e1f12018-04-17 11:28:46 +0000894 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400895 b.MustAddTask(name, task)
896
Eric Boren8615fe52016-12-12 14:30:12 -0500897 // All compile tasks are runnable as their own Job. Assert that the Job
898 // is listed in JOBS.
899 if !util.In(name, JOBS) {
900 glog.Fatalf("Job %q is missing from the JOBS list!", name)
901 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500902
903 // Upload the skiaserve binary only for Linux Android compile bots.
904 // See skbug.com/7399 for context.
905 if parts["configuration"] == "Release" &&
906 parts["extra_config"] == "Android" &&
907 !strings.Contains(parts["os"], "Win") &&
908 !strings.Contains(parts["os"], "Mac") {
909 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400910 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 -0400911 task.Dependencies = append(task.Dependencies, name)
912 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500913 return uploadName
914 }
915
borenetdb182c72016-09-30 12:53:12 -0700916 return name
917}
918
919// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
920// task in the generated chain of tasks, which the Job should add as a
921// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000922func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry5a12d052018-05-15 17:19:42 -0400923 dims := []string{
924 "pool:SkiaCT",
925 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
926 }
927 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400928 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400929 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400930 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren5cb5c742018-04-27 13:14:38 -0400931 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400932 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700933 return name
934}
935
Eric Boren84ae6412018-09-27 14:55:03 -0400936// updateGoDEPS generates an UpdateGoDEPS task. Returns the name of the last
937// task in the generated chain of tasks, which the Job should add as a
938// dependency.
939func updateGoDEPS(b *specs.TasksCfgBuilder, name string) string {
940 dims := linuxGceDimensions(MACHINE_TYPE_LARGE)
941 task := kitchenTask(name, "update_go_deps", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPDATE_GO_DEPS, dims, nil, OUTPUT_NONE)
942 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
943 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
944 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
945 b.MustAddTask(name, task)
946 return name
947}
948
Eric Borenf7928b42017-07-28 07:35:28 -0400949// checkGeneratedFiles verifies that no generated SKSL files have been edited
950// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000951func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400952 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 -0400953 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400954 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400955 return name
956}
957
borenetdb182c72016-09-30 12:53:12 -0700958// housekeeper generates a Housekeeper task. Returns the name of the last task
959// in the generated chain of tasks, which the Job should add as a dependency.
Kevin Lubick37baac12018-10-09 16:25:27 -0400960func housekeeper(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400961 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400962 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400963 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700964 return name
965}
966
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500967// bookmaker generates a Bookmaker task. Returns the name of the last task
968// in the generated chain of tasks, which the Job should add as a dependency.
969func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400970 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400971 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400972 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Ben Wagner43588022018-12-18 23:16:07 -0500973 task.Dependencies = append(task.Dependencies, compileTaskName, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren5cb5c742018-04-27 13:14:38 -0400974 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400975 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500976 return name
977}
978
Ravi Mistry5e967422018-02-01 13:38:13 -0500979// androidFrameworkCompile generates an Android Framework Compile task. Returns
980// the name of the last task in the generated chain of tasks, which the Job
981// should add as a dependency.
982func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400983 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 -0400984 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400985 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500986 return name
987}
988
borenet2dbbfa52016-10-14 06:32:09 -0700989// infra generates an infra_tests task. Returns the name of the last task in the
990// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000991func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400992 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400993 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400994 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400995 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren9599b0f2018-04-17 15:55:57 -0400996 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -0700997 return name
998}
999
Kevin Lubick49688432018-10-08 13:58:47 -04001000func buildstats(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string) string {
1001 task := kitchenTask(name, "compute_buildstats", "swarm_recipe.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
1002 task.Dependencies = append(task.Dependencies, compileTaskName)
Kevin Lubick6ca0d8a2018-10-09 13:31:33 -04001003 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("bloaty"))
Kevin Lubick49688432018-10-08 13:58:47 -04001004 b.MustAddTask(name, task)
1005
Kevin Lubick8875baf2018-10-18 13:35:04 -04001006 // Upload release results (for tracking in perf)
1007 // We have some jobs that are FYI (e.g. Debug-CanvasKit)
1008 if strings.Contains(name, "Release") {
1009 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
1010 extraProps := map[string]string{
1011 "gs_bucket": CONFIG.GsBucketNano,
1012 }
1013 uploadTask := kitchenTask(name, "upload_buildstats_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_NANO, linuxGceDimensions(MACHINE_TYPE_SMALL), extraProps, OUTPUT_NONE)
1014 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1015 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1016 b.MustAddTask(uploadName, uploadTask)
1017 return uploadName
Kevin Lubick49688432018-10-08 13:58:47 -04001018 }
Kevin Lubick49688432018-10-08 13:58:47 -04001019
1020 return name
1021}
1022
Yuqian Li4a577af2018-01-05 11:13:43 -05001023func getParentRevisionName(compileTaskName string, parts map[string]string) string {
1024 if parts["extra_config"] == "" {
1025 return compileTaskName + "-ParentRevision"
1026 } else {
1027 return compileTaskName + "_ParentRevision"
1028 }
1029}
1030
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001031// calmbench generates a calmbench task. Returns the name of the last task in the
1032// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -04001033func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
1034 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -04001035 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001036 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001037 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1038 // Specify "rack" dimension for consistent test results.
1039 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1040 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001041 if parts["os"] == "Ubuntu18" {
1042 task.Dimensions = append(task.Dimensions, "rack:2")
1043 } else {
1044 task.Dimensions = append(task.Dimensions, "rack:1")
1045 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001046 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001047 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001048
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001049 // Upload results if necessary.
1050 if strings.Contains(name, "Release") && doUpload(name) {
1051 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001052 extraProps := map[string]string{
1053 "gs_bucket": CONFIG.GsBucketCalm,
1054 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001055 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 -04001056 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1057 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1058 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001059 return uploadName
1060 }
1061
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001062 return name
1063}
1064
borenetdb182c72016-09-30 12:53:12 -07001065// doUpload indicates whether the given Job should upload its results.
1066func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -05001067 for _, s := range CONFIG.NoUpload {
1068 m, err := regexp.MatchString(s, name)
1069 if err != nil {
1070 glog.Fatal(err)
1071 }
1072 if m {
borenetdb182c72016-09-30 12:53:12 -07001073 return false
1074 }
1075 }
1076 return true
1077}
1078
1079// test generates a Test task. Returns the name of the last task in the
1080// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001081func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001082 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001083 if strings.Contains(name, "SKQP") {
1084 recipe = "skqp_test"
Kevin Lubick35b87a52018-10-08 15:07:42 -04001085 if strings.Contains(name, "Emulator") {
1086 recipe = "test_skqp_emulator"
1087 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001088 } else if strings.Contains(name, "OpenCL") {
1089 // TODO(dogben): Longer term we may not want this to be called a "Test" task, but until we start
1090 // running hs_bench or kx, it will be easier to fit into the current job name schema.
1091 recipe = "compute_test"
Kevin Lubick92c91712018-08-09 10:00:02 -04001092 } else if strings.Contains(name, "PathKit") {
1093 recipe = "test_pathkit"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001094 } else if strings.Contains(name, "CanvasKit") {
1095 recipe = "test_canvaskit"
Kevin Lubick82999c02018-08-28 10:52:18 -04001096 } else if strings.Contains(name, "LottieWeb") {
1097 recipe = "test_lottie_web"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001098 }
Stephan Altmüller64cc5762018-08-02 08:51:38 +02001099 extraProps := map[string]string{
1100 "gold_hashes_url": CONFIG.GoldHashesURL,
1101 }
Eric Boreneb702382018-04-19 09:36:45 -04001102 iid := internalHardwareLabel(parts)
1103 if iid != nil {
1104 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
1105 }
Kevin Lubick92c91712018-08-09 10:00:02 -04001106 isolate := "test_skia_bundled.isolate"
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001107 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "Emulator") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick92c91712018-08-09 10:00:02 -04001108 isolate = "swarm_recipe.isolate"
1109 }
1110 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -04001111 task.CipdPackages = append(task.CipdPackages, pkgs...)
Eric Boren8c172ba2018-07-19 13:27:49 -04001112 if strings.Contains(name, "Lottie") {
1113 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("lottie-samples"))
1114 }
Kevin Lubick82999c02018-08-28 10:52:18 -04001115 if !strings.Contains(name, "LottieWeb") {
1116 // Test.+LottieWeb doesn't require anything in Skia to be compiled.
1117 task.Dependencies = append(task.Dependencies, compileTaskName)
1118 }
1119
Eric Boren9599b0f2018-04-17 15:55:57 -04001120 if strings.Contains(name, "Android_ASAN") {
1121 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +00001122 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001123 if strings.Contains(name, "SKQP") {
Kevin Lubick35b87a52018-10-08 15:07:42 -04001124 if !strings.Contains(name, "Emulator") {
1125 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
1126 }
Eric Boren8b3f9e62017-04-04 09:06:16 -04001127 }
Kevin Lubick90189522017-05-15 08:30:27 -04001128 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001129 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -04001130 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001131 task.Expiration = 20 * time.Hour
Ben Wagner73e2ced2018-12-17 12:44:30 -05001132
Eric Boren5cb5c742018-04-27 13:14:38 -04001133 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001134 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001135 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001136 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001137 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1138 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001139 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001140 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001141 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1142 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001143 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001144 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001145 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001146
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001147 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
1148 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -07001149 if doUpload(name) {
1150 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001151 extraProps := map[string]string{
1152 "gs_bucket": CONFIG.GsBucketGm,
1153 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001154 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 -04001155 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1156 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1157 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001158 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001159 }
1160
1161 return name
1162}
1163
borenetdb182c72016-09-30 12:53:12 -07001164// perf generates a Perf task. Returns the name of the last task in the
1165// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001166func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001167 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001168 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001169 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001170 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001171 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubick556350d2018-10-12 15:21:17 -04001172 } else if strings.Contains(name, "PathKit") {
1173 recipe = "perf_pathkit"
Kevin Lubickf2a146c2018-10-17 14:59:35 -04001174 } else if strings.Contains(name, "CanvasKit") {
1175 recipe = "perf_canvaskit"
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001176 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001177 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1178 task.CipdPackages = append(task.CipdPackages, pkgs...)
1179 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001180 task.Expiration = 20 * time.Hour
Eric Boren5cb5c742018-04-27 13:14:38 -04001181 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001182 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001183 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001184 }
1185
Eric Boren4b254b92016-11-08 12:55:32 -05001186 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001187 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001188 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001189 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1190 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001191 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001192 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001193 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1194 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001195 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001196 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001197 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001198 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001199 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001200 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001201 if parts["cpu_or_gpu_value"] == "QuadroP400" {
1202 // Specify "rack" dimension for consistent test results.
1203 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
1204 // for more context.
Ben Wagner2aa9a222018-11-06 13:45:40 -05001205 if parts["os"] == "Ubuntu18" {
1206 task.Dimensions = append(task.Dimensions, "rack:2")
1207 } else {
1208 task.Dimensions = append(task.Dimensions, "rack:1")
1209 }
Kevin Lubickde1a1a22018-10-01 10:07:42 -04001210 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001211 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001212
borenetdb182c72016-09-30 12:53:12 -07001213 // Upload results if necessary.
1214 if strings.Contains(name, "Release") && doUpload(name) {
1215 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001216 extraProps := map[string]string{
1217 "gs_bucket": CONFIG.GsBucketNano,
1218 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001219 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 -04001220 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1221 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1222 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001223 return uploadName
1224 }
1225 return name
1226}
1227
Eric Borenb66099b2018-04-25 15:09:22 -04001228// Run the presubmit.
1229func presubmit(b *specs.TasksCfgBuilder, name string) string {
1230 extraProps := map[string]string{
1231 "category": "cq",
1232 "patch_gerrit_url": "https://skia-review.googlesource.com",
1233 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001234 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001235 "reason": "CQ",
1236 "repo_name": "skia",
1237 }
Ben Wagner297e86b2018-05-14 12:38:09 -04001238 // Use MACHINE_TYPE_LARGE because it seems to save time versus MEDIUM and we want presubmit to be
1239 // fast.
Ben Wagnere99a4b12018-05-04 11:18:01 -04001240 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001241
1242 replaceArg := func(key, value string) {
1243 found := false
1244 for idx, arg := range task.Command {
1245 if arg == key {
1246 task.Command[idx+1] = value
1247 found = true
1248 }
1249 }
1250 if !found {
1251 task.Command = append(task.Command, key, value)
1252 }
1253 }
1254 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1255 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001256 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001257 task.Dependencies = []string{} // No bundled recipes for this one.
1258 b.MustAddTask(name, task)
1259 return name
1260}
1261
borenetdb182c72016-09-30 12:53:12 -07001262// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001263func process(b *specs.TasksCfgBuilder, name string) {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001264 var priority float64 // Leave as default for most jobs.
borenetdb182c72016-09-30 12:53:12 -07001265 deps := []string{}
1266
Eric Boren8b3f9e62017-04-04 09:06:16 -04001267 // Bundle Recipes.
1268 if name == BUNDLE_RECIPES_NAME {
1269 deps = append(deps, bundleRecipes(b))
1270 }
1271
Kevin Lubick07072942017-05-11 13:35:23 -04001272 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001273 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1274 deps = append(deps, isolateCIPDAsset(b, name))
1275 }
1276
borenetdb182c72016-09-30 12:53:12 -07001277 parts, err := jobNameSchema.ParseJobName(name)
1278 if err != nil {
1279 glog.Fatal(err)
1280 }
1281
1282 // RecreateSKPs.
1283 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001284 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001285 }
1286
Eric Boren84ae6412018-09-27 14:55:03 -04001287 // Update Go DEPS.
1288 if strings.Contains(name, "UpdateGoDEPS") {
1289 deps = append(deps, updateGoDEPS(b, name))
1290 }
1291
borenet2dbbfa52016-10-14 06:32:09 -07001292 // Infra tests.
1293 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001294 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001295 }
1296
borenetdb182c72016-09-30 12:53:12 -07001297 // Compile bots.
1298 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001299 if parts["extra_config"] == "Android_Framework" {
1300 // Android Framework compile tasks use a different recipe.
1301 deps = append(deps, androidFrameworkCompile(b, name))
1302 } else {
1303 deps = append(deps, compile(b, name, parts))
1304 }
borenetdb182c72016-09-30 12:53:12 -07001305 }
1306
Eric Borenf5a90e82016-11-15 15:18:20 -05001307 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001308 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001309 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1310 if err != nil {
1311 glog.Fatal(err)
1312 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001313 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1314 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1315 if err != nil {
1316 glog.Fatal(err)
1317 }
1318
Eric Boren628e78b2016-11-17 11:33:27 -05001319 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001320 if parts["role"] != "Build" &&
Eric Boren84ae6412018-09-27 14:55:03 -04001321 name != "Housekeeper-Nightly-UpdateGoDEPS" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001322 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001323 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001324 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001325 name != "Housekeeper-OnDemand-Presubmit" &&
Kevin Lubick37baac12018-10-09 16:25:27 -04001326 name != "Housekeeper-PerCommit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001327 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001328 !strings.Contains(name, "RecreateSKPs") &&
Kevin Lubick82999c02018-08-28 10:52:18 -04001329 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") &&
1330 !strings.Contains(name, "LottieWeb") {
boreneted20a702016-10-20 11:04:31 -07001331 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001332 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001333 compile(b, compileParentName, compileParentParts)
1334 }
borenet52383432016-10-17 10:17:53 -07001335 }
borenetdb182c72016-09-30 12:53:12 -07001336
Eric Borenf7928b42017-07-28 07:35:28 -04001337 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001338 if name == "Housekeeper-PerCommit" {
Kevin Lubick37baac12018-10-09 16:25:27 -04001339 deps = append(deps, housekeeper(b, name))
borenetdb182c72016-09-30 12:53:12 -07001340 }
Eric Borenf7928b42017-07-28 07:35:28 -04001341 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001342 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001343 }
Eric Borenb66099b2018-04-25 15:09:22 -04001344 if name == "Housekeeper-OnDemand-Presubmit" {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001345 priority = 1
Eric Borenb66099b2018-04-25 15:09:22 -04001346 deps = append(deps, presubmit(b, name))
1347 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001348 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001349 deps = append(deps, bookmaker(b, name, compileTaskName))
1350 }
borenetdb182c72016-09-30 12:53:12 -07001351
1352 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001353
1354 pkgs := []*specs.CipdPackage{}
1355
Kevin Lubick90189522017-05-15 08:30:27 -04001356 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001357 pkgs = []*specs.CipdPackage{
1358 b.MustGetCipdPackageFromAsset("skimage"),
1359 b.MustGetCipdPackageFromAsset("skp"),
1360 b.MustGetCipdPackageFromAsset("svg"),
1361 }
borenetdb182c72016-09-30 12:53:12 -07001362 }
Kevin Lubick90189522017-05-15 08:30:27 -04001363
Ben Wagner5655ba42017-10-02 10:48:32 -04001364 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1365 if strings.Contains(name, "SAN") {
1366 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1367 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001368 if strings.Contains(name, "Vulkan") {
1369 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1370 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001371 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
Kevin Lubick1b5ece02018-09-11 17:09:28 -04001372 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("mesa_intel_driver_linux"))
Kevin Lubick0a51b482017-02-06 12:45:29 -05001373 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001374 if strings.Contains(name, "OpenCL") {
1375 pkgs = append(pkgs,
1376 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
1377 b.MustGetCipdPackageFromAsset("opencl_intel_neo_linux"),
1378 )
1379 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001380 }
Ben Wagner299b8822018-03-09 13:42:56 -05001381 if strings.Contains(name, "ProcDump") {
1382 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1383 }
Kevin Lubick8e9750d2018-10-09 09:36:35 -04001384 if strings.Contains(name, "CanvasKit") || strings.Contains(name, "LottieWeb") || strings.Contains(name, "PathKit") {
Kevin Lubick82999c02018-08-28 10:52:18 -04001385 // Docker-based tests that don't need the standard CIPD assets
Kevin Lubick92c91712018-08-09 10:00:02 -04001386 pkgs = []*specs.CipdPackage{}
1387 }
borenetdb182c72016-09-30 12:53:12 -07001388
1389 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001390 if parts["role"] == "Test" {
Ravi Mistryeea245c2018-10-09 10:31:11 -04001391 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001392 }
1393
1394 // Perf bots.
Ravi Mistryeea245c2018-10-09 10:31:11 -04001395 if parts["role"] == "Perf" {
boreneted20a702016-10-20 11:04:31 -07001396 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001397 }
1398
Yuqian Li4a577af2018-01-05 11:13:43 -05001399 // Calmbench bots.
1400 if parts["role"] == "Calmbench" {
1401 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1402 }
1403
Kevin Lubick49688432018-10-08 13:58:47 -04001404 // BuildStats bots. This computes things like binary size.
1405 if parts["role"] == "BuildStats" {
1406 deps = append(deps, buildstats(b, name, parts, compileTaskName))
1407 }
1408
borenetdb182c72016-09-30 12:53:12 -07001409 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001410 j := &specs.JobSpec{
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001411 Priority: priority,
borenetdb182c72016-09-30 12:53:12 -07001412 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001413 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001414 }
Eric Borenba937a42017-07-31 10:41:15 -04001415 if strings.Contains(name, "-Nightly-") {
1416 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryeea245c2018-10-09 10:31:11 -04001417 } else if strings.Contains(name, "-Weekly-") {
Eric Borenba937a42017-07-31 10:41:15 -04001418 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001419 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001420 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001421 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001422 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001423 }
Eric Boren8615fe52016-12-12 14:30:12 -05001424 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001425}
1426
Eric Boren27225492017-02-01 15:56:55 -05001427func loadJson(flag *string, defaultFlag string, val interface{}) {
1428 if *flag == "" {
1429 *flag = defaultFlag
1430 }
1431 b, err := ioutil.ReadFile(*flag)
1432 if err != nil {
1433 glog.Fatal(err)
1434 }
1435 if err := json.Unmarshal(b, val); err != nil {
1436 glog.Fatal(err)
1437 }
1438}
1439
borenetdb182c72016-09-30 12:53:12 -07001440// Regenerate the tasks.json file.
1441func main() {
boreneted20a702016-10-20 11:04:31 -07001442 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001443 b.SetAssetsDir(*assetsDir)
1444 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1445
1446 // Load the jobs from a JSON file.
1447 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1448
Eric Boren27225492017-02-01 15:56:55 -05001449 // Load general config information from a JSON file.
1450 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1451
borenetdb182c72016-09-30 12:53:12 -07001452 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001453 if *builderNameSchemaFile == "" {
1454 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1455 }
1456 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001457 if err != nil {
1458 glog.Fatal(err)
1459 }
1460 jobNameSchema = schema
1461
borenetdb182c72016-09-30 12:53:12 -07001462 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001463 for _, name := range JOBS {
1464 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001465 }
1466
boreneted20a702016-10-20 11:04:31 -07001467 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001468}
1469
1470// TODO(borenet): The below really belongs in its own file, probably next to the
1471// builder_name_schema.json file.
1472
Eric Boren8ff86a62018-04-17 14:11:23 -04001473// schema is a sub-struct of JobNameSchema.
1474type schema struct {
1475 Keys []string `json:"keys"`
1476 OptionalKeys []string `json:"optional_keys"`
1477 RecurseRoles []string `json:"recurse_roles"`
1478}
1479
borenetdb182c72016-09-30 12:53:12 -07001480// JobNameSchema is a struct used for (de)constructing Job names in a
1481// predictable format.
1482type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001483 Schema map[string]*schema `json:"builder_name_schema"`
1484 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001485}
1486
1487// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1488// file.
1489func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1490 var rv JobNameSchema
1491 f, err := os.Open(jsonFile)
1492 if err != nil {
1493 return nil, err
1494 }
1495 defer util.Close(f)
1496 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1497 return nil, err
1498 }
1499 return &rv, nil
1500}
1501
1502// ParseJobName splits the given Job name into its component parts, according
1503// to the schema.
1504func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001505 popFront := func(items []string) (string, []string, error) {
1506 if len(items) == 0 {
1507 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1508 }
1509 return items[0], items[1:], nil
1510 }
1511
1512 result := map[string]string{}
1513
1514 var parse func(int, string, []string) ([]string, error)
1515 parse = func(depth int, role string, parts []string) ([]string, error) {
1516 s, ok := s.Schema[role]
1517 if !ok {
1518 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1519 }
1520 if depth == 0 {
1521 result["role"] = role
1522 } else {
1523 result[fmt.Sprintf("sub-role-%d", depth)] = role
1524 }
1525 var err error
1526 for _, key := range s.Keys {
1527 var value string
1528 value, parts, err = popFront(parts)
1529 if err != nil {
1530 return nil, err
1531 }
1532 result[key] = value
1533 }
1534 for _, subRole := range s.RecurseRoles {
1535 if len(parts) > 0 && parts[0] == subRole {
1536 parts, err = parse(depth+1, parts[0], parts[1:])
1537 if err != nil {
1538 return nil, err
1539 }
1540 }
1541 }
1542 for _, key := range s.OptionalKeys {
1543 if len(parts) > 0 {
1544 var value string
1545 value, parts, err = popFront(parts)
1546 if err != nil {
1547 return nil, err
1548 }
1549 result[key] = value
1550 }
1551 }
1552 if len(parts) > 0 {
1553 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1554 }
1555 return parts, nil
1556 }
1557
borenetdb182c72016-09-30 12:53:12 -07001558 split := strings.Split(n, s.Sep)
1559 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001560 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001561 }
1562 role := split[0]
1563 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001564 _, err := parse(0, role, split)
1565 return result, err
borenetdb182c72016-09-30 12:53:12 -07001566}
1567
1568// MakeJobName assembles the given parts of a Job name, according to the schema.
1569func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001570 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001571
1572 var process func(int, map[string]string) (map[string]string, error)
1573 process = func(depth int, parts map[string]string) (map[string]string, error) {
1574 roleKey := "role"
1575 if depth != 0 {
1576 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001577 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001578 role, ok := parts[roleKey]
1579 if !ok {
1580 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1581 }
1582
1583 s, ok := s.Schema[role]
1584 if !ok {
1585 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1586 }
1587 rvParts = append(rvParts, role)
1588 delete(parts, roleKey)
1589
1590 for _, key := range s.Keys {
1591 value, ok := parts[key]
1592 if !ok {
1593 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1594 }
1595 rvParts = append(rvParts, value)
1596 delete(parts, key)
1597 }
1598
1599 if len(s.RecurseRoles) > 0 {
1600 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1601 subRole, ok := parts[subRoleKey]
1602 if !ok {
1603 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1604 }
1605 rvParts = append(rvParts, subRole)
1606 delete(parts, subRoleKey)
1607 found := false
1608 for _, recurseRole := range s.RecurseRoles {
1609 if recurseRole == subRole {
1610 found = true
1611 var err error
1612 parts, err = process(depth+1, parts)
1613 if err != nil {
1614 return nil, err
1615 }
1616 break
1617 }
1618 }
1619 if !found {
1620 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1621 }
1622 }
1623 for _, key := range s.OptionalKeys {
1624 if value, ok := parts[key]; ok {
1625 rvParts = append(rvParts, value)
1626 delete(parts, key)
1627 }
1628 }
1629 if len(parts) > 0 {
1630 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1631 }
1632 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001633 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001634
1635 // Copy the parts map, so that we can modify at will.
1636 partsCpy := make(map[string]string, len(parts))
1637 for k, v := range parts {
1638 partsCpy[k] = v
1639 }
1640 if _, err := process(0, partsCpy); err != nil {
1641 return "", err
borenetdb182c72016-09-30 12:53:12 -07001642 }
1643 return strings.Join(rvParts, s.Sep), nil
1644}