blob: ffb71e3250b5c67e16e8197b3d4828ace78eb588 [file] [log] [blame]
borenetdb182c72016-09-30 12:53:12 -07001// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7/*
8 Generate the tasks.json file.
9*/
10
11import (
borenetdb182c72016-09-30 12:53:12 -070012 "encoding/json"
Eric Boren27225492017-02-01 15:56:55 -050013 "flag"
borenetdb182c72016-09-30 12:53:12 -070014 "fmt"
Eric Boren27225492017-02-01 15:56:55 -050015 "io/ioutil"
borenetdb182c72016-09-30 12:53:12 -070016 "os"
17 "path"
Eric Boren7e3a3642017-06-14 15:25:31 -040018 "path/filepath"
Eric Boren27225492017-02-01 15:56:55 -050019 "regexp"
Eric Boren7e3a3642017-06-14 15:25:31 -040020 "runtime"
borenetdb182c72016-09-30 12:53:12 -070021 "sort"
Kevin Lubick32f318b2017-10-17 13:40:52 -040022 "strconv"
borenetdb182c72016-09-30 12:53:12 -070023 "strings"
Eric Boren4b254b92016-11-08 12:55:32 -050024 "time"
borenetdb182c72016-09-30 12:53:12 -070025
Eric Borencb0b98b2018-06-08 08:25:57 -040026 "github.com/golang/glog"
Eric Boren7e3a3642017-06-14 15:25:31 -040027 "go.skia.org/infra/go/sklog"
borenetdb182c72016-09-30 12:53:12 -070028 "go.skia.org/infra/go/util"
29 "go.skia.org/infra/task_scheduler/go/specs"
30)
31
32const (
Kevin Lubick814b1492017-11-29 14:45:14 -050033 BUNDLE_RECIPES_NAME = "Housekeeper-PerCommit-BundleRecipes"
Stephan Altmueller88df8d22018-03-07 14:44:44 -050034 ISOLATE_GCLOUD_LINUX_NAME = "Housekeeper-PerCommit-IsolateGCloudLinux"
Eric Boren9d834582018-08-03 14:29:03 -040035 ISOLATE_GO_DEPS_NAME = "Housekeeper-PerCommit-IsolateGoDeps"
Stephan Altmueller88df8d22018-03-07 14:44:44 -050036 ISOLATE_GO_LINUX_NAME = "Housekeeper-PerCommit-IsolateGoLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050037 ISOLATE_SKIMAGE_NAME = "Housekeeper-PerCommit-IsolateSkImage"
38 ISOLATE_SKP_NAME = "Housekeeper-PerCommit-IsolateSKP"
39 ISOLATE_SVG_NAME = "Housekeeper-PerCommit-IsolateSVG"
40 ISOLATE_NDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidNDKLinux"
Stephan Altmueller2a552172018-02-20 11:40:25 -050041 ISOLATE_SDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidSDKLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050042 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
43 ISOLATE_WIN_VULKAN_SDK_NAME = "Housekeeper-PerCommit-IsolateWinVulkanSDK"
Eric Boren8b3f9e62017-04-04 09:06:16 -040044
Ben Wagner1676ec22018-04-06 17:39:06 -040045 DEFAULT_OS_DEBIAN = "Debian-9.4"
46 DEFAULT_OS_LINUX_GCE = DEFAULT_OS_DEBIAN
Ben Wagnere8d2a452018-08-06 10:00:54 -040047 DEFAULT_OS_MAC = "Mac-10.13.6"
Eric Boren170c39c2017-11-15 11:22:57 -050048 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
49 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070050
Eric Boreneb702382018-04-19 09:36:45 -040051 DEFAULT_PROJECT = "skia"
52
Ben Wagner297e86b2018-05-14 12:38:09 -040053 // Small is a 2-core machine.
54 // TODO(dogben): Would n1-standard-1 or n1-standard-2 be sufficient?
Ben Wagnere99a4b12018-05-04 11:18:01 -040055 MACHINE_TYPE_SMALL = "n1-highmem-2"
Ben Wagner297e86b2018-05-14 12:38:09 -040056 // Medium is a 16-core machine
57 MACHINE_TYPE_MEDIUM = "n1-standard-16"
58 // Large is a 64-core machine. (We use "highcpu" because we don't need more than 57GB memory for
59 // any of our tasks.)
Ben Wagnere99a4b12018-05-04 11:18:01 -040060 MACHINE_TYPE_LARGE = "n1-highcpu-64"
61
Eric Boren9599b0f2018-04-17 15:55:57 -040062 // Swarming output dirs.
63 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
64 OUTPUT_BUILD = "build"
65 OUTPUT_COVERAGE = "coverage"
66 OUTPUT_TEST = "test"
67 OUTPUT_PERF = "perf"
68
borenetdb182c72016-09-30 12:53:12 -070069 // Name prefix for upload jobs.
70 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040071
72 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
73 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
74 SERVICE_ACCOUNT_CT_SKPS = "skia-external-ct-skps@skia-swarming-bots.iam.gserviceaccount.com"
75 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
76 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
77 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
78 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
79 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
80 SERVICE_ACCOUNT_UPLOAD_COVERAGE = "skia-external-coverage-uploade@skia-swarming-bots.iam.gserviceaccount.com"
81 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
82 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070083)
84
85var (
86 // "Constants"
87
Eric Boren27225492017-02-01 15:56:55 -050088 // Top-level list of all jobs to run at each commit; loaded from
89 // jobs.json.
90 JOBS []string
91
Eric Boren27225492017-02-01 15:56:55 -050092 // General configuration information.
93 CONFIG struct {
Kevin Lubickc795a4c2017-10-09 15:26:19 -040094 GsBucketCoverage string `json:"gs_bucket_coverage"`
95 GsBucketGm string `json:"gs_bucket_gm"`
Stephan Altmüller64cc5762018-08-02 08:51:38 +020096 GoldHashesURL string `json:"gold_hashes_url"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040097 GsBucketNano string `json:"gs_bucket_nano"`
Yuqian Li2ebf3d12017-10-24 09:43:21 -040098 GsBucketCalm string `json:"gs_bucket_calm"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040099 NoUpload []string `json:"no_upload"`
100 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -0700101 }
102
Eric Boreneb702382018-04-19 09:36:45 -0400103 // alternateProject can be set in an init function to override the default project ID.
104 alternateProject string
105
Ben Wagner053d0462018-04-17 12:45:29 -0400106 // alternateServiceAccount can be set in an init function to override the normal service accounts.
107 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
108 // should be used, or uses sklog.Fatal to indicate a problem.
109 alternateServiceAccount func(serviceAccountEnum string) string
110
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400111 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
112 // dimensions for the given task.
113 alternateSwarmDimensions func(parts map[string]string) []string
114
Eric Borenfd4d60e2017-09-15 10:35:44 -0400115 // internalHardwareLabelFn can be set in an init function to provide an
116 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400117 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400118
borenetdb182c72016-09-30 12:53:12 -0700119 // Defines the structure of job names.
120 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500121
Eric Boren5cb5c742018-04-27 13:14:38 -0400122 // Named caches used by tasks.
123 CACHES_GIT = []*specs.Cache{
124 &specs.Cache{
125 Name: "git",
126 Path: "cache/git",
127 },
128 &specs.Cache{
129 Name: "git_cache",
130 Path: "cache/git_cache",
131 },
132 }
133 CACHES_WORKDIR = []*specs.Cache{
134 &specs.Cache{
135 Name: "work",
136 Path: "cache/work",
137 },
138 }
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400139 CACHES_DOCKER = []*specs.Cache{
140 &specs.Cache{
141 Name: "docker",
142 Path: "cache/docker",
143 },
144 }
Ben Wagner702fe012018-06-15 09:19:13 -0400145 // Versions of the following copied from
146 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template_canary.json#42
147 // to test the fix for chromium:836196.
148 // (In the future we may want to use versions from
149 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template.json#42)
Eric Boren9599b0f2018-04-17 15:55:57 -0400150 // TODO(borenet): Roll these versions automatically!
151 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
152 &specs.CipdPackage{
153 Name: "infra/tools/luci/vpython/${platform}",
154 Path: "cipd_bin_packages",
Eric Borenb33f9eb2018-08-03 10:31:24 -0400155 Version: "git_revision:b6cdec8586c9f8d3d728b1bc0bd4331330ba66fc",
Eric Boren9599b0f2018-04-17 15:55:57 -0400156 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400157 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400158
Eric Borenaa037522018-06-18 16:02:15 -0400159 CIPD_PKGS_CPYTHON = []*specs.CipdPackage{
160 &specs.CipdPackage{
161 Name: "infra/python/cpython/${platform}",
162 Path: "cipd_bin_packages",
163 Version: "version:2.7.14.chromium14",
164 },
165 }
166
Eric Boren9599b0f2018-04-17 15:55:57 -0400167 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
168 &specs.CipdPackage{
169 Name: "infra/tools/luci/kitchen/${platform}",
170 Path: ".",
Ben Wagner702fe012018-06-15 09:19:13 -0400171 Version: "git_revision:546aae39f1fb9dce9add528e2011afa574535ecd",
Eric Boren9599b0f2018-04-17 15:55:57 -0400172 },
173 &specs.CipdPackage{
Ben Wagnercd7ace22018-06-11 15:48:35 -0400174 Name: "infra/tools/luci-auth/${platform}",
Eric Boren9599b0f2018-04-17 15:55:57 -0400175 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400176 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400177 },
178 }, CIPD_PKGS_PYTHON...)
179
180 CIPD_PKGS_GIT = []*specs.CipdPackage{
181 &specs.CipdPackage{
182 Name: "infra/git/${platform}",
183 Path: "cipd_bin_packages",
Eric Borene42cef52018-06-20 07:11:38 -0400184 Version: "version:2.17.1.chromium15",
Eric Boren9599b0f2018-04-17 15:55:57 -0400185 },
186 &specs.CipdPackage{
187 Name: "infra/tools/git/${platform}",
188 Path: "cipd_bin_packages",
Eric Boren3f13bcb2018-06-15 07:39:36 -0400189 Version: "git_revision:0ae21738597e5601ba90372315145fec18582fc4",
Eric Boren9599b0f2018-04-17 15:55:57 -0400190 },
191 &specs.CipdPackage{
192 Name: "infra/tools/luci/git-credential-luci/${platform}",
193 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400194 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400195 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000196 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400197
Eric Boren9599b0f2018-04-17 15:55:57 -0400198 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
199 &specs.CipdPackage{
200 Name: "infra/gsutil",
201 Path: "cipd_bin_packages",
202 Version: "version:4.28",
203 },
204 }
205
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400206 CIPD_PKGS_XCODE = []*specs.CipdPackage{
207 // https://chromium.googlesource.com/chromium/tools/build/+/e19b7d9390e2bb438b566515b141ed2b9ed2c7c2/scripts/slave/recipe_modules/ios/api.py#317
208 // This package is really just an installer for XCode.
209 &specs.CipdPackage{
Ben Wagner66760792018-08-09 12:52:16 -0400210 Name: "infra/tools/mac_toolchain/${platform}",
211 Path: "mac_toolchain",
212 // When this is updated, also update
213 // https://skia.googlesource.com/skcms.git/+/f1e2b45d18facbae2dece3aca673fe1603077846/infra/bots/gen_tasks.go#56
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400214 Version: "git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a",
215 },
216 }
217
Eric Boren27225492017-02-01 15:56:55 -0500218 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500219 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.")
220 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
221 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500222 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700223)
224
Eric Boreneb702382018-04-19 09:36:45 -0400225// Build the LogDog annotation URL.
226func logdogAnnotationUrl() string {
227 project := DEFAULT_PROJECT
228 if alternateProject != "" {
229 project = alternateProject
230 }
231 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
232}
233
Eric Boren9599b0f2018-04-17 15:55:57 -0400234// Create a properties JSON string.
235func props(p map[string]string) string {
236 d := make(map[string]interface{}, len(p)+1)
237 for k, v := range p {
238 d[k] = interface{}(v)
239 }
240 d["$kitchen"] = struct {
241 DevShell bool `json:"devshell"`
242 GitAuth bool `json:"git_auth"`
243 }{
244 DevShell: true,
245 GitAuth: true,
246 }
247
248 j, err := json.Marshal(d)
249 if err != nil {
250 sklog.Fatal(err)
251 }
252 return strings.Replace(string(j), "\\u003c", "<", -1)
253}
254
255// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
256// recipe.
257func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
258 if serviceAccount != "" && alternateServiceAccount != nil {
259 serviceAccount = alternateServiceAccount(serviceAccount)
260 }
261 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
Eric Borenaa037522018-06-18 16:02:15 -0400262 if strings.Contains(name, "Win") {
263 cipd = append(cipd, CIPD_PKGS_CPYTHON...)
264 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400265 properties := map[string]string{
266 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
267 "buildername": name,
268 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400269 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400270 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
271 "patch_set": specs.PLACEHOLDER_PATCHSET,
272 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
273 "repository": specs.PLACEHOLDER_REPO,
274 "revision": specs.PLACEHOLDER_REVISION,
275 "swarm_out_dir": outputDir,
276 }
277 for k, v := range extraProps {
278 properties[k] = v
279 }
280 var outputs []string = nil
281 if outputDir != OUTPUT_NONE {
282 outputs = []string{outputDir}
283 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400284 task := &specs.TaskSpec{
285 Caches: []*specs.Cache{
286 &specs.Cache{
287 Name: "vpython",
288 Path: "cache/vpython",
289 },
290 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400291 CipdPackages: cipd,
292 Command: []string{
293 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
294 "-checkout-dir", "recipe_bundle",
295 "-mode", "swarming",
296 "-luci-system-account", "system",
297 "-cache-dir", "cache",
298 "-temp-dir", "tmp",
299 "-known-gerrit-host", "android.googlesource.com",
300 "-known-gerrit-host", "boringssl.googlesource.com",
301 "-known-gerrit-host", "chromium.googlesource.com",
302 "-known-gerrit-host", "dart.googlesource.com",
303 "-known-gerrit-host", "fuchsia.googlesource.com",
304 "-known-gerrit-host", "go.googlesource.com",
305 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400306 "-known-gerrit-host", "skia.googlesource.com",
307 "-known-gerrit-host", "webrtc.googlesource.com",
308 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
309 "-workdir", ".",
310 "-recipe", recipe,
311 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400312 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400313 },
314 Dependencies: []string{BUNDLE_RECIPES_NAME},
315 Dimensions: dimensions,
316 EnvPrefixes: map[string][]string{
Ben Wagnerd709a852018-08-31 12:56:31 -0400317 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
Eric Boren7c42e012018-08-20 09:45:02 -0400318 "VPYTHON_VIRTUALENV_ROOT": []string{"cache/vpython"},
Eric Boren9599b0f2018-04-17 15:55:57 -0400319 },
320 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400321 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400322 },
323 Isolate: relpath(isolate),
324 Outputs: outputs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400325 ServiceAccount: serviceAccount,
326 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400327 timeout(task, time.Hour)
328 return task
Eric Boren9599b0f2018-04-17 15:55:57 -0400329}
330
Eric Borenfd4d60e2017-09-15 10:35:44 -0400331// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400332func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400333 if internalHardwareLabelFn != nil {
334 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400335 }
336 return nil
337}
338
Eric Boren27225492017-02-01 15:56:55 -0500339// linuxGceDimensions are the Swarming dimensions for Linux GCE
340// instances.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400341func linuxGceDimensions(machineType string) []string {
Eric Boren27225492017-02-01 15:56:55 -0500342 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400343 // Specify CPU to avoid running builds on bots with a more unique CPU.
344 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500345 "gpu:none",
Ben Wagner82a33422018-04-26 18:02:23 -0400346 // Currently all Linux GCE tasks run on 16-CPU machines.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400347 fmt.Sprintf("machine_type:%s", machineType),
Eric Boren170c39c2017-11-15 11:22:57 -0500348 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500349 fmt.Sprintf("pool:%s", CONFIG.Pool),
350 }
351}
352
borenetdb182c72016-09-30 12:53:12 -0700353// deriveCompileTaskName returns the name of a compile task based on the given
354// job name.
355func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500356 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500357 return "Build-Debian9-GCC-x86_64-Release"
358 } else if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400359 return "Build-Debian9-GCC-x86_64-Release-Shared"
Yuqian Li4a577af2018-01-05 11:13:43 -0500360 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700361 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400362 ec := []string{}
363 if val := parts["extra_config"]; val != "" {
364 ec = strings.Split(val, "_")
Mike Kleinc24e0c12018-08-17 13:24:51 -0400365 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 -0400366 keep := make([]string, 0, len(ec))
367 for _, part := range ec {
368 if !util.In(part, ignore) {
369 keep = append(keep, part)
370 }
371 }
372 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400373 }
borenetdb182c72016-09-30 12:53:12 -0700374 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400375 if !util.In("Android", ec) {
376 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700377 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400378 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500379 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400380 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400381 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400382 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400383 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400384 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700385 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400386 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700387 task_os = "Mac"
388 } else if strings.Contains(task_os, "Win") {
389 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400390 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
391 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700392 }
Eric Boren50831302016-11-18 13:10:51 -0500393 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700394 "role": "Build",
395 "os": task_os,
396 "compiler": parts["compiler"],
397 "target_arch": parts["arch"],
398 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500399 }
Eric Borene8b38ab2018-06-08 12:37:53 -0400400 if strings.Contains(jobName, "-CT_") {
401 ec = []string{"Static"}
402 }
Kevin Lubick92c91712018-08-09 10:00:02 -0400403 if strings.Contains(jobName, "PathKit") {
404 ec = []string{"PathKit"}
405 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400406 if len(ec) > 0 {
407 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500408 }
409 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700410 if err != nil {
411 glog.Fatal(err)
412 }
413 return name
414 } else {
415 return jobName
416 }
417}
418
419// swarmDimensions generates swarming bot dimensions for the given task.
420func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400421 if alternateSwarmDimensions != nil {
422 return alternateSwarmDimensions(parts)
423 }
424 return defaultSwarmDimensions(parts)
425}
426
427// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
428func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700429 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500430 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700431 }
432 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400433 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400434 "Android": "Android",
435 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400436 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400437 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500438 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400439 "Ubuntu14": DEFAULT_OS_UBUNTU,
Eric Boren810c2b62017-07-11 08:11:15 -0400440 "Ubuntu17": "Ubuntu-17.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500441 "Win": DEFAULT_OS_WIN,
Ben Wagner4c3b63e2018-08-02 17:07:58 -0400442 "Win10": "Windows-10-17134.191",
Kevin Lubick291547d2017-03-21 09:25:34 -0400443 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500444 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400445 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400446 "Win8": "Windows-8.1-SP0",
Stephan Altmueller0edb9822018-08-16 18:11:57 -0400447 "iOS": "iOS-11.4.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500448 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400449 if !ok {
450 glog.Fatalf("Entry %q not found in OS mapping.", os)
451 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500452 if os == "Win10" && parts["model"] == "Golo" {
Ben Wagnerf6148b62018-03-15 13:53:25 -0400453 // ChOps-owned machines have Windows 10 v1709, but a slightly different version than Skolo.
454 d["os"] = "Windows-10-16299.309"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500455 }
Ben Wagnere1c37a72018-04-24 16:59:48 -0400456 if d["os"] == DEFAULT_OS_WIN {
457 // TODO(dogben): Temporarily add image dimension during upgrade.
Ben Wagner7a879622018-07-18 10:14:23 -0400458 d["image"] = "windows-server-2016-dc-v20180710"
Ben Wagnere1c37a72018-04-24 16:59:48 -0400459 }
borenetdb182c72016-09-30 12:53:12 -0700460 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400461 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700462 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400463 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400464 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700465 // For Android, the device type is a better dimension
466 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400467 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400468 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500469 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500470 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagnerc72c9482018-06-11 13:48:44 -0400471 "GalaxyS7_G930FD": {"herolte", "R16NW_G930FXXU2EREM"}, // This is Oreo.
Ben Wagner8d8f45d2018-06-04 17:32:04 -0400472 "MotoG4": {"athene", "NPJS25.93-14.7-8"},
Ben Wagner7efa13d2018-08-28 15:52:38 -0400473 "NVIDIA_Shield": {"foster", "OPR6.170623.010"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500474 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500475 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500476 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner2a510c92018-04-11 12:36:56 -0400477 "NexusPlayer": {"fugu", "OPR2.170623.027"},
Kevin Lubick8fe1b042018-08-21 13:00:14 -0400478 "Pixel": {"sailfish", "PPR1.180610.009"},
Kevin Lubick1118cfd2018-08-24 10:24:54 -0400479 "Pixel2XL": {"taimen", "PPR1.180610.009"},
Ben Wagner36682782017-06-14 10:01:45 -0400480 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500481 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400482 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500483 }
Eric Boren4b254b92016-11-08 12:55:32 -0500484 d["device_type"] = deviceInfo[0]
485 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700486 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400487 device, ok := map[string]string{
Eric Boren792079c2016-11-09 14:03:20 -0500488 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400489 "iPhone6": "iPhone7,2",
490 "iPhone7": "iPhone9,1",
491 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700492 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400493 if !ok {
494 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
495 }
496 d["device"] = device
Ben Wagnerd26e4462018-05-22 10:46:15 -0400497 } else if strings.Contains(parts["extra_config"], "SwiftShader") {
498 if parts["model"] != "GCE" || d["os"] != DEFAULT_OS_DEBIAN || parts["cpu_or_gpu_value"] != "SwiftShader" {
499 glog.Fatalf("Please update defaultSwarmDimensions for SwiftShader %s %s %s.", parts["os"], parts["model"], parts["cpu_or_gpu_value"])
500 }
501 d["cpu"] = "x86-64-Haswell_GCE"
502 d["os"] = DEFAULT_OS_LINUX_GCE
503 d["machine_type"] = MACHINE_TYPE_SMALL
borenetdb182c72016-09-30 12:53:12 -0700504 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400505 modelMapping, ok := map[string]map[string]string{
506 "AVX": {
Ben Wagner7ea54282018-08-22 14:07:48 -0400507 "Golo": "x86-64-E5-2670",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400508 },
509 "AVX2": {
Ben Wagner35eb7fa2018-08-06 11:27:17 -0400510 "GCE": "x86-64-Haswell_GCE",
511 "MacBookPro11.5": "x86-64-i7-4870HQ",
512 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400513 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400514 "AVX512": {
515 "GCE": "x86-64-Skylake_GCE",
516 },
borenetdb182c72016-09-30 12:53:12 -0700517 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400518 if !ok {
519 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
520 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400521 cpu, ok := modelMapping[parts["model"]]
522 if !ok {
523 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700524 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400525 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500526 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
527 d["os"] = DEFAULT_OS_LINUX_GCE
528 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400529 if parts["model"] == "GCE" && d["cpu"] == "x86-64-Haswell_GCE" {
Ben Wagner27d5a362018-05-09 15:37:34 -0400530 // Coverage gets slower with more cores.
531 if strings.Contains(parts["extra_config"], "Coverage") {
Ben Wagner297e86b2018-05-14 12:38:09 -0400532 d["machine_type"] = MACHINE_TYPE_SMALL
533 } else {
534 d["machine_type"] = MACHINE_TYPE_MEDIUM
Ben Wagner27d5a362018-05-09 15:37:34 -0400535 }
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500536 }
borenetdb182c72016-09-30 12:53:12 -0700537 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400538 if strings.Contains(parts["os"], "Win") {
539 gpu, ok := map[string]string{
Ben Wagnerf6148b62018-03-15 13:53:25 -0400540 "GT610": "10de:104a-23.21.13.9101",
Ben Wagnerce1db862018-08-06 14:28:49 -0400541 "GTX660": "10de:11c0-24.21.13.9882",
542 "GTX960": "10de:1401-24.21.13.9882",
Greg Daniel900e5c82018-08-28 10:59:24 -0400543 "IntelHD4400": "8086:0a16-20.19.15.4963",
544 "IntelIris540": "8086:1926-24.20.100.6229",
545 "IntelIris6100": "8086:162b-20.19.15.4963",
Ben Wagner1f0fb092018-08-27 18:09:52 -0400546 "RadeonHD7770": "1002:683d-24.20.13001.1010",
547 "RadeonR9M470X": "1002:6646-24.20.13001.1010",
Ben Wagnerf6148b62018-03-15 13:53:25 -0400548 "QuadroP400": "10de:1cb3-23.21.13.9103",
Ben Wagner1d060782017-06-14 10:34:18 -0400549 }[parts["cpu_or_gpu_value"]]
550 if !ok {
551 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
552 }
553 d["gpu"] = gpu
Eric Borenbb198fb2017-06-28 11:45:54 -0400554 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400555 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400556 // Intel drivers come from CIPD, so no need to specify the version here.
557 "IntelBayTrail": "8086:0f31",
558 "IntelHD2000": "8086:0102",
559 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500560 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400561 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400562 }[parts["cpu_or_gpu_value"]]
563 if !ok {
564 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
565 }
566 d["gpu"] = gpu
567 } else if strings.Contains(parts["os"], "Mac") {
568 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500569 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500570 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400571 "IntelIris5100": "8086:0a2e",
Ben Wagnereeeb3282018-05-15 16:45:42 -0400572 "RadeonHD8870M": "1002:6821-4.0.20-3.2.8",
Ben Wagner1d060782017-06-14 10:34:18 -0400573 }[parts["cpu_or_gpu_value"]]
574 if !ok {
575 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
576 }
577 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500578 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
579 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
580 // Run all tasks on Golo machines for now.
581 d["cpu"] = "x86-64-i7-4578U"
582 }
Ben Wagner1d060782017-06-14 10:34:18 -0400583 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500584 version, ok := map[string]string{
Kevin Lubickff8387f2018-05-01 10:43:35 -0400585 "MaliT604": "10575.22.0",
Kevin Lubicke114e592018-05-01 08:53:52 -0400586 "MaliT764": "10575.22.0",
Kevin Lubicke467d4e2018-05-01 13:12:58 -0400587 "MaliT860": "10575.22.0",
588 "PowerVRGX6250": "10575.22.0",
589 "TegraK1": "10575.22.0",
590 "IntelHDGraphics615": "10575.22.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400591 }[parts["cpu_or_gpu_value"]]
592 if !ok {
593 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
594 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500595 d["gpu"] = parts["cpu_or_gpu_value"]
596 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400597 } else {
598 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500599 }
borenetdb182c72016-09-30 12:53:12 -0700600 }
601 } else {
602 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400603 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubickf14a3c02018-08-22 09:35:32 -0400604 if strings.Contains(parts["extra_config"], "PathKit") {
605 // The build isn't really parallelized for pathkit, so
606 // the bulky machines don't buy us much. All we really need is
607 // docker, which was manually installed on the MEDIUM and LARGE
608 // Debian machines and should be on any newly-created Debian
609 // machines (after Aug 2018).
610 return linuxGceDimensions(MACHINE_TYPE_MEDIUM)
611 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400612 // Use many-core machines for Build tasks.
613 return linuxGceDimensions(MACHINE_TYPE_LARGE)
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500614 } else if d["os"] == DEFAULT_OS_WIN {
615 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400616 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagnere99a4b12018-05-04 11:18:01 -0400617 // Use many-core machines for Build tasks.
618 d["machine_type"] = MACHINE_TYPE_LARGE
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500619 } else if d["os"] == DEFAULT_OS_MAC {
620 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400621 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400622 }
borenetdb182c72016-09-30 12:53:12 -0700623 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400624
Ben Wagnerd709a852018-08-31 12:56:31 -0400625 if parts["cpu_or_gpu_value"] == "QuadroP400" {
626 // Specify "rack" dimension for consistent test results.
627 // See https://bugs.chromium.org/p/chromium/issues/detail?id=784662&desc=2#c34
628 // for more context.
629 d["rack"] = "1"
630 }
631
borenetdb182c72016-09-30 12:53:12 -0700632 rv := make([]string, 0, len(d))
633 for k, v := range d {
634 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
635 }
636 sort.Strings(rv)
637 return rv
638}
639
Eric Boren7e3a3642017-06-14 15:25:31 -0400640// relpath returns the relative path to the given file from the config file.
641func relpath(f string) string {
642 _, filename, _, _ := runtime.Caller(0)
643 dir := path.Dir(filename)
644 rel := dir
645 if *cfgFile != "" {
646 rel = path.Dir(*cfgFile)
647 }
648 rv, err := filepath.Rel(rel, path.Join(dir, f))
649 if err != nil {
650 sklog.Fatal(err)
651 }
652 return rv
653}
654
Eric Boren8b3f9e62017-04-04 09:06:16 -0400655// bundleRecipes generates the task to bundle and isolate the recipes.
656func bundleRecipes(b *specs.TasksCfgBuilder) string {
Eric Boren63924422018-06-21 09:02:30 -0400657 pkgs := append([]*specs.CipdPackage{}, CIPD_PKGS_GIT...)
658 pkgs = append(pkgs, CIPD_PKGS_PYTHON...)
Eric Boren8b3f9e62017-04-04 09:06:16 -0400659 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren63924422018-06-21 09:02:30 -0400660 CipdPackages: pkgs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400661 Command: []string{
662 "/bin/bash", "skia/infra/bots/bundle_recipes.sh", specs.PLACEHOLDER_ISOLATED_OUTDIR,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400663 },
Ben Wagnere99a4b12018-05-04 11:18:01 -0400664 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400665 EnvPrefixes: map[string][]string{
666 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
667 },
Ben Wagnerc062b6b2018-07-24 17:10:46 -0400668 Isolate: relpath("swarm_recipe.isolate"),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400669 })
670 return BUNDLE_RECIPES_NAME
671}
672
Kevin Lubick07072942017-05-11 13:35:23 -0400673type isolateAssetCfg struct {
Eric Boren9599b0f2018-04-17 15:55:57 -0400674 cipdPkg string
675 path string
Kevin Lubick07072942017-05-11 13:35:23 -0400676}
677
678var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500679 ISOLATE_GCLOUD_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400680 cipdPkg: "gcloud_linux",
681 path: "gcloud_linux",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500682 },
Eric Boren9d834582018-08-03 14:29:03 -0400683 ISOLATE_GO_DEPS_NAME: {
684 cipdPkg: "go_deps",
685 path: "go_deps",
686 },
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500687 ISOLATE_GO_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400688 cipdPkg: "go",
689 path: "go",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500690 },
Kevin Lubick07072942017-05-11 13:35:23 -0400691 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400692 cipdPkg: "skimage",
693 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400694 },
695 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400696 cipdPkg: "skp",
697 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400698 },
699 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400700 cipdPkg: "svg",
701 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400702 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500703 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400704 cipdPkg: "android_ndk_linux",
705 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500706 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500707 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400708 cipdPkg: "android_sdk_linux",
709 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500710 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500711 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400712 cipdPkg: "win_toolchain",
713 path: "t",
Kevin Lubick814b1492017-11-29 14:45:14 -0500714 },
715 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400716 cipdPkg: "win_vulkan_sdk",
717 path: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500718 },
Kevin Lubick07072942017-05-11 13:35:23 -0400719}
720
Eric Boren9599b0f2018-04-17 15:55:57 -0400721// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400722func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400723 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400724 b.MustAddTask(name, &specs.TaskSpec{
725 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400726 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400727 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400728 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400729 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400730 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400731 })
732 return name
733}
734
Kevin Lubick90189522017-05-15 08:30:27 -0400735// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
736// This allows us to save time on I/O bound bots, like the RPIs.
737func getIsolatedCIPDDeps(parts map[string]string) []string {
738 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400739 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
740 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400741 rpiOS := []string{"Android", "ChromeOS", "iOS"}
742
743 if o := parts["os"]; strings.Contains(o, "Chromecast") {
744 // Chromecasts don't have enough disk space to fit all of the content,
745 // so we do a subset of the skps.
746 deps = append(deps, ISOLATE_SKP_NAME)
747 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
748 // Skpbench only needs skps
749 deps = append(deps, ISOLATE_SKP_NAME)
750 } else if util.In(o, rpiOS) {
751 deps = append(deps, ISOLATE_SKP_NAME)
752 deps = append(deps, ISOLATE_SVG_NAME)
753 deps = append(deps, ISOLATE_SKIMAGE_NAME)
754 }
755
756 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400757}
758
Eric Boren5cb5c742018-04-27 13:14:38 -0400759// usesGit adds attributes to tasks which use git.
760func usesGit(t *specs.TaskSpec, name string) {
761 t.Caches = append(t.Caches, CACHES_GIT...)
762 if !strings.Contains(name, "NoDEPS") {
763 t.Caches = append(t.Caches, CACHES_WORKDIR...)
764 }
765 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
766}
767
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400768// usesDocker adds attributes to tasks which use docker.
769func usesDocker(t *specs.TaskSpec, name string) {
770 // currently, just the WASM (using EMCC) builder uses Docker.
771 if strings.Contains(name, "EMCC") {
772 t.Caches = append(t.Caches, CACHES_DOCKER...)
773 }
774}
775
Eric Boren5cb5c742018-04-27 13:14:38 -0400776// timeout sets the timeout(s) for this task.
777func timeout(task *specs.TaskSpec, timeout time.Duration) {
778 task.ExecutionTimeout = timeout
779 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
780}
781
borenetdb182c72016-09-30 12:53:12 -0700782// compile generates a compile task. Returns the name of the last task in the
783// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700784func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400785 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400786 usesGit(task, name)
Kevin Lubick30cc00c2018-08-03 10:26:00 -0400787 usesDocker(task, name)
borenetdb182c72016-09-30 12:53:12 -0700788
789 // Android bots require a toolchain.
790 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500791 if parts["extra_config"] == "Android_Framework" {
792 // Do not need a toolchain when building the
793 // Android Framework.
794 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400795 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400796 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400797 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
798 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400799 task.CipdPackages = append(task.CipdPackages, pkg)
borenetdb182c72016-09-30 12:53:12 -0700800 } else {
Eric Boren9599b0f2018-04-17 15:55:57 -0400801 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500802 if strings.Contains(name, "SKQP") {
Eric Boren9d834582018-08-03 14:29:03 -0400803 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_SDK_LINUX_NAME), isolateCIPDAsset(b, ISOLATE_GO_LINUX_NAME), isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500804 }
borenetdb182c72016-09-30 12:53:12 -0700805 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500806 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400807 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
808 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400809 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400810 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400811 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400812 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400813 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400814 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
815 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400816 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400817 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500818 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400819 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500820 }
821 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400822 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500823 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400824 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
825 if parts["compiler"] != "GCC" {
826 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
827 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400828 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400829 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400830 if strings.Contains(name, "SwiftShader") {
831 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
832 }
Ben Wagner55a7d222018-06-28 20:41:04 -0400833 if strings.Contains(name, "OpenCL") {
834 task.CipdPackages = append(task.CipdPackages,
835 b.MustGetCipdPackageFromAsset("opencl_headers"),
836 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
837 )
838 }
Mike Klein27dcee12016-11-09 16:31:42 -0500839 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400840 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400841 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400842 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400843 }
borenetdb182c72016-09-30 12:53:12 -0700844 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400845 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700846 }
Ben Wagner30a4e3d2018-08-07 16:58:15 -0400847 if strings.Contains(name, "OpenCL") {
848 task.CipdPackages = append(task.CipdPackages,
849 b.MustGetCipdPackageFromAsset("opencl_headers"),
850 )
851 }
Ben Wagnercdfa16d2018-08-03 10:07:47 -0400852 } else if strings.Contains(name, "Mac") {
853 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_XCODE...)
854 task.Caches = append(task.Caches, &specs.Cache{
855 Name: "xcode",
856 Path: "cache/Xcode.app",
857 })
858 if strings.Contains(name, "CommandBuffer") {
859 timeout(task, 2*time.Hour)
860 }
861 if strings.Contains(name, "MoltenVK") {
862 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("moltenvk"))
863 }
Chris Dalton2b937f52018-05-17 10:17:10 -0600864 }
865
Ben Wagneradeb75d2018-04-19 21:48:55 -0400866 task.MaxAttempts = 1
867
Eric Borenbd2e1f12018-04-17 11:28:46 +0000868 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400869 b.MustAddTask(name, task)
870
Eric Boren8615fe52016-12-12 14:30:12 -0500871 // All compile tasks are runnable as their own Job. Assert that the Job
872 // is listed in JOBS.
873 if !util.In(name, JOBS) {
874 glog.Fatalf("Job %q is missing from the JOBS list!", name)
875 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500876
877 // Upload the skiaserve binary only for Linux Android compile bots.
878 // See skbug.com/7399 for context.
879 if parts["configuration"] == "Release" &&
880 parts["extra_config"] == "Android" &&
881 !strings.Contains(parts["os"], "Win") &&
882 !strings.Contains(parts["os"], "Mac") {
883 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400884 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 -0400885 task.Dependencies = append(task.Dependencies, name)
886 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500887 return uploadName
888 }
889
borenetdb182c72016-09-30 12:53:12 -0700890 return name
891}
892
893// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
894// task in the generated chain of tasks, which the Job should add as a
895// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000896func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry5a12d052018-05-15 17:19:42 -0400897 dims := []string{
898 "pool:SkiaCT",
899 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
900 }
901 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400902 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400903 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400904 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren5cb5c742018-04-27 13:14:38 -0400905 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400906 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700907 return name
908}
909
910// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
911// generated chain of tasks, which the Job should add as a dependency.
Eric Borene8b38ab2018-06-08 12:37:53 -0400912func ctSKPs(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400913 dims := []string{
914 "pool:SkiaCT",
915 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
916 }
Eric Borene8b38ab2018-06-08 12:37:53 -0400917 task := kitchenTask(name, "ct_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_CT_SKPS, dims, nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400918 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400919 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Eric Borene8b38ab2018-06-08 12:37:53 -0400920 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400921 timeout(task, 24*time.Hour)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400922 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400923 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700924 return name
925}
926
Eric Borenf7928b42017-07-28 07:35:28 -0400927// checkGeneratedFiles verifies that no generated SKSL files have been edited
928// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000929func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400930 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 -0400931 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400932 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400933 return name
934}
935
borenetdb182c72016-09-30 12:53:12 -0700936// housekeeper generates a Housekeeper task. Returns the name of the last task
937// in the generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000938func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400939 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400940 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400941 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
942 task.Dependencies = append(task.Dependencies, compileTaskName)
943 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700944 return name
945}
946
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500947// bookmaker generates a Bookmaker task. Returns the name of the last task
948// in the generated chain of tasks, which the Job should add as a dependency.
949func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400950 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400951 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400952 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400953 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
954 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400955 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400956 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500957 return name
958}
959
Ravi Mistry5e967422018-02-01 13:38:13 -0500960// androidFrameworkCompile generates an Android Framework Compile task. Returns
961// the name of the last task in the generated chain of tasks, which the Job
962// should add as a dependency.
963func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400964 task := kitchenTask(name, "android_compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400965 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -0400966 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400967 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500968 return name
969}
970
borenet2dbbfa52016-10-14 06:32:09 -0700971// infra generates an infra_tests task. Returns the name of the last task in the
972// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000973func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400974 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400975 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400976 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren9d834582018-08-03 14:29:03 -0400977 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
Eric Boren9599b0f2018-04-17 15:55:57 -0400978 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -0700979 return name
980}
981
Yuqian Li4a577af2018-01-05 11:13:43 -0500982func getParentRevisionName(compileTaskName string, parts map[string]string) string {
983 if parts["extra_config"] == "" {
984 return compileTaskName + "-ParentRevision"
985 } else {
986 return compileTaskName + "_ParentRevision"
987 }
988}
989
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400990// calmbench generates a calmbench task. Returns the name of the last task in the
991// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -0400992func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
993 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -0400994 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400995 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
996 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400997 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400998 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400999
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001000 // Upload results if necessary.
1001 if strings.Contains(name, "Release") && doUpload(name) {
1002 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001003 extraProps := map[string]string{
1004 "gs_bucket": CONFIG.GsBucketCalm,
1005 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001006 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 -04001007 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1008 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1009 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -04001010 return uploadName
1011 }
1012
Yuqian Lic81aaaa2017-10-16 12:24:43 -04001013 return name
1014}
1015
borenetdb182c72016-09-30 12:53:12 -07001016// doUpload indicates whether the given Job should upload its results.
1017func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -05001018 for _, s := range CONFIG.NoUpload {
1019 m, err := regexp.MatchString(s, name)
1020 if err != nil {
1021 glog.Fatal(err)
1022 }
1023 if m {
borenetdb182c72016-09-30 12:53:12 -07001024 return false
1025 }
1026 }
1027 return true
1028}
1029
1030// test generates a Test task. Returns the name of the last task in the
1031// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001032func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001033 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001034 if strings.Contains(name, "SKQP") {
1035 recipe = "skqp_test"
Ben Wagnera5e70302018-06-28 17:43:08 -04001036 } else if strings.Contains(name, "OpenCL") {
1037 // TODO(dogben): Longer term we may not want this to be called a "Test" task, but until we start
1038 // running hs_bench or kx, it will be easier to fit into the current job name schema.
1039 recipe = "compute_test"
Kevin Lubick92c91712018-08-09 10:00:02 -04001040 } else if strings.Contains(name, "PathKit") {
1041 recipe = "test_pathkit"
Kevin Lubick82999c02018-08-28 10:52:18 -04001042 } else if strings.Contains(name, "LottieWeb") {
1043 recipe = "test_lottie_web"
Stephan Altmueller88df8d22018-03-07 14:44:44 -05001044 }
Stephan Altmüller64cc5762018-08-02 08:51:38 +02001045 extraProps := map[string]string{
1046 "gold_hashes_url": CONFIG.GoldHashesURL,
1047 }
Eric Boreneb702382018-04-19 09:36:45 -04001048 iid := internalHardwareLabel(parts)
1049 if iid != nil {
1050 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
1051 }
Kevin Lubick92c91712018-08-09 10:00:02 -04001052 isolate := "test_skia_bundled.isolate"
Kevin Lubick82999c02018-08-28 10:52:18 -04001053 if strings.Contains(name, "PathKit") || strings.Contains(name, "LottieWeb") {
Kevin Lubick92c91712018-08-09 10:00:02 -04001054 isolate = "swarm_recipe.isolate"
1055 }
1056 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -04001057 task.CipdPackages = append(task.CipdPackages, pkgs...)
Eric Boren8c172ba2018-07-19 13:27:49 -04001058 if strings.Contains(name, "Lottie") {
1059 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("lottie-samples"))
1060 }
Kevin Lubick82999c02018-08-28 10:52:18 -04001061 if !strings.Contains(name, "LottieWeb") {
1062 // Test.+LottieWeb doesn't require anything in Skia to be compiled.
1063 task.Dependencies = append(task.Dependencies, compileTaskName)
1064 }
1065
Eric Boren9599b0f2018-04-17 15:55:57 -04001066 if strings.Contains(name, "Android_ASAN") {
1067 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +00001068 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001069 if strings.Contains(name, "SKQP") {
1070 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
Eric Boren8b3f9e62017-04-04 09:06:16 -04001071 }
Kevin Lubick90189522017-05-15 08:30:27 -04001072 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001073 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -04001074 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001075 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001076 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001077 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001078 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001079 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001080 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001081 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1082 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001083 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001084 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001085 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1086 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001087 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001088 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001089 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001090
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001091 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
1092 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -07001093 if doUpload(name) {
1094 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001095 extraProps := map[string]string{
1096 "gs_bucket": CONFIG.GsBucketGm,
1097 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001098 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 -04001099 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1100 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1101 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001102 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001103 }
1104
1105 return name
1106}
1107
1108func coverage(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
1109 shards := 1
1110 deps := []string{}
1111
1112 tf := parts["test_filter"]
1113 if strings.Contains(tf, "Shard") {
1114 // Expected Shard_NN
1115 shardstr := strings.Split(tf, "_")[1]
1116 var err error
1117 shards, err = strconv.Atoi(shardstr)
1118 if err != nil {
1119 glog.Fatalf("Expected int for number of shards %q in %s: %s", shardstr, name, err)
1120 }
1121 }
1122 for i := 0; i < shards; i++ {
1123 n := strings.Replace(name, tf, fmt.Sprintf("shard_%02d_%02d", i, shards), 1)
Eric Boren9599b0f2018-04-17 15:55:57 -04001124 task := kitchenTask(n, "test", "test_skia_bundled.isolate", "", swarmDimensions(parts), nil, OUTPUT_COVERAGE)
1125 task.CipdPackages = append(task.CipdPackages, pkgs...)
1126 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -04001127
Eric Boren9599b0f2018-04-17 15:55:57 -04001128 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001129 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001130 timeout(task, 4*time.Hour)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001131 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001132 task.Dependencies = append(task.Dependencies, deps...)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001133 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001134 b.MustAddTask(n, task)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001135 deps = append(deps, n)
borenetdb182c72016-09-30 12:53:12 -07001136 }
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001137
Kevin Lubick32f318b2017-10-17 13:40:52 -04001138 uploadName := fmt.Sprintf("%s%s%s", "Upload", jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001139 extraProps := map[string]string{
1140 "gs_bucket": CONFIG.GsBucketCoverage,
1141 }
Ben Wagner27d5a362018-05-09 15:37:34 -04001142 // Use MACHINE_TYPE_LARGE because this does a bunch of computation before upload.
1143 uploadTask := kitchenTask(uploadName, "upload_coverage_results", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPLOAD_COVERAGE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -04001144 usesGit(uploadTask, uploadName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001145 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001146 // We need clang_linux to get access to the llvm-profdata and llvm-cov binaries
1147 // which are used to deal with the raw coverage data output by the Test step.
Eric Boren9599b0f2018-04-17 15:55:57 -04001148 uploadTask.CipdPackages = append(uploadTask.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
1149 uploadTask.CipdPackages = append(uploadTask.CipdPackages, pkgs...)
1150 // A dependency on compileTaskName makes the TaskScheduler link the
1151 // isolated output of the compile step to the input of the upload step,
1152 // which gives us access to the instrumented binary. The binary is
1153 // needed to figure out symbol names and line numbers.
1154 uploadTask.Dependencies = append(uploadTask.Dependencies, compileTaskName)
1155 uploadTask.Dependencies = append(uploadTask.Dependencies, deps...)
1156 b.MustAddTask(uploadName, uploadTask)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001157 return uploadName
borenetdb182c72016-09-30 12:53:12 -07001158}
1159
1160// perf generates a Perf task. Returns the name of the last task in the
1161// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001162func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001163 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001164 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001165 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001166 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001167 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001168 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001169 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1170 task.CipdPackages = append(task.CipdPackages, pkgs...)
1171 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001172 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001173 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001174 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001175 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001176 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001177 }
1178
Eric Boren4b254b92016-11-08 12:55:32 -05001179 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001180 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001181 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001182 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1183 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001184 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001185 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001186 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1187 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001188 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001189 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001190 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001191 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001192 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001193 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001194 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001195
borenetdb182c72016-09-30 12:53:12 -07001196 // Upload results if necessary.
1197 if strings.Contains(name, "Release") && doUpload(name) {
1198 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001199 extraProps := map[string]string{
1200 "gs_bucket": CONFIG.GsBucketNano,
1201 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001202 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 -04001203 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1204 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1205 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001206 return uploadName
1207 }
1208 return name
1209}
1210
Eric Borenb66099b2018-04-25 15:09:22 -04001211// Run the presubmit.
1212func presubmit(b *specs.TasksCfgBuilder, name string) string {
1213 extraProps := map[string]string{
1214 "category": "cq",
1215 "patch_gerrit_url": "https://skia-review.googlesource.com",
1216 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001217 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001218 "reason": "CQ",
1219 "repo_name": "skia",
1220 }
Ben Wagner297e86b2018-05-14 12:38:09 -04001221 // Use MACHINE_TYPE_LARGE because it seems to save time versus MEDIUM and we want presubmit to be
1222 // fast.
Ben Wagnere99a4b12018-05-04 11:18:01 -04001223 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001224
1225 replaceArg := func(key, value string) {
1226 found := false
1227 for idx, arg := range task.Command {
1228 if arg == key {
1229 task.Command[idx+1] = value
1230 found = true
1231 }
1232 }
1233 if !found {
1234 task.Command = append(task.Command, key, value)
1235 }
1236 }
1237 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1238 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001239 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001240 task.Dependencies = []string{} // No bundled recipes for this one.
1241 b.MustAddTask(name, task)
1242 return name
1243}
1244
borenetdb182c72016-09-30 12:53:12 -07001245// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001246func process(b *specs.TasksCfgBuilder, name string) {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001247 var priority float64 // Leave as default for most jobs.
borenetdb182c72016-09-30 12:53:12 -07001248 deps := []string{}
1249
Eric Boren8b3f9e62017-04-04 09:06:16 -04001250 // Bundle Recipes.
1251 if name == BUNDLE_RECIPES_NAME {
1252 deps = append(deps, bundleRecipes(b))
1253 }
1254
Kevin Lubick07072942017-05-11 13:35:23 -04001255 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001256 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1257 deps = append(deps, isolateCIPDAsset(b, name))
1258 }
1259
borenetdb182c72016-09-30 12:53:12 -07001260 parts, err := jobNameSchema.ParseJobName(name)
1261 if err != nil {
1262 glog.Fatal(err)
1263 }
1264
1265 // RecreateSKPs.
1266 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001267 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001268 }
1269
borenet2dbbfa52016-10-14 06:32:09 -07001270 // Infra tests.
1271 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001272 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001273 }
1274
borenetdb182c72016-09-30 12:53:12 -07001275 // Compile bots.
1276 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001277 if parts["extra_config"] == "Android_Framework" {
1278 // Android Framework compile tasks use a different recipe.
1279 deps = append(deps, androidFrameworkCompile(b, name))
1280 } else {
1281 deps = append(deps, compile(b, name, parts))
1282 }
borenetdb182c72016-09-30 12:53:12 -07001283 }
1284
Eric Borenf5a90e82016-11-15 15:18:20 -05001285 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001286 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001287 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1288 if err != nil {
1289 glog.Fatal(err)
1290 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001291 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1292 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1293 if err != nil {
1294 glog.Fatal(err)
1295 }
1296
Eric Boren628e78b2016-11-17 11:33:27 -05001297 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001298 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001299 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001300 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001301 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001302 name != "Housekeeper-OnDemand-Presubmit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001303 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001304 !strings.Contains(name, "RecreateSKPs") &&
Ben Wagner50b84682017-06-12 13:03:29 -04001305 !strings.Contains(name, "-CT_") &&
Kevin Lubick82999c02018-08-28 10:52:18 -04001306 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") &&
1307 !strings.Contains(name, "LottieWeb") {
boreneted20a702016-10-20 11:04:31 -07001308 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001309 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001310 compile(b, compileParentName, compileParentParts)
1311 }
borenet52383432016-10-17 10:17:53 -07001312 }
borenetdb182c72016-09-30 12:53:12 -07001313
Eric Borene8b38ab2018-06-08 12:37:53 -04001314 // CT bots.
1315 if strings.Contains(name, "-CT_") {
1316 deps = append(deps, ctSKPs(b, name, compileTaskName))
1317 }
1318
Eric Borenf7928b42017-07-28 07:35:28 -04001319 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001320 if name == "Housekeeper-PerCommit" {
Eric Boren27688612018-04-16 13:21:01 +00001321 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -07001322 }
Eric Borenf7928b42017-07-28 07:35:28 -04001323 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001324 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001325 }
Eric Borenb66099b2018-04-25 15:09:22 -04001326 if name == "Housekeeper-OnDemand-Presubmit" {
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001327 priority = 1
Eric Borenb66099b2018-04-25 15:09:22 -04001328 deps = append(deps, presubmit(b, name))
1329 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001330 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001331 deps = append(deps, bookmaker(b, name, compileTaskName))
1332 }
borenetdb182c72016-09-30 12:53:12 -07001333
1334 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001335
1336 pkgs := []*specs.CipdPackage{}
1337
Kevin Lubick90189522017-05-15 08:30:27 -04001338 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001339 pkgs = []*specs.CipdPackage{
1340 b.MustGetCipdPackageFromAsset("skimage"),
1341 b.MustGetCipdPackageFromAsset("skp"),
1342 b.MustGetCipdPackageFromAsset("svg"),
1343 }
borenetdb182c72016-09-30 12:53:12 -07001344 }
Kevin Lubick90189522017-05-15 08:30:27 -04001345
Ben Wagner5655ba42017-10-02 10:48:32 -04001346 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1347 if strings.Contains(name, "SAN") {
1348 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1349 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001350 if strings.Contains(name, "Vulkan") {
1351 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1352 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001353 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
1354 if strings.Contains(name, "Release") {
1355 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
1356 } else {
1357 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
1358 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001359 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001360 if strings.Contains(name, "OpenCL") {
1361 pkgs = append(pkgs,
1362 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
1363 b.MustGetCipdPackageFromAsset("opencl_intel_neo_linux"),
1364 )
1365 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001366 }
Ben Wagner299b8822018-03-09 13:42:56 -05001367 if strings.Contains(name, "ProcDump") {
1368 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1369 }
Kevin Lubick82999c02018-08-28 10:52:18 -04001370 if strings.Contains(name, "PathKit") || strings.Contains(name, "LottieWeb") {
1371 // Docker-based tests that don't need the standard CIPD assets
Kevin Lubick92c91712018-08-09 10:00:02 -04001372 pkgs = []*specs.CipdPackage{}
1373 }
borenetdb182c72016-09-30 12:53:12 -07001374
1375 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001376 if parts["role"] == "Test" {
1377 if strings.Contains(parts["extra_config"], "Coverage") {
1378 deps = append(deps, coverage(b, name, parts, compileTaskName, pkgs))
1379 } else if !strings.Contains(name, "-CT_") {
1380 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
1381 }
1382
borenetdb182c72016-09-30 12:53:12 -07001383 }
1384
1385 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -05001386 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -07001387 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001388 }
1389
Yuqian Li4a577af2018-01-05 11:13:43 -05001390 // Calmbench bots.
1391 if parts["role"] == "Calmbench" {
1392 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1393 }
1394
borenetdb182c72016-09-30 12:53:12 -07001395 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001396 j := &specs.JobSpec{
Ben Wagnerc062b6b2018-07-24 17:10:46 -04001397 Priority: priority,
borenetdb182c72016-09-30 12:53:12 -07001398 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001399 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001400 }
Eric Borenba937a42017-07-31 10:41:15 -04001401 if strings.Contains(name, "-Nightly-") {
1402 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryf06dae82017-10-16 10:31:41 -04001403 } else if strings.Contains(name, "-Weekly-") || strings.Contains(name, "CT_DM_1m_SKPs") {
Eric Borenba937a42017-07-31 10:41:15 -04001404 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001405 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001406 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001407 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001408 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001409 }
Eric Boren8615fe52016-12-12 14:30:12 -05001410 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001411}
1412
Eric Boren27225492017-02-01 15:56:55 -05001413func loadJson(flag *string, defaultFlag string, val interface{}) {
1414 if *flag == "" {
1415 *flag = defaultFlag
1416 }
1417 b, err := ioutil.ReadFile(*flag)
1418 if err != nil {
1419 glog.Fatal(err)
1420 }
1421 if err := json.Unmarshal(b, val); err != nil {
1422 glog.Fatal(err)
1423 }
1424}
1425
borenetdb182c72016-09-30 12:53:12 -07001426// Regenerate the tasks.json file.
1427func main() {
boreneted20a702016-10-20 11:04:31 -07001428 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001429 b.SetAssetsDir(*assetsDir)
1430 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1431
1432 // Load the jobs from a JSON file.
1433 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1434
Eric Boren27225492017-02-01 15:56:55 -05001435 // Load general config information from a JSON file.
1436 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1437
borenetdb182c72016-09-30 12:53:12 -07001438 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001439 if *builderNameSchemaFile == "" {
1440 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1441 }
1442 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001443 if err != nil {
1444 glog.Fatal(err)
1445 }
1446 jobNameSchema = schema
1447
borenetdb182c72016-09-30 12:53:12 -07001448 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001449 for _, name := range JOBS {
1450 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001451 }
1452
boreneted20a702016-10-20 11:04:31 -07001453 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001454}
1455
1456// TODO(borenet): The below really belongs in its own file, probably next to the
1457// builder_name_schema.json file.
1458
Eric Boren8ff86a62018-04-17 14:11:23 -04001459// schema is a sub-struct of JobNameSchema.
1460type schema struct {
1461 Keys []string `json:"keys"`
1462 OptionalKeys []string `json:"optional_keys"`
1463 RecurseRoles []string `json:"recurse_roles"`
1464}
1465
borenetdb182c72016-09-30 12:53:12 -07001466// JobNameSchema is a struct used for (de)constructing Job names in a
1467// predictable format.
1468type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001469 Schema map[string]*schema `json:"builder_name_schema"`
1470 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001471}
1472
1473// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1474// file.
1475func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1476 var rv JobNameSchema
1477 f, err := os.Open(jsonFile)
1478 if err != nil {
1479 return nil, err
1480 }
1481 defer util.Close(f)
1482 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1483 return nil, err
1484 }
1485 return &rv, nil
1486}
1487
1488// ParseJobName splits the given Job name into its component parts, according
1489// to the schema.
1490func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001491 popFront := func(items []string) (string, []string, error) {
1492 if len(items) == 0 {
1493 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1494 }
1495 return items[0], items[1:], nil
1496 }
1497
1498 result := map[string]string{}
1499
1500 var parse func(int, string, []string) ([]string, error)
1501 parse = func(depth int, role string, parts []string) ([]string, error) {
1502 s, ok := s.Schema[role]
1503 if !ok {
1504 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1505 }
1506 if depth == 0 {
1507 result["role"] = role
1508 } else {
1509 result[fmt.Sprintf("sub-role-%d", depth)] = role
1510 }
1511 var err error
1512 for _, key := range s.Keys {
1513 var value string
1514 value, parts, err = popFront(parts)
1515 if err != nil {
1516 return nil, err
1517 }
1518 result[key] = value
1519 }
1520 for _, subRole := range s.RecurseRoles {
1521 if len(parts) > 0 && parts[0] == subRole {
1522 parts, err = parse(depth+1, parts[0], parts[1:])
1523 if err != nil {
1524 return nil, err
1525 }
1526 }
1527 }
1528 for _, key := range s.OptionalKeys {
1529 if len(parts) > 0 {
1530 var value string
1531 value, parts, err = popFront(parts)
1532 if err != nil {
1533 return nil, err
1534 }
1535 result[key] = value
1536 }
1537 }
1538 if len(parts) > 0 {
1539 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1540 }
1541 return parts, nil
1542 }
1543
borenetdb182c72016-09-30 12:53:12 -07001544 split := strings.Split(n, s.Sep)
1545 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001546 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001547 }
1548 role := split[0]
1549 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001550 _, err := parse(0, role, split)
1551 return result, err
borenetdb182c72016-09-30 12:53:12 -07001552}
1553
1554// MakeJobName assembles the given parts of a Job name, according to the schema.
1555func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001556 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001557
1558 var process func(int, map[string]string) (map[string]string, error)
1559 process = func(depth int, parts map[string]string) (map[string]string, error) {
1560 roleKey := "role"
1561 if depth != 0 {
1562 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001563 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001564 role, ok := parts[roleKey]
1565 if !ok {
1566 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1567 }
1568
1569 s, ok := s.Schema[role]
1570 if !ok {
1571 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1572 }
1573 rvParts = append(rvParts, role)
1574 delete(parts, roleKey)
1575
1576 for _, key := range s.Keys {
1577 value, ok := parts[key]
1578 if !ok {
1579 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1580 }
1581 rvParts = append(rvParts, value)
1582 delete(parts, key)
1583 }
1584
1585 if len(s.RecurseRoles) > 0 {
1586 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1587 subRole, ok := parts[subRoleKey]
1588 if !ok {
1589 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1590 }
1591 rvParts = append(rvParts, subRole)
1592 delete(parts, subRoleKey)
1593 found := false
1594 for _, recurseRole := range s.RecurseRoles {
1595 if recurseRole == subRole {
1596 found = true
1597 var err error
1598 parts, err = process(depth+1, parts)
1599 if err != nil {
1600 return nil, err
1601 }
1602 break
1603 }
1604 }
1605 if !found {
1606 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1607 }
1608 }
1609 for _, key := range s.OptionalKeys {
1610 if value, ok := parts[key]; ok {
1611 rvParts = append(rvParts, value)
1612 delete(parts, key)
1613 }
1614 }
1615 if len(parts) > 0 {
1616 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1617 }
1618 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001619 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001620
1621 // Copy the parts map, so that we can modify at will.
1622 partsCpy := make(map[string]string, len(parts))
1623 for k, v := range parts {
1624 partsCpy[k] = v
1625 }
1626 if _, err := process(0, partsCpy); err != nil {
1627 return "", err
borenetdb182c72016-09-30 12:53:12 -07001628 }
1629 return strings.Join(rvParts, s.Sep), nil
1630}