blob: d4608c401061523b061161a69bb78f48580e8114 [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"
35 ISOLATE_GO_LINUX_NAME = "Housekeeper-PerCommit-IsolateGoLinux"
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 Wagner5a9df182018-02-09 11:21:15 -050046 DEFAULT_OS_MAC = "Mac-10.13.3"
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.
62 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
63 OUTPUT_BUILD = "build"
64 OUTPUT_COVERAGE = "coverage"
65 OUTPUT_TEST = "test"
66 OUTPUT_PERF = "perf"
67
borenetdb182c72016-09-30 12:53:12 -070068 // Name prefix for upload jobs.
69 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040070
71 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
72 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
73 SERVICE_ACCOUNT_CT_SKPS = "skia-external-ct-skps@skia-swarming-bots.iam.gserviceaccount.com"
74 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
75 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
76 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
77 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
78 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
79 SERVICE_ACCOUNT_UPLOAD_COVERAGE = "skia-external-coverage-uploade@skia-swarming-bots.iam.gserviceaccount.com"
80 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
81 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070082)
83
84var (
85 // "Constants"
86
Eric Boren27225492017-02-01 15:56:55 -050087 // Top-level list of all jobs to run at each commit; loaded from
88 // jobs.json.
89 JOBS []string
90
Eric Boren27225492017-02-01 15:56:55 -050091 // General configuration information.
92 CONFIG struct {
Kevin Lubickc795a4c2017-10-09 15:26:19 -040093 GsBucketCoverage string `json:"gs_bucket_coverage"`
94 GsBucketGm string `json:"gs_bucket_gm"`
95 GsBucketNano string `json:"gs_bucket_nano"`
Yuqian Li2ebf3d12017-10-24 09:43:21 -040096 GsBucketCalm string `json:"gs_bucket_calm"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040097 NoUpload []string `json:"no_upload"`
98 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070099 }
100
Eric Boreneb702382018-04-19 09:36:45 -0400101 // alternateProject can be set in an init function to override the default project ID.
102 alternateProject string
103
Ben Wagner053d0462018-04-17 12:45:29 -0400104 // alternateServiceAccount can be set in an init function to override the normal service accounts.
105 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
106 // should be used, or uses sklog.Fatal to indicate a problem.
107 alternateServiceAccount func(serviceAccountEnum string) string
108
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400109 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
110 // dimensions for the given task.
111 alternateSwarmDimensions func(parts map[string]string) []string
112
Eric Borenfd4d60e2017-09-15 10:35:44 -0400113 // internalHardwareLabelFn can be set in an init function to provide an
114 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400115 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400116
borenetdb182c72016-09-30 12:53:12 -0700117 // Defines the structure of job names.
118 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500119
Eric Boren5cb5c742018-04-27 13:14:38 -0400120 // Named caches used by tasks.
121 CACHES_GIT = []*specs.Cache{
122 &specs.Cache{
123 Name: "git",
124 Path: "cache/git",
125 },
126 &specs.Cache{
127 Name: "git_cache",
128 Path: "cache/git_cache",
129 },
130 }
131 CACHES_WORKDIR = []*specs.Cache{
132 &specs.Cache{
133 Name: "work",
134 Path: "cache/work",
135 },
136 }
137
Ben Wagner702fe012018-06-15 09:19:13 -0400138 // Versions of the following copied from
139 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template_canary.json#42
140 // to test the fix for chromium:836196.
141 // (In the future we may want to use versions from
142 // https://chrome-internal.googlesource.com/infradata/config/+/master/configs/cr-buildbucket/swarming_task_template.json#42)
Eric Boren9599b0f2018-04-17 15:55:57 -0400143 // TODO(borenet): Roll these versions automatically!
144 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
145 &specs.CipdPackage{
146 Name: "infra/tools/luci/vpython/${platform}",
147 Path: "cipd_bin_packages",
Kevin Lubick39132872018-07-02 13:18:13 -0400148 Version: "git_revision:b9c4670197dcefd8762d6e509302acd3efc6e303",
Eric Boren9599b0f2018-04-17 15:55:57 -0400149 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400150 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400151
Eric Borenaa037522018-06-18 16:02:15 -0400152 CIPD_PKGS_CPYTHON = []*specs.CipdPackage{
153 &specs.CipdPackage{
154 Name: "infra/python/cpython/${platform}",
155 Path: "cipd_bin_packages",
156 Version: "version:2.7.14.chromium14",
157 },
158 }
159
Eric Boren9599b0f2018-04-17 15:55:57 -0400160 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
161 &specs.CipdPackage{
162 Name: "infra/tools/luci/kitchen/${platform}",
163 Path: ".",
Ben Wagner702fe012018-06-15 09:19:13 -0400164 Version: "git_revision:546aae39f1fb9dce9add528e2011afa574535ecd",
Eric Boren9599b0f2018-04-17 15:55:57 -0400165 },
166 &specs.CipdPackage{
Ben Wagnercd7ace22018-06-11 15:48:35 -0400167 Name: "infra/tools/luci-auth/${platform}",
Eric Boren9599b0f2018-04-17 15:55:57 -0400168 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400169 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400170 },
171 }, CIPD_PKGS_PYTHON...)
172
173 CIPD_PKGS_GIT = []*specs.CipdPackage{
174 &specs.CipdPackage{
175 Name: "infra/git/${platform}",
176 Path: "cipd_bin_packages",
Eric Borene42cef52018-06-20 07:11:38 -0400177 Version: "version:2.17.1.chromium15",
Eric Boren9599b0f2018-04-17 15:55:57 -0400178 },
179 &specs.CipdPackage{
180 Name: "infra/tools/git/${platform}",
181 Path: "cipd_bin_packages",
Eric Boren3f13bcb2018-06-15 07:39:36 -0400182 Version: "git_revision:0ae21738597e5601ba90372315145fec18582fc4",
Eric Boren9599b0f2018-04-17 15:55:57 -0400183 },
184 &specs.CipdPackage{
185 Name: "infra/tools/luci/git-credential-luci/${platform}",
186 Path: "cipd_bin_packages",
Ben Wagnercd7ace22018-06-11 15:48:35 -0400187 Version: "git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c",
Eric Boren9599b0f2018-04-17 15:55:57 -0400188 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000189 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400190
Eric Boren9599b0f2018-04-17 15:55:57 -0400191 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
192 &specs.CipdPackage{
193 Name: "infra/gsutil",
194 Path: "cipd_bin_packages",
195 Version: "version:4.28",
196 },
197 }
198
Eric Boren27225492017-02-01 15:56:55 -0500199 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500200 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.")
201 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
202 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500203 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700204)
205
Eric Boreneb702382018-04-19 09:36:45 -0400206// Build the LogDog annotation URL.
207func logdogAnnotationUrl() string {
208 project := DEFAULT_PROJECT
209 if alternateProject != "" {
210 project = alternateProject
211 }
212 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
213}
214
Eric Boren9599b0f2018-04-17 15:55:57 -0400215// Create a properties JSON string.
216func props(p map[string]string) string {
217 d := make(map[string]interface{}, len(p)+1)
218 for k, v := range p {
219 d[k] = interface{}(v)
220 }
221 d["$kitchen"] = struct {
222 DevShell bool `json:"devshell"`
223 GitAuth bool `json:"git_auth"`
224 }{
225 DevShell: true,
226 GitAuth: true,
227 }
228
229 j, err := json.Marshal(d)
230 if err != nil {
231 sklog.Fatal(err)
232 }
233 return strings.Replace(string(j), "\\u003c", "<", -1)
234}
235
236// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
237// recipe.
238func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
239 if serviceAccount != "" && alternateServiceAccount != nil {
240 serviceAccount = alternateServiceAccount(serviceAccount)
241 }
242 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
Eric Borenaa037522018-06-18 16:02:15 -0400243 if strings.Contains(name, "Win") {
244 cipd = append(cipd, CIPD_PKGS_CPYTHON...)
245 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400246 properties := map[string]string{
247 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
248 "buildername": name,
249 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400250 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400251 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
252 "patch_set": specs.PLACEHOLDER_PATCHSET,
253 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
254 "repository": specs.PLACEHOLDER_REPO,
255 "revision": specs.PLACEHOLDER_REVISION,
256 "swarm_out_dir": outputDir,
257 }
258 for k, v := range extraProps {
259 properties[k] = v
260 }
261 var outputs []string = nil
262 if outputDir != OUTPUT_NONE {
263 outputs = []string{outputDir}
264 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400265 task := &specs.TaskSpec{
266 Caches: []*specs.Cache{
267 &specs.Cache{
268 Name: "vpython",
269 Path: "cache/vpython",
270 },
271 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400272 CipdPackages: cipd,
273 Command: []string{
274 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
275 "-checkout-dir", "recipe_bundle",
276 "-mode", "swarming",
277 "-luci-system-account", "system",
278 "-cache-dir", "cache",
279 "-temp-dir", "tmp",
280 "-known-gerrit-host", "android.googlesource.com",
281 "-known-gerrit-host", "boringssl.googlesource.com",
282 "-known-gerrit-host", "chromium.googlesource.com",
283 "-known-gerrit-host", "dart.googlesource.com",
284 "-known-gerrit-host", "fuchsia.googlesource.com",
285 "-known-gerrit-host", "go.googlesource.com",
286 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400287 "-known-gerrit-host", "skia.googlesource.com",
288 "-known-gerrit-host", "webrtc.googlesource.com",
289 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
290 "-workdir", ".",
291 "-recipe", recipe,
292 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400293 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400294 },
295 Dependencies: []string{BUNDLE_RECIPES_NAME},
296 Dimensions: dimensions,
297 EnvPrefixes: map[string][]string{
298 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
299 "VPYTHON_VIRTUALENV_ROOT": []string{"${cache_dir}/vpython"},
300 },
301 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400302 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400303 },
304 Isolate: relpath(isolate),
305 Outputs: outputs,
306 Priority: 0.8,
307 ServiceAccount: serviceAccount,
308 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400309 timeout(task, time.Hour)
310 return task
Eric Boren9599b0f2018-04-17 15:55:57 -0400311}
312
Eric Borenfd4d60e2017-09-15 10:35:44 -0400313// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400314func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400315 if internalHardwareLabelFn != nil {
316 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400317 }
318 return nil
319}
320
Eric Boren27225492017-02-01 15:56:55 -0500321// linuxGceDimensions are the Swarming dimensions for Linux GCE
322// instances.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400323func linuxGceDimensions(machineType string) []string {
Eric Boren27225492017-02-01 15:56:55 -0500324 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400325 // Specify CPU to avoid running builds on bots with a more unique CPU.
326 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500327 "gpu:none",
Ben Wagner82a33422018-04-26 18:02:23 -0400328 // Currently all Linux GCE tasks run on 16-CPU machines.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400329 fmt.Sprintf("machine_type:%s", machineType),
Eric Boren170c39c2017-11-15 11:22:57 -0500330 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500331 fmt.Sprintf("pool:%s", CONFIG.Pool),
332 }
333}
334
borenetdb182c72016-09-30 12:53:12 -0700335// deriveCompileTaskName returns the name of a compile task based on the given
336// job name.
337func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500338 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500339 return "Build-Debian9-GCC-x86_64-Release"
340 } else if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400341 return "Build-Debian9-GCC-x86_64-Release-Shared"
Yuqian Li4a577af2018-01-05 11:13:43 -0500342 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700343 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400344 ec := []string{}
345 if val := parts["extra_config"]; val != "" {
346 ec = strings.Split(val, "_")
Robert Phillips65eb4fb2018-05-31 13:27:52 -0400347 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR", "FSAA", "FAAA", "FDAA", "NativeFonts", "GDI", "NoGPUThreads", "ProcDump", "DDL1", "DDL3", "T8888", "DDLTotal", "DDLRecord", "9x9"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400348 keep := make([]string, 0, len(ec))
349 for _, part := range ec {
350 if !util.In(part, ignore) {
351 keep = append(keep, part)
352 }
353 }
354 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400355 }
borenetdb182c72016-09-30 12:53:12 -0700356 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400357 if !util.In("Android", ec) {
358 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700359 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400360 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500361 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400362 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400363 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400364 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400365 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400366 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700367 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400368 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700369 task_os = "Mac"
370 } else if strings.Contains(task_os, "Win") {
371 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400372 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
373 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700374 }
Eric Boren50831302016-11-18 13:10:51 -0500375 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700376 "role": "Build",
377 "os": task_os,
378 "compiler": parts["compiler"],
379 "target_arch": parts["arch"],
380 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500381 }
Eric Borene8b38ab2018-06-08 12:37:53 -0400382 if strings.Contains(jobName, "-CT_") {
383 ec = []string{"Static"}
384 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400385 if len(ec) > 0 {
386 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500387 }
388 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700389 if err != nil {
390 glog.Fatal(err)
391 }
392 return name
393 } else {
394 return jobName
395 }
396}
397
398// swarmDimensions generates swarming bot dimensions for the given task.
399func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400400 if alternateSwarmDimensions != nil {
401 return alternateSwarmDimensions(parts)
402 }
403 return defaultSwarmDimensions(parts)
404}
405
406// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
407func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700408 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500409 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700410 }
411 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400412 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400413 "Android": "Android",
414 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400415 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400416 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500417 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400418 "Ubuntu14": DEFAULT_OS_UBUNTU,
Eric Boren810c2b62017-07-11 08:11:15 -0400419 "Ubuntu17": "Ubuntu-17.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500420 "Win": DEFAULT_OS_WIN,
Ben Wagner0954a192018-07-11 17:33:52 -0400421 "Win10": "Windows-10-17134.165",
Kevin Lubick291547d2017-03-21 09:25:34 -0400422 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500423 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400424 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400425 "Win8": "Windows-8.1-SP0",
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400426 "iOS": "iOS-10.3.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500427 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400428 if !ok {
429 glog.Fatalf("Entry %q not found in OS mapping.", os)
430 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500431 if os == "Win10" && parts["model"] == "Golo" {
Ben Wagnerf6148b62018-03-15 13:53:25 -0400432 // ChOps-owned machines have Windows 10 v1709, but a slightly different version than Skolo.
433 d["os"] = "Windows-10-16299.309"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500434 }
Ben Wagnere1c37a72018-04-24 16:59:48 -0400435 if d["os"] == DEFAULT_OS_WIN {
436 // TODO(dogben): Temporarily add image dimension during upgrade.
Ben Wagnerbe9aa8d2018-04-26 14:52:11 -0400437 d["image"] = "windows-server-2016-dc-v20180410"
Ben Wagnere1c37a72018-04-24 16:59:48 -0400438 }
Ben Wagner418ff4a2018-06-20 16:12:16 -0400439 if d["os"] == DEFAULT_OS_MAC && (parts["model"] == "MacBook10.1" || parts["model"] == "MacBookAir7.2") {
440 // TODO(dogben): Get all Mac bots on the same version.
Ben Wagner42974b72018-07-10 16:29:53 -0400441 d["os"] = "Mac-10.13.6"
Ben Wagner418ff4a2018-06-20 16:12:16 -0400442 }
borenetdb182c72016-09-30 12:53:12 -0700443 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400444 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700445 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400446 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400447 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700448 // For Android, the device type is a better dimension
449 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400450 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400451 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500452 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500453 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagnerc72c9482018-06-11 13:48:44 -0400454 "GalaxyS7_G930FD": {"herolte", "R16NW_G930FXXU2EREM"}, // This is Oreo.
Ben Wagner8d8f45d2018-06-04 17:32:04 -0400455 "MotoG4": {"athene", "NPJS25.93-14.7-8"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500456 "NVIDIA_Shield": {"foster", "NRD90M_1915764_848"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500457 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500458 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500459 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner2a510c92018-04-11 12:36:56 -0400460 "NexusPlayer": {"fugu", "OPR2.170623.027"},
Ben Wagner3de510a2018-05-22 15:50:07 -0400461 "Pixel": {"sailfish", "OPM4.171019.016.B1"},
462 "Pixel2XL": {"taimen", "OPM4.171019.016.B1"},
Ben Wagner36682782017-06-14 10:01:45 -0400463 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500464 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400465 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500466 }
Eric Boren4b254b92016-11-08 12:55:32 -0500467 d["device_type"] = deviceInfo[0]
468 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700469 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400470 device, ok := map[string]string{
Eric Boren792079c2016-11-09 14:03:20 -0500471 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400472 "iPhone6": "iPhone7,2",
473 "iPhone7": "iPhone9,1",
474 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700475 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400476 if !ok {
477 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
478 }
479 d["device"] = device
Ben Wagnerd26e4462018-05-22 10:46:15 -0400480 } else if strings.Contains(parts["extra_config"], "SwiftShader") {
481 if parts["model"] != "GCE" || d["os"] != DEFAULT_OS_DEBIAN || parts["cpu_or_gpu_value"] != "SwiftShader" {
482 glog.Fatalf("Please update defaultSwarmDimensions for SwiftShader %s %s %s.", parts["os"], parts["model"], parts["cpu_or_gpu_value"])
483 }
484 d["cpu"] = "x86-64-Haswell_GCE"
485 d["os"] = DEFAULT_OS_LINUX_GCE
486 d["machine_type"] = MACHINE_TYPE_SMALL
borenetdb182c72016-09-30 12:53:12 -0700487 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400488 modelMapping, ok := map[string]map[string]string{
489 "AVX": {
490 "MacMini7.1": "x86-64-E5-2697_v2",
491 "Golo": "x86-64-E5-2670",
492 },
493 "AVX2": {
Ben Wagner85fb42a2017-11-07 16:57:37 -0500494 "GCE": "x86-64-Haswell_GCE",
Mike Klein9a01a212017-11-03 12:19:54 -0400495 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400496 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400497 "AVX512": {
498 "GCE": "x86-64-Skylake_GCE",
499 },
borenetdb182c72016-09-30 12:53:12 -0700500 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400501 if !ok {
502 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
503 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400504 cpu, ok := modelMapping[parts["model"]]
505 if !ok {
506 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700507 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400508 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500509 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
510 d["os"] = DEFAULT_OS_LINUX_GCE
511 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400512 if parts["model"] == "GCE" && d["cpu"] == "x86-64-Haswell_GCE" {
Ben Wagner27d5a362018-05-09 15:37:34 -0400513 // Coverage gets slower with more cores.
514 if strings.Contains(parts["extra_config"], "Coverage") {
Ben Wagner297e86b2018-05-14 12:38:09 -0400515 d["machine_type"] = MACHINE_TYPE_SMALL
516 } else {
517 d["machine_type"] = MACHINE_TYPE_MEDIUM
Ben Wagner27d5a362018-05-09 15:37:34 -0400518 }
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500519 }
borenetdb182c72016-09-30 12:53:12 -0700520 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400521 if strings.Contains(parts["os"], "Win") {
522 gpu, ok := map[string]string{
Ben Wagnerf6148b62018-03-15 13:53:25 -0400523 "GT610": "10de:104a-23.21.13.9101",
Ben Wagner96ee1192018-02-28 17:30:19 -0500524 "GTX1070": "10de:1ba1-23.21.13.9101",
525 "GTX660": "10de:11c0-23.21.13.9101",
526 "GTX960": "10de:1401-23.21.13.9101",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500527 "IntelHD4400": "8086:0a16-20.19.15.4835",
Ben Wagner300cf062018-04-11 11:29:59 -0400528 "IntelIris540": "8086:1926-23.20.16.4982",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500529 "IntelIris6100": "8086:162b-20.19.15.4835",
Ben Wagnerf8f18392018-04-24 18:17:02 -0400530 "RadeonHD7770": "1002:683d-23.20.15033.5003",
531 "RadeonR9M470X": "1002:6646-23.20.15033.5003",
Ben Wagnerf6148b62018-03-15 13:53:25 -0400532 "QuadroP400": "10de:1cb3-23.21.13.9103",
Ben Wagner1d060782017-06-14 10:34:18 -0400533 }[parts["cpu_or_gpu_value"]]
534 if !ok {
535 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
536 }
537 d["gpu"] = gpu
Ben Wagner08435892017-02-18 23:28:26 -0500538
Ben Wagner4b1df022017-06-15 12:28:04 -0400539 // Specify cpu dimension for NUCs and ShuttleCs. We temporarily have two
540 // types of machines with a GTX960.
541 cpu, ok := map[string]string{
542 "NUC6i7KYK": "x86-64-i7-6770HQ",
543 "ShuttleC": "x86-64-i7-6700K",
Ben Wagner1d060782017-06-14 10:34:18 -0400544 }[parts["model"]]
545 if ok {
Ben Wagner4b1df022017-06-15 12:28:04 -0400546 d["cpu"] = cpu
Ben Wagner1d060782017-06-14 10:34:18 -0400547 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400548 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400549 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400550 // Intel drivers come from CIPD, so no need to specify the version here.
551 "IntelBayTrail": "8086:0f31",
552 "IntelHD2000": "8086:0102",
553 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500554 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400555 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400556 }[parts["cpu_or_gpu_value"]]
557 if !ok {
558 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
559 }
560 d["gpu"] = gpu
561 } else if strings.Contains(parts["os"], "Mac") {
562 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500563 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500564 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400565 "IntelIris5100": "8086:0a2e",
Ben Wagnereeeb3282018-05-15 16:45:42 -0400566 "RadeonHD8870M": "1002:6821-4.0.20-3.2.8",
Ben Wagner1d060782017-06-14 10:34:18 -0400567 }[parts["cpu_or_gpu_value"]]
568 if !ok {
569 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
570 }
571 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500572 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
573 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
574 // Run all tasks on Golo machines for now.
575 d["cpu"] = "x86-64-i7-4578U"
576 }
Ben Wagner1d060782017-06-14 10:34:18 -0400577 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500578 version, ok := map[string]string{
Kevin Lubickff8387f2018-05-01 10:43:35 -0400579 "MaliT604": "10575.22.0",
Kevin Lubicke114e592018-05-01 08:53:52 -0400580 "MaliT764": "10575.22.0",
Kevin Lubicke467d4e2018-05-01 13:12:58 -0400581 "MaliT860": "10575.22.0",
582 "PowerVRGX6250": "10575.22.0",
583 "TegraK1": "10575.22.0",
584 "IntelHDGraphics615": "10575.22.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400585 }[parts["cpu_or_gpu_value"]]
586 if !ok {
587 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
588 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500589 d["gpu"] = parts["cpu_or_gpu_value"]
590 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400591 } else {
592 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500593 }
borenetdb182c72016-09-30 12:53:12 -0700594 }
595 } else {
596 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400597 if d["os"] == DEFAULT_OS_DEBIAN {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400598 // Use many-core machines for Build tasks.
599 return linuxGceDimensions(MACHINE_TYPE_LARGE)
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500600 } else if d["os"] == DEFAULT_OS_WIN {
601 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400602 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagnere99a4b12018-05-04 11:18:01 -0400603 // Use many-core machines for Build tasks.
604 d["machine_type"] = MACHINE_TYPE_LARGE
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500605 } else if d["os"] == DEFAULT_OS_MAC {
606 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400607 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400608 }
borenetdb182c72016-09-30 12:53:12 -0700609 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400610
borenetdb182c72016-09-30 12:53:12 -0700611 rv := make([]string, 0, len(d))
612 for k, v := range d {
613 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
614 }
615 sort.Strings(rv)
616 return rv
617}
618
Eric Boren7e3a3642017-06-14 15:25:31 -0400619// relpath returns the relative path to the given file from the config file.
620func relpath(f string) string {
621 _, filename, _, _ := runtime.Caller(0)
622 dir := path.Dir(filename)
623 rel := dir
624 if *cfgFile != "" {
625 rel = path.Dir(*cfgFile)
626 }
627 rv, err := filepath.Rel(rel, path.Join(dir, f))
628 if err != nil {
629 sklog.Fatal(err)
630 }
631 return rv
632}
633
Eric Boren8b3f9e62017-04-04 09:06:16 -0400634// bundleRecipes generates the task to bundle and isolate the recipes.
635func bundleRecipes(b *specs.TasksCfgBuilder) string {
Eric Boren63924422018-06-21 09:02:30 -0400636 pkgs := append([]*specs.CipdPackage{}, CIPD_PKGS_GIT...)
637 pkgs = append(pkgs, CIPD_PKGS_PYTHON...)
Eric Boren8b3f9e62017-04-04 09:06:16 -0400638 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren63924422018-06-21 09:02:30 -0400639 CipdPackages: pkgs,
Eric Boren9599b0f2018-04-17 15:55:57 -0400640 Command: []string{
641 "/bin/bash", "skia/infra/bots/bundle_recipes.sh", specs.PLACEHOLDER_ISOLATED_OUTDIR,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400642 },
Ben Wagnere99a4b12018-05-04 11:18:01 -0400643 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400644 EnvPrefixes: map[string][]string{
645 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
646 },
647 Isolate: relpath("swarm_recipe.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400648 Priority: 0.7,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400649 })
650 return BUNDLE_RECIPES_NAME
651}
652
Kevin Lubick07072942017-05-11 13:35:23 -0400653type isolateAssetCfg struct {
Eric Boren9599b0f2018-04-17 15:55:57 -0400654 cipdPkg string
655 path string
Kevin Lubick07072942017-05-11 13:35:23 -0400656}
657
658var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500659 ISOLATE_GCLOUD_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400660 cipdPkg: "gcloud_linux",
661 path: "gcloud_linux",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500662 },
663 ISOLATE_GO_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400664 cipdPkg: "go",
665 path: "go",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500666 },
Kevin Lubick07072942017-05-11 13:35:23 -0400667 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400668 cipdPkg: "skimage",
669 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400670 },
671 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400672 cipdPkg: "skp",
673 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400674 },
675 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400676 cipdPkg: "svg",
677 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400678 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500679 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400680 cipdPkg: "android_ndk_linux",
681 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500682 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500683 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400684 cipdPkg: "android_sdk_linux",
685 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500686 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500687 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400688 cipdPkg: "win_toolchain",
689 path: "t",
Kevin Lubick814b1492017-11-29 14:45:14 -0500690 },
691 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400692 cipdPkg: "win_vulkan_sdk",
693 path: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500694 },
Kevin Lubick07072942017-05-11 13:35:23 -0400695}
696
Eric Boren9599b0f2018-04-17 15:55:57 -0400697// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400698func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400699 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400700 b.MustAddTask(name, &specs.TaskSpec{
701 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400702 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400703 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400704 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400705 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400706 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400707 Priority: 0.7,
708 })
709 return name
710}
711
Kevin Lubick90189522017-05-15 08:30:27 -0400712// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
713// This allows us to save time on I/O bound bots, like the RPIs.
714func getIsolatedCIPDDeps(parts map[string]string) []string {
715 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400716 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
717 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400718 rpiOS := []string{"Android", "ChromeOS", "iOS"}
719
720 if o := parts["os"]; strings.Contains(o, "Chromecast") {
721 // Chromecasts don't have enough disk space to fit all of the content,
722 // so we do a subset of the skps.
723 deps = append(deps, ISOLATE_SKP_NAME)
724 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
725 // Skpbench only needs skps
726 deps = append(deps, ISOLATE_SKP_NAME)
727 } else if util.In(o, rpiOS) {
728 deps = append(deps, ISOLATE_SKP_NAME)
729 deps = append(deps, ISOLATE_SVG_NAME)
730 deps = append(deps, ISOLATE_SKIMAGE_NAME)
731 }
732
733 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400734}
735
Eric Boren5cb5c742018-04-27 13:14:38 -0400736// usesGit adds attributes to tasks which use git.
737func usesGit(t *specs.TaskSpec, name string) {
738 t.Caches = append(t.Caches, CACHES_GIT...)
739 if !strings.Contains(name, "NoDEPS") {
740 t.Caches = append(t.Caches, CACHES_WORKDIR...)
741 }
742 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
743}
744
745// timeout sets the timeout(s) for this task.
746func timeout(task *specs.TaskSpec, timeout time.Duration) {
747 task.ExecutionTimeout = timeout
748 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
749}
750
borenetdb182c72016-09-30 12:53:12 -0700751// compile generates a compile task. Returns the name of the last task in the
752// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700753func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400754 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400755 usesGit(task, name)
borenetdb182c72016-09-30 12:53:12 -0700756
757 // Android bots require a toolchain.
758 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500759 if parts["extra_config"] == "Android_Framework" {
760 // Do not need a toolchain when building the
761 // Android Framework.
762 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400763 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400764 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400765 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
766 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400767 task.CipdPackages = append(task.CipdPackages, pkg)
borenetdb182c72016-09-30 12:53:12 -0700768 } else {
Eric Boren9599b0f2018-04-17 15:55:57 -0400769 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500770 if strings.Contains(name, "SKQP") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400771 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_SDK_LINUX_NAME), isolateCIPDAsset(b, ISOLATE_GO_LINUX_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500772 }
borenetdb182c72016-09-30 12:53:12 -0700773 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500774 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400775 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
776 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400777 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400778 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400779 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400780 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400781 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400782 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
783 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400784 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400785 } else if strings.Contains(name, "CommandBuffer") {
786 timeout(task, 2*time.Hour)
Eric Borenbb198fb2017-06-28 11:45:54 -0400787 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500788 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400789 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500790 }
791 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400792 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500793 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400794 if strings.Contains(name, "EMCC") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400795 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("emscripten_sdk"))
Kevin Lubickebf648e2017-09-21 13:45:16 -0400796 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400797 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
798 if parts["compiler"] != "GCC" {
799 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
800 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400801 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400802 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400803 if strings.Contains(name, "SwiftShader") {
804 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
805 }
Ben Wagner55a7d222018-06-28 20:41:04 -0400806 if strings.Contains(name, "OpenCL") {
807 task.CipdPackages = append(task.CipdPackages,
808 b.MustGetCipdPackageFromAsset("opencl_headers"),
809 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
810 )
811 }
Mike Klein27dcee12016-11-09 16:31:42 -0500812 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400813 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400814 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400815 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400816 }
borenetdb182c72016-09-30 12:53:12 -0700817 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400818 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700819 }
820 }
821
Chris Dalton2b937f52018-05-17 10:17:10 -0600822 if strings.Contains(name, "MoltenVK") {
823 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("moltenvk"))
824 }
825
Ben Wagneradeb75d2018-04-19 21:48:55 -0400826 task.MaxAttempts = 1
827
Eric Borenbd2e1f12018-04-17 11:28:46 +0000828 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400829 b.MustAddTask(name, task)
830
Eric Boren8615fe52016-12-12 14:30:12 -0500831 // All compile tasks are runnable as their own Job. Assert that the Job
832 // is listed in JOBS.
833 if !util.In(name, JOBS) {
834 glog.Fatalf("Job %q is missing from the JOBS list!", name)
835 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500836
837 // Upload the skiaserve binary only for Linux Android compile bots.
838 // See skbug.com/7399 for context.
839 if parts["configuration"] == "Release" &&
840 parts["extra_config"] == "Android" &&
841 !strings.Contains(parts["os"], "Win") &&
842 !strings.Contains(parts["os"], "Mac") {
843 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400844 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 -0400845 task.Dependencies = append(task.Dependencies, name)
846 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500847 return uploadName
848 }
849
borenetdb182c72016-09-30 12:53:12 -0700850 return name
851}
852
853// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
854// task in the generated chain of tasks, which the Job should add as a
855// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000856func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry5a12d052018-05-15 17:19:42 -0400857 dims := []string{
858 "pool:SkiaCT",
859 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
860 }
861 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400862 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400863 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren5cb5c742018-04-27 13:14:38 -0400864 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400865 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700866 return name
867}
868
869// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
870// generated chain of tasks, which the Job should add as a dependency.
Eric Borene8b38ab2018-06-08 12:37:53 -0400871func ctSKPs(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400872 dims := []string{
873 "pool:SkiaCT",
874 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
875 }
Eric Borene8b38ab2018-06-08 12:37:53 -0400876 task := kitchenTask(name, "ct_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_CT_SKPS, dims, nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400877 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400878 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Eric Borene8b38ab2018-06-08 12:37:53 -0400879 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400880 timeout(task, 24*time.Hour)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400881 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400882 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700883 return name
884}
885
Eric Borenf7928b42017-07-28 07:35:28 -0400886// checkGeneratedFiles verifies that no generated SKSL files have been edited
887// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000888func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400889 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 -0400890 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400891 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400892 return name
893}
894
borenetdb182c72016-09-30 12:53:12 -0700895// housekeeper generates a Housekeeper task. Returns the name of the last task
896// in the generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000897func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400898 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400899 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400900 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
901 task.Dependencies = append(task.Dependencies, compileTaskName)
902 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700903 return name
904}
905
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500906// bookmaker generates a Bookmaker task. Returns the name of the last task
907// in the generated chain of tasks, which the Job should add as a dependency.
908func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400909 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400910 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400911 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400912 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
913 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400914 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400915 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500916 return name
917}
918
Ravi Mistry5e967422018-02-01 13:38:13 -0500919// androidFrameworkCompile generates an Android Framework Compile task. Returns
920// the name of the last task in the generated chain of tasks, which the Job
921// should add as a dependency.
922func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400923 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 -0400924 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -0400925 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400926 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500927 return name
928}
929
borenet2dbbfa52016-10-14 06:32:09 -0700930// infra generates an infra_tests task. Returns the name of the last task in the
931// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000932func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400933 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400934 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400935 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
936 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -0700937 return name
938}
939
Yuqian Li4a577af2018-01-05 11:13:43 -0500940func getParentRevisionName(compileTaskName string, parts map[string]string) string {
941 if parts["extra_config"] == "" {
942 return compileTaskName + "-ParentRevision"
943 } else {
944 return compileTaskName + "_ParentRevision"
945 }
946}
947
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400948// calmbench generates a calmbench task. Returns the name of the last task in the
949// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -0400950func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
951 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -0400952 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400953 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
954 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400955 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400956 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400957
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400958 // Upload results if necessary.
959 if strings.Contains(name, "Release") && doUpload(name) {
960 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400961 extraProps := map[string]string{
962 "gs_bucket": CONFIG.GsBucketCalm,
963 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400964 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 -0400965 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
966 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
967 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400968 return uploadName
969 }
970
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400971 return name
972}
973
borenetdb182c72016-09-30 12:53:12 -0700974// doUpload indicates whether the given Job should upload its results.
975func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -0500976 for _, s := range CONFIG.NoUpload {
977 m, err := regexp.MatchString(s, name)
978 if err != nil {
979 glog.Fatal(err)
980 }
981 if m {
borenetdb182c72016-09-30 12:53:12 -0700982 return false
983 }
984 }
985 return true
986}
987
988// test generates a Test task. Returns the name of the last task in the
989// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700990func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500991 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500992 if strings.Contains(name, "SKQP") {
993 recipe = "skqp_test"
Ben Wagnera5e70302018-06-28 17:43:08 -0400994 } else if strings.Contains(name, "OpenCL") {
995 // TODO(dogben): Longer term we may not want this to be called a "Test" task, but until we start
996 // running hs_bench or kx, it will be easier to fit into the current job name schema.
997 recipe = "compute_test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500998 }
Eric Boreneb702382018-04-19 09:36:45 -0400999 extraProps := map[string]string{}
1000 iid := internalHardwareLabel(parts)
1001 if iid != nil {
1002 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
1003 }
Eric Borene9a67002018-04-24 13:12:05 -04001004 task := kitchenTask(name, recipe, "test_skia_bundled.isolate", "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -04001005 task.CipdPackages = append(task.CipdPackages, pkgs...)
1006 task.Dependencies = append(task.Dependencies, compileTaskName)
1007 if strings.Contains(name, "Android_ASAN") {
1008 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +00001009 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001010 if strings.Contains(name, "SKQP") {
1011 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
Eric Boren8b3f9e62017-04-04 09:06:16 -04001012 }
Kevin Lubick90189522017-05-15 08:30:27 -04001013 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001014 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -04001015 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001016 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001017 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001018 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001019 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001020 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001021 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001022 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1023 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001024 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001025 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001026 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1027 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001028 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001029 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001030 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001031
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001032 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
1033 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -07001034 if doUpload(name) {
1035 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001036 extraProps := map[string]string{
1037 "gs_bucket": CONFIG.GsBucketGm,
1038 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001039 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 -04001040 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1041 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1042 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001043 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001044 }
1045
1046 return name
1047}
1048
1049func coverage(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
1050 shards := 1
1051 deps := []string{}
1052
1053 tf := parts["test_filter"]
1054 if strings.Contains(tf, "Shard") {
1055 // Expected Shard_NN
1056 shardstr := strings.Split(tf, "_")[1]
1057 var err error
1058 shards, err = strconv.Atoi(shardstr)
1059 if err != nil {
1060 glog.Fatalf("Expected int for number of shards %q in %s: %s", shardstr, name, err)
1061 }
1062 }
1063 for i := 0; i < shards; i++ {
1064 n := strings.Replace(name, tf, fmt.Sprintf("shard_%02d_%02d", i, shards), 1)
Eric Boren9599b0f2018-04-17 15:55:57 -04001065 task := kitchenTask(n, "test", "test_skia_bundled.isolate", "", swarmDimensions(parts), nil, OUTPUT_COVERAGE)
1066 task.CipdPackages = append(task.CipdPackages, pkgs...)
1067 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -04001068
Eric Boren9599b0f2018-04-17 15:55:57 -04001069 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001070 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001071 timeout(task, 4*time.Hour)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001072 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001073 task.Dependencies = append(task.Dependencies, deps...)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001074 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001075 b.MustAddTask(n, task)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001076 deps = append(deps, n)
borenetdb182c72016-09-30 12:53:12 -07001077 }
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001078
Kevin Lubick32f318b2017-10-17 13:40:52 -04001079 uploadName := fmt.Sprintf("%s%s%s", "Upload", jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001080 extraProps := map[string]string{
1081 "gs_bucket": CONFIG.GsBucketCoverage,
1082 }
Ben Wagner27d5a362018-05-09 15:37:34 -04001083 // Use MACHINE_TYPE_LARGE because this does a bunch of computation before upload.
1084 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 -04001085 usesGit(uploadTask, uploadName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001086 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001087 // We need clang_linux to get access to the llvm-profdata and llvm-cov binaries
1088 // which are used to deal with the raw coverage data output by the Test step.
Eric Boren9599b0f2018-04-17 15:55:57 -04001089 uploadTask.CipdPackages = append(uploadTask.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
1090 uploadTask.CipdPackages = append(uploadTask.CipdPackages, pkgs...)
1091 // A dependency on compileTaskName makes the TaskScheduler link the
1092 // isolated output of the compile step to the input of the upload step,
1093 // which gives us access to the instrumented binary. The binary is
1094 // needed to figure out symbol names and line numbers.
1095 uploadTask.Dependencies = append(uploadTask.Dependencies, compileTaskName)
1096 uploadTask.Dependencies = append(uploadTask.Dependencies, deps...)
1097 b.MustAddTask(uploadName, uploadTask)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001098 return uploadName
borenetdb182c72016-09-30 12:53:12 -07001099}
1100
1101// perf generates a Perf task. Returns the name of the last task in the
1102// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001103func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001104 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001105 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001106 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001107 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001108 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001109 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001110 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1111 task.CipdPackages = append(task.CipdPackages, pkgs...)
1112 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001113 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001114 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001115 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001116 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001117 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001118 }
1119
Eric Boren4b254b92016-11-08 12:55:32 -05001120 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001121 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001122 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001123 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1124 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001125 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001126 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001127 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1128 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001129 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001130 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001131 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001132 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001133 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001134 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001135 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001136
borenetdb182c72016-09-30 12:53:12 -07001137 // Upload results if necessary.
1138 if strings.Contains(name, "Release") && doUpload(name) {
1139 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001140 extraProps := map[string]string{
1141 "gs_bucket": CONFIG.GsBucketNano,
1142 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001143 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 -04001144 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1145 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1146 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001147 return uploadName
1148 }
1149 return name
1150}
1151
Eric Borenb66099b2018-04-25 15:09:22 -04001152// Run the presubmit.
1153func presubmit(b *specs.TasksCfgBuilder, name string) string {
1154 extraProps := map[string]string{
1155 "category": "cq",
1156 "patch_gerrit_url": "https://skia-review.googlesource.com",
1157 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001158 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001159 "reason": "CQ",
1160 "repo_name": "skia",
1161 }
Ben Wagner297e86b2018-05-14 12:38:09 -04001162 // Use MACHINE_TYPE_LARGE because it seems to save time versus MEDIUM and we want presubmit to be
1163 // fast.
Ben Wagnere99a4b12018-05-04 11:18:01 -04001164 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001165
1166 replaceArg := func(key, value string) {
1167 found := false
1168 for idx, arg := range task.Command {
1169 if arg == key {
1170 task.Command[idx+1] = value
1171 found = true
1172 }
1173 }
1174 if !found {
1175 task.Command = append(task.Command, key, value)
1176 }
1177 }
1178 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1179 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001180 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001181 task.Dependencies = []string{} // No bundled recipes for this one.
1182 b.MustAddTask(name, task)
1183 return name
1184}
1185
borenetdb182c72016-09-30 12:53:12 -07001186// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001187func process(b *specs.TasksCfgBuilder, name string) {
borenetdb182c72016-09-30 12:53:12 -07001188 deps := []string{}
1189
Eric Boren8b3f9e62017-04-04 09:06:16 -04001190 // Bundle Recipes.
1191 if name == BUNDLE_RECIPES_NAME {
1192 deps = append(deps, bundleRecipes(b))
1193 }
1194
Kevin Lubick07072942017-05-11 13:35:23 -04001195 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001196 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1197 deps = append(deps, isolateCIPDAsset(b, name))
1198 }
1199
borenetdb182c72016-09-30 12:53:12 -07001200 parts, err := jobNameSchema.ParseJobName(name)
1201 if err != nil {
1202 glog.Fatal(err)
1203 }
1204
1205 // RecreateSKPs.
1206 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001207 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001208 }
1209
borenet2dbbfa52016-10-14 06:32:09 -07001210 // Infra tests.
1211 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001212 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001213 }
1214
borenetdb182c72016-09-30 12:53:12 -07001215 // Compile bots.
1216 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001217 if parts["extra_config"] == "Android_Framework" {
1218 // Android Framework compile tasks use a different recipe.
1219 deps = append(deps, androidFrameworkCompile(b, name))
1220 } else {
1221 deps = append(deps, compile(b, name, parts))
1222 }
borenetdb182c72016-09-30 12:53:12 -07001223 }
1224
Eric Borenf5a90e82016-11-15 15:18:20 -05001225 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001226 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001227 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1228 if err != nil {
1229 glog.Fatal(err)
1230 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001231 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1232 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1233 if err != nil {
1234 glog.Fatal(err)
1235 }
1236
Eric Boren628e78b2016-11-17 11:33:27 -05001237 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001238 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001239 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001240 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001241 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001242 name != "Housekeeper-OnDemand-Presubmit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001243 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001244 !strings.Contains(name, "RecreateSKPs") &&
Ben Wagner50b84682017-06-12 13:03:29 -04001245 !strings.Contains(name, "-CT_") &&
1246 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") {
boreneted20a702016-10-20 11:04:31 -07001247 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001248 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001249 compile(b, compileParentName, compileParentParts)
1250 }
borenet52383432016-10-17 10:17:53 -07001251 }
borenetdb182c72016-09-30 12:53:12 -07001252
Eric Borene8b38ab2018-06-08 12:37:53 -04001253 // CT bots.
1254 if strings.Contains(name, "-CT_") {
1255 deps = append(deps, ctSKPs(b, name, compileTaskName))
1256 }
1257
Eric Borenf7928b42017-07-28 07:35:28 -04001258 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001259 if name == "Housekeeper-PerCommit" {
Eric Boren27688612018-04-16 13:21:01 +00001260 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -07001261 }
Eric Borenf7928b42017-07-28 07:35:28 -04001262 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001263 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001264 }
Eric Borenb66099b2018-04-25 15:09:22 -04001265 if name == "Housekeeper-OnDemand-Presubmit" {
1266 deps = append(deps, presubmit(b, name))
1267 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001268 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001269 deps = append(deps, bookmaker(b, name, compileTaskName))
1270 }
borenetdb182c72016-09-30 12:53:12 -07001271
1272 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001273
1274 pkgs := []*specs.CipdPackage{}
1275
Kevin Lubick90189522017-05-15 08:30:27 -04001276 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001277 pkgs = []*specs.CipdPackage{
1278 b.MustGetCipdPackageFromAsset("skimage"),
1279 b.MustGetCipdPackageFromAsset("skp"),
1280 b.MustGetCipdPackageFromAsset("svg"),
1281 }
borenetdb182c72016-09-30 12:53:12 -07001282 }
Kevin Lubick90189522017-05-15 08:30:27 -04001283
Ben Wagner5655ba42017-10-02 10:48:32 -04001284 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1285 if strings.Contains(name, "SAN") {
1286 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1287 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001288 if strings.Contains(name, "Vulkan") {
1289 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1290 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001291 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
1292 if strings.Contains(name, "Release") {
1293 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
1294 } else {
1295 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
1296 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001297 }
Ben Wagnera5e70302018-06-28 17:43:08 -04001298 if strings.Contains(name, "OpenCL") {
1299 pkgs = append(pkgs,
1300 b.MustGetCipdPackageFromAsset("opencl_ocl_icd_linux"),
1301 b.MustGetCipdPackageFromAsset("opencl_intel_neo_linux"),
1302 )
1303 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001304 }
Ben Wagner299b8822018-03-09 13:42:56 -05001305 if strings.Contains(name, "ProcDump") {
1306 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1307 }
borenetdb182c72016-09-30 12:53:12 -07001308
1309 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001310 if parts["role"] == "Test" {
1311 if strings.Contains(parts["extra_config"], "Coverage") {
1312 deps = append(deps, coverage(b, name, parts, compileTaskName, pkgs))
1313 } else if !strings.Contains(name, "-CT_") {
1314 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
1315 }
1316
borenetdb182c72016-09-30 12:53:12 -07001317 }
1318
1319 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -05001320 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -07001321 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001322 }
1323
Yuqian Li4a577af2018-01-05 11:13:43 -05001324 // Calmbench bots.
1325 if parts["role"] == "Calmbench" {
1326 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1327 }
1328
borenetdb182c72016-09-30 12:53:12 -07001329 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001330 j := &specs.JobSpec{
borenetdb182c72016-09-30 12:53:12 -07001331 Priority: 0.8,
1332 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001333 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001334 }
Eric Borenba937a42017-07-31 10:41:15 -04001335 if strings.Contains(name, "-Nightly-") {
1336 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryf06dae82017-10-16 10:31:41 -04001337 } else if strings.Contains(name, "-Weekly-") || strings.Contains(name, "CT_DM_1m_SKPs") {
Eric Borenba937a42017-07-31 10:41:15 -04001338 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001339 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001340 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001341 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001342 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001343 }
Eric Boren8615fe52016-12-12 14:30:12 -05001344 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001345}
1346
Eric Boren27225492017-02-01 15:56:55 -05001347func loadJson(flag *string, defaultFlag string, val interface{}) {
1348 if *flag == "" {
1349 *flag = defaultFlag
1350 }
1351 b, err := ioutil.ReadFile(*flag)
1352 if err != nil {
1353 glog.Fatal(err)
1354 }
1355 if err := json.Unmarshal(b, val); err != nil {
1356 glog.Fatal(err)
1357 }
1358}
1359
borenetdb182c72016-09-30 12:53:12 -07001360// Regenerate the tasks.json file.
1361func main() {
boreneted20a702016-10-20 11:04:31 -07001362 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001363 b.SetAssetsDir(*assetsDir)
1364 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1365
1366 // Load the jobs from a JSON file.
1367 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1368
Eric Boren27225492017-02-01 15:56:55 -05001369 // Load general config information from a JSON file.
1370 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1371
borenetdb182c72016-09-30 12:53:12 -07001372 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001373 if *builderNameSchemaFile == "" {
1374 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1375 }
1376 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001377 if err != nil {
1378 glog.Fatal(err)
1379 }
1380 jobNameSchema = schema
1381
borenetdb182c72016-09-30 12:53:12 -07001382 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001383 for _, name := range JOBS {
1384 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001385 }
1386
boreneted20a702016-10-20 11:04:31 -07001387 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001388}
1389
1390// TODO(borenet): The below really belongs in its own file, probably next to the
1391// builder_name_schema.json file.
1392
Eric Boren8ff86a62018-04-17 14:11:23 -04001393// schema is a sub-struct of JobNameSchema.
1394type schema struct {
1395 Keys []string `json:"keys"`
1396 OptionalKeys []string `json:"optional_keys"`
1397 RecurseRoles []string `json:"recurse_roles"`
1398}
1399
borenetdb182c72016-09-30 12:53:12 -07001400// JobNameSchema is a struct used for (de)constructing Job names in a
1401// predictable format.
1402type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001403 Schema map[string]*schema `json:"builder_name_schema"`
1404 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001405}
1406
1407// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1408// file.
1409func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1410 var rv JobNameSchema
1411 f, err := os.Open(jsonFile)
1412 if err != nil {
1413 return nil, err
1414 }
1415 defer util.Close(f)
1416 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1417 return nil, err
1418 }
1419 return &rv, nil
1420}
1421
1422// ParseJobName splits the given Job name into its component parts, according
1423// to the schema.
1424func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001425 popFront := func(items []string) (string, []string, error) {
1426 if len(items) == 0 {
1427 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1428 }
1429 return items[0], items[1:], nil
1430 }
1431
1432 result := map[string]string{}
1433
1434 var parse func(int, string, []string) ([]string, error)
1435 parse = func(depth int, role string, parts []string) ([]string, error) {
1436 s, ok := s.Schema[role]
1437 if !ok {
1438 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1439 }
1440 if depth == 0 {
1441 result["role"] = role
1442 } else {
1443 result[fmt.Sprintf("sub-role-%d", depth)] = role
1444 }
1445 var err error
1446 for _, key := range s.Keys {
1447 var value string
1448 value, parts, err = popFront(parts)
1449 if err != nil {
1450 return nil, err
1451 }
1452 result[key] = value
1453 }
1454 for _, subRole := range s.RecurseRoles {
1455 if len(parts) > 0 && parts[0] == subRole {
1456 parts, err = parse(depth+1, parts[0], parts[1:])
1457 if err != nil {
1458 return nil, err
1459 }
1460 }
1461 }
1462 for _, key := range s.OptionalKeys {
1463 if len(parts) > 0 {
1464 var value string
1465 value, parts, err = popFront(parts)
1466 if err != nil {
1467 return nil, err
1468 }
1469 result[key] = value
1470 }
1471 }
1472 if len(parts) > 0 {
1473 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1474 }
1475 return parts, nil
1476 }
1477
borenetdb182c72016-09-30 12:53:12 -07001478 split := strings.Split(n, s.Sep)
1479 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001480 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001481 }
1482 role := split[0]
1483 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001484 _, err := parse(0, role, split)
1485 return result, err
borenetdb182c72016-09-30 12:53:12 -07001486}
1487
1488// MakeJobName assembles the given parts of a Job name, according to the schema.
1489func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001490 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001491
1492 var process func(int, map[string]string) (map[string]string, error)
1493 process = func(depth int, parts map[string]string) (map[string]string, error) {
1494 roleKey := "role"
1495 if depth != 0 {
1496 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001497 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001498 role, ok := parts[roleKey]
1499 if !ok {
1500 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1501 }
1502
1503 s, ok := s.Schema[role]
1504 if !ok {
1505 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1506 }
1507 rvParts = append(rvParts, role)
1508 delete(parts, roleKey)
1509
1510 for _, key := range s.Keys {
1511 value, ok := parts[key]
1512 if !ok {
1513 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1514 }
1515 rvParts = append(rvParts, value)
1516 delete(parts, key)
1517 }
1518
1519 if len(s.RecurseRoles) > 0 {
1520 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1521 subRole, ok := parts[subRoleKey]
1522 if !ok {
1523 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1524 }
1525 rvParts = append(rvParts, subRole)
1526 delete(parts, subRoleKey)
1527 found := false
1528 for _, recurseRole := range s.RecurseRoles {
1529 if recurseRole == subRole {
1530 found = true
1531 var err error
1532 parts, err = process(depth+1, parts)
1533 if err != nil {
1534 return nil, err
1535 }
1536 break
1537 }
1538 }
1539 if !found {
1540 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1541 }
1542 }
1543 for _, key := range s.OptionalKeys {
1544 if value, ok := parts[key]; ok {
1545 rvParts = append(rvParts, value)
1546 delete(parts, key)
1547 }
1548 }
1549 if len(parts) > 0 {
1550 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1551 }
1552 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001553 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001554
1555 // Copy the parts map, so that we can modify at will.
1556 partsCpy := make(map[string]string, len(parts))
1557 for k, v := range parts {
1558 partsCpy[k] = v
1559 }
1560 if _, err := process(0, partsCpy); err != nil {
1561 return "", err
borenetdb182c72016-09-30 12:53:12 -07001562 }
1563 return strings.Join(rvParts, s.Sep), nil
1564}