blob: 64c7209894efd334827a4ca28de54fd71b510128 [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
26 "github.com/skia-dev/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 Wagnere99a4b12018-05-04 11:18:01 -040052 MACHINE_TYPE_SMALL = "n1-highmem-2"
53 MACHINE_TYPE_LARGE = "n1-highcpu-64"
54
Eric Boren9599b0f2018-04-17 15:55:57 -040055 // Swarming output dirs.
56 OUTPUT_NONE = "output_ignored" // This will result in outputs not being isolated.
57 OUTPUT_BUILD = "build"
58 OUTPUT_COVERAGE = "coverage"
59 OUTPUT_TEST = "test"
60 OUTPUT_PERF = "perf"
61
borenetdb182c72016-09-30 12:53:12 -070062 // Name prefix for upload jobs.
63 PREFIX_UPLOAD = "Upload"
Eric Boren9599b0f2018-04-17 15:55:57 -040064
65 SERVICE_ACCOUNT_BOOKMAKER = "skia-bookmaker@skia-swarming-bots.iam.gserviceaccount.com"
66 SERVICE_ACCOUNT_COMPILE = "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
67 SERVICE_ACCOUNT_CT_SKPS = "skia-external-ct-skps@skia-swarming-bots.iam.gserviceaccount.com"
68 SERVICE_ACCOUNT_HOUSEKEEPER = "skia-external-housekeeper@skia-swarming-bots.iam.gserviceaccount.com"
69 SERVICE_ACCOUNT_RECREATE_SKPS = "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
70 SERVICE_ACCOUNT_UPDATE_META_CONFIG = "skia-update-meta-config@skia-swarming-bots.iam.gserviceaccount.com"
71 SERVICE_ACCOUNT_UPLOAD_BINARY = "skia-external-binary-uploader@skia-swarming-bots.iam.gserviceaccount.com"
72 SERVICE_ACCOUNT_UPLOAD_CALMBENCH = "skia-external-calmbench-upload@skia-swarming-bots.iam.gserviceaccount.com"
73 SERVICE_ACCOUNT_UPLOAD_COVERAGE = "skia-external-coverage-uploade@skia-swarming-bots.iam.gserviceaccount.com"
74 SERVICE_ACCOUNT_UPLOAD_GM = "skia-external-gm-uploader@skia-swarming-bots.iam.gserviceaccount.com"
75 SERVICE_ACCOUNT_UPLOAD_NANO = "skia-external-nano-uploader@skia-swarming-bots.iam.gserviceaccount.com"
borenetdb182c72016-09-30 12:53:12 -070076)
77
78var (
79 // "Constants"
80
Eric Boren27225492017-02-01 15:56:55 -050081 // Top-level list of all jobs to run at each commit; loaded from
82 // jobs.json.
83 JOBS []string
84
Eric Boren27225492017-02-01 15:56:55 -050085 // General configuration information.
86 CONFIG struct {
Kevin Lubickc795a4c2017-10-09 15:26:19 -040087 GsBucketCoverage string `json:"gs_bucket_coverage"`
88 GsBucketGm string `json:"gs_bucket_gm"`
89 GsBucketNano string `json:"gs_bucket_nano"`
Yuqian Li2ebf3d12017-10-24 09:43:21 -040090 GsBucketCalm string `json:"gs_bucket_calm"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040091 NoUpload []string `json:"no_upload"`
92 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070093 }
94
Eric Boreneb702382018-04-19 09:36:45 -040095 // alternateProject can be set in an init function to override the default project ID.
96 alternateProject string
97
Ben Wagner053d0462018-04-17 12:45:29 -040098 // alternateServiceAccount can be set in an init function to override the normal service accounts.
99 // Takes one of SERVICE_ACCOUNT_* constants as an argument and returns the service account that
100 // should be used, or uses sklog.Fatal to indicate a problem.
101 alternateServiceAccount func(serviceAccountEnum string) string
102
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400103 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
104 // dimensions for the given task.
105 alternateSwarmDimensions func(parts map[string]string) []string
106
Eric Borenfd4d60e2017-09-15 10:35:44 -0400107 // internalHardwareLabelFn can be set in an init function to provide an
108 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400109 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -0400110
borenetdb182c72016-09-30 12:53:12 -0700111 // Defines the structure of job names.
112 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -0500113
Eric Boren5cb5c742018-04-27 13:14:38 -0400114 // Named caches used by tasks.
115 CACHES_GIT = []*specs.Cache{
116 &specs.Cache{
117 Name: "git",
118 Path: "cache/git",
119 },
120 &specs.Cache{
121 Name: "git_cache",
122 Path: "cache/git_cache",
123 },
124 }
125 CACHES_WORKDIR = []*specs.Cache{
126 &specs.Cache{
127 Name: "work",
128 Path: "cache/work",
129 },
130 }
131
Eric Boren9599b0f2018-04-17 15:55:57 -0400132 // TODO(borenet): Roll these versions automatically!
133 CIPD_PKGS_PYTHON = []*specs.CipdPackage{
134 &specs.CipdPackage{
135 Name: "infra/tools/luci/vpython/${platform}",
136 Path: "cipd_bin_packages",
137 Version: "git_revision:d0130097bd6364a8d834cb9efd4554c1f6192c82",
138 },
Eric Borenf4a5fc72017-06-06 08:27:09 -0400139 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400140
141 CIPD_PKGS_KITCHEN = append([]*specs.CipdPackage{
142 &specs.CipdPackage{
143 Name: "infra/tools/luci/kitchen/${platform}",
144 Path: ".",
145 Version: "git_revision:206b4474cb712bdad8b7b3f213880cfbf03f120c",
146 },
147 &specs.CipdPackage{
148 Name: "infra/tools/authutil/${platform}",
149 Path: "cipd_bin_packages",
150 Version: "git_revision:9c63809842a277ce10a86afd51b61c639a665d11",
151 },
152 }, CIPD_PKGS_PYTHON...)
153
154 CIPD_PKGS_GIT = []*specs.CipdPackage{
155 &specs.CipdPackage{
156 Name: "infra/git/${platform}",
157 Path: "cipd_bin_packages",
158 Version: "version:2.15.0.chromium12",
159 },
160 &specs.CipdPackage{
161 Name: "infra/tools/git/${platform}",
162 Path: "cipd_bin_packages",
163 Version: "git_revision:fa7a52f4741f5e04bba0dfccc9b8456dc572c60b",
164 },
165 &specs.CipdPackage{
166 Name: "infra/tools/luci/git-credential-luci/${platform}",
167 Path: "cipd_bin_packages",
168 Version: "git_revision:d0130097bd6364a8d834cb9efd4554c1f6192c82",
169 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000170 }
Eric Borenf4a5fc72017-06-06 08:27:09 -0400171
Eric Boren9599b0f2018-04-17 15:55:57 -0400172 CIPD_PKGS_GSUTIL = []*specs.CipdPackage{
173 &specs.CipdPackage{
174 Name: "infra/gsutil",
175 Path: "cipd_bin_packages",
176 Version: "version:4.28",
177 },
178 }
179
180 RECIPE_BUNDLE_UNIX = "recipe_bundle/recipes"
181 RECIPE_BUNDLE_WIN = "recipe_bundle/recipes.bat"
182
Eric Boren27225492017-02-01 15:56:55 -0500183 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -0500184 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.")
185 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
186 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -0500187 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -0700188)
189
Eric Boreneb702382018-04-19 09:36:45 -0400190// Build the LogDog annotation URL.
191func logdogAnnotationUrl() string {
192 project := DEFAULT_PROJECT
193 if alternateProject != "" {
194 project = alternateProject
195 }
196 return fmt.Sprintf("logdog://logs.chromium.org/%s/%s/+/annotations", project, specs.PLACEHOLDER_TASK_ID)
197}
198
Eric Boren9599b0f2018-04-17 15:55:57 -0400199// Create a properties JSON string.
200func props(p map[string]string) string {
201 d := make(map[string]interface{}, len(p)+1)
202 for k, v := range p {
203 d[k] = interface{}(v)
204 }
205 d["$kitchen"] = struct {
206 DevShell bool `json:"devshell"`
207 GitAuth bool `json:"git_auth"`
208 }{
209 DevShell: true,
210 GitAuth: true,
211 }
212
213 j, err := json.Marshal(d)
214 if err != nil {
215 sklog.Fatal(err)
216 }
217 return strings.Replace(string(j), "\\u003c", "<", -1)
218}
219
220// kitchenTask returns a specs.TaskSpec instance which uses Kitchen to run a
221// recipe.
222func kitchenTask(name, recipe, isolate, serviceAccount string, dimensions []string, extraProps map[string]string, outputDir string) *specs.TaskSpec {
223 if serviceAccount != "" && alternateServiceAccount != nil {
224 serviceAccount = alternateServiceAccount(serviceAccount)
225 }
226 cipd := append([]*specs.CipdPackage{}, CIPD_PKGS_KITCHEN...)
227 properties := map[string]string{
228 "buildbucket_build_id": specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID,
229 "buildername": name,
230 "patch_issue": specs.PLACEHOLDER_ISSUE,
Eric Boren2f62de02018-05-03 09:56:48 -0400231 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Boren9599b0f2018-04-17 15:55:57 -0400232 "patch_repo": specs.PLACEHOLDER_PATCH_REPO,
233 "patch_set": specs.PLACEHOLDER_PATCHSET,
234 "patch_storage": specs.PLACEHOLDER_PATCH_STORAGE,
235 "repository": specs.PLACEHOLDER_REPO,
236 "revision": specs.PLACEHOLDER_REVISION,
237 "swarm_out_dir": outputDir,
238 }
239 for k, v := range extraProps {
240 properties[k] = v
241 }
242 var outputs []string = nil
243 if outputDir != OUTPUT_NONE {
244 outputs = []string{outputDir}
245 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400246 task := &specs.TaskSpec{
247 Caches: []*specs.Cache{
248 &specs.Cache{
249 Name: "vpython",
250 Path: "cache/vpython",
251 },
252 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400253 CipdPackages: cipd,
254 Command: []string{
255 "./kitchen${EXECUTABLE_SUFFIX}", "cook",
256 "-checkout-dir", "recipe_bundle",
257 "-mode", "swarming",
258 "-luci-system-account", "system",
259 "-cache-dir", "cache",
260 "-temp-dir", "tmp",
261 "-known-gerrit-host", "android.googlesource.com",
262 "-known-gerrit-host", "boringssl.googlesource.com",
263 "-known-gerrit-host", "chromium.googlesource.com",
264 "-known-gerrit-host", "dart.googlesource.com",
265 "-known-gerrit-host", "fuchsia.googlesource.com",
266 "-known-gerrit-host", "go.googlesource.com",
267 "-known-gerrit-host", "llvm.googlesource.com",
Eric Boren9599b0f2018-04-17 15:55:57 -0400268 "-known-gerrit-host", "skia.googlesource.com",
269 "-known-gerrit-host", "webrtc.googlesource.com",
270 "-output-result-json", "${ISOLATED_OUTDIR}/build_result_filename",
271 "-workdir", ".",
272 "-recipe", recipe,
273 "-properties", props(properties),
Eric Boreneb702382018-04-19 09:36:45 -0400274 "-logdog-annotation-url", logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400275 },
276 Dependencies: []string{BUNDLE_RECIPES_NAME},
277 Dimensions: dimensions,
278 EnvPrefixes: map[string][]string{
279 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
280 "VPYTHON_VIRTUALENV_ROOT": []string{"${cache_dir}/vpython"},
281 },
282 ExtraTags: map[string]string{
Eric Boreneb702382018-04-19 09:36:45 -0400283 "log_location": logdogAnnotationUrl(),
Eric Boren9599b0f2018-04-17 15:55:57 -0400284 },
285 Isolate: relpath(isolate),
286 Outputs: outputs,
287 Priority: 0.8,
288 ServiceAccount: serviceAccount,
289 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400290 timeout(task, time.Hour)
291 return task
Eric Boren9599b0f2018-04-17 15:55:57 -0400292}
293
Eric Borenfd4d60e2017-09-15 10:35:44 -0400294// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400295func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400296 if internalHardwareLabelFn != nil {
297 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400298 }
299 return nil
300}
301
Eric Boren27225492017-02-01 15:56:55 -0500302// linuxGceDimensions are the Swarming dimensions for Linux GCE
303// instances.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400304func linuxGceDimensions(machineType string) []string {
Eric Boren27225492017-02-01 15:56:55 -0500305 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400306 // Specify CPU to avoid running builds on bots with a more unique CPU.
307 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500308 "gpu:none",
Ben Wagner82a33422018-04-26 18:02:23 -0400309 // Currently all Linux GCE tasks run on 16-CPU machines.
Ben Wagnere99a4b12018-05-04 11:18:01 -0400310 fmt.Sprintf("machine_type:%s", machineType),
Eric Boren170c39c2017-11-15 11:22:57 -0500311 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500312 fmt.Sprintf("pool:%s", CONFIG.Pool),
313 }
314}
315
borenetdb182c72016-09-30 12:53:12 -0700316// deriveCompileTaskName returns the name of a compile task based on the given
317// job name.
318func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500319 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500320 return "Build-Debian9-GCC-x86_64-Release"
321 } else if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400322 return "Build-Debian9-GCC-x86_64-Release-Shared"
Yuqian Li4a577af2018-01-05 11:13:43 -0500323 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700324 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400325 ec := []string{}
326 if val := parts["extra_config"]; val != "" {
327 ec = strings.Split(val, "_")
Kevin Lubicka585f732018-05-07 12:08:58 -0400328 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR", "FSAA", "FAAA", "FDAA", "NativeFonts", "GDI", "NoGPUThreads", "ProcDump", "DDL1", "DDL3", "T8888"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400329 keep := make([]string, 0, len(ec))
330 for _, part := range ec {
331 if !util.In(part, ignore) {
332 keep = append(keep, part)
333 }
334 }
335 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400336 }
borenetdb182c72016-09-30 12:53:12 -0700337 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400338 if !util.In("Android", ec) {
339 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700340 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400341 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500342 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400343 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400344 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400345 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400346 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400347 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700348 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400349 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700350 task_os = "Mac"
351 } else if strings.Contains(task_os, "Win") {
352 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400353 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
354 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700355 }
Eric Boren50831302016-11-18 13:10:51 -0500356 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700357 "role": "Build",
358 "os": task_os,
359 "compiler": parts["compiler"],
360 "target_arch": parts["arch"],
361 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500362 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400363 if len(ec) > 0 {
364 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500365 }
366 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700367 if err != nil {
368 glog.Fatal(err)
369 }
370 return name
371 } else {
372 return jobName
373 }
374}
375
376// swarmDimensions generates swarming bot dimensions for the given task.
377func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400378 if alternateSwarmDimensions != nil {
379 return alternateSwarmDimensions(parts)
380 }
381 return defaultSwarmDimensions(parts)
382}
383
384// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
385func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700386 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500387 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700388 }
389 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400390 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400391 "Android": "Android",
392 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400393 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400394 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500395 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400396 "Ubuntu14": DEFAULT_OS_UBUNTU,
Eric Boren810c2b62017-07-11 08:11:15 -0400397 "Ubuntu17": "Ubuntu-17.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500398 "Win": DEFAULT_OS_WIN,
Ben Wagner38a29f22018-04-11 14:38:45 -0400399 "Win10": "Windows-10-16299.371",
Kevin Lubick291547d2017-03-21 09:25:34 -0400400 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500401 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400402 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400403 "Win8": "Windows-8.1-SP0",
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400404 "iOS": "iOS-10.3.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500405 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400406 if !ok {
407 glog.Fatalf("Entry %q not found in OS mapping.", os)
408 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500409 if os == "Win10" && parts["model"] == "Golo" {
Ben Wagnerf6148b62018-03-15 13:53:25 -0400410 // ChOps-owned machines have Windows 10 v1709, but a slightly different version than Skolo.
411 d["os"] = "Windows-10-16299.309"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500412 }
Ben Wagnere1c37a72018-04-24 16:59:48 -0400413 if d["os"] == DEFAULT_OS_WIN {
414 // TODO(dogben): Temporarily add image dimension during upgrade.
Ben Wagnerbe9aa8d2018-04-26 14:52:11 -0400415 d["image"] = "windows-server-2016-dc-v20180410"
Ben Wagnere1c37a72018-04-24 16:59:48 -0400416 }
borenetdb182c72016-09-30 12:53:12 -0700417 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400418 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700419 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400420 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400421 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700422 // For Android, the device type is a better dimension
423 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400424 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400425 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500426 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500427 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400428 "GalaxyS7_G930A": {"heroqlteatt", "NRD90M_G930AUCS4BQC2"},
429 "GalaxyS7_G930FD": {"herolte", "NRD90M_G930FXXU1DQAS"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400430 "MotoG4": {"athene", "NPJ25.93-14"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500431 "NVIDIA_Shield": {"foster", "NRD90M_1915764_848"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500432 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500433 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500434 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner2a510c92018-04-11 12:36:56 -0400435 "NexusPlayer": {"fugu", "OPR2.170623.027"},
Kevin Lubickb5d82b42018-02-20 10:29:45 -0500436 "Pixel": {"sailfish", "OPM1.171019.016"},
Kevin Lubickc24d5bc2018-04-02 11:00:52 -0400437 "Pixel2XL": {"taimen", "OPM1.171019.021"},
Ben Wagner2a510c92018-04-11 12:36:56 -0400438 "PixelC": {"dragon", "OPM1.171019.026"},
Ben Wagner36682782017-06-14 10:01:45 -0400439 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500440 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400441 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500442 }
Eric Boren4b254b92016-11-08 12:55:32 -0500443 d["device_type"] = deviceInfo[0]
444 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700445 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400446 device, ok := map[string]string{
Eric Boren792079c2016-11-09 14:03:20 -0500447 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400448 "iPhone6": "iPhone7,2",
449 "iPhone7": "iPhone9,1",
450 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700451 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400452 if !ok {
453 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
454 }
455 d["device"] = device
borenetdb182c72016-09-30 12:53:12 -0700456 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400457 modelMapping, ok := map[string]map[string]string{
458 "AVX": {
459 "MacMini7.1": "x86-64-E5-2697_v2",
460 "Golo": "x86-64-E5-2670",
461 },
462 "AVX2": {
Ben Wagner85fb42a2017-11-07 16:57:37 -0500463 "GCE": "x86-64-Haswell_GCE",
Mike Klein9a01a212017-11-03 12:19:54 -0400464 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400465 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400466 "AVX512": {
467 "GCE": "x86-64-Skylake_GCE",
468 },
borenetdb182c72016-09-30 12:53:12 -0700469 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400470 if !ok {
471 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
472 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400473 cpu, ok := modelMapping[parts["model"]]
474 if !ok {
475 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700476 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400477 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500478 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
479 d["os"] = DEFAULT_OS_LINUX_GCE
480 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400481 if parts["model"] == "GCE" && d["cpu"] == "x86-64-Haswell_GCE" {
482 // nanobench runs single-threaded, so use a small machine.
483 // dm is multi-threaded for CPU, so use a large machine.
484 machineType, ok := map[string]string{
485 "Calmbench": MACHINE_TYPE_SMALL,
486 "Perf": MACHINE_TYPE_SMALL,
487 "Test": MACHINE_TYPE_LARGE,
488 }[parts["role"]]
489 if !ok {
490 glog.Fatalf("Entry %q not found in GCE machine type mapping.", parts["role"])
491 }
Ben Wagner27d5a362018-05-09 15:37:34 -0400492 // Coverage gets slower with more cores.
493 if strings.Contains(parts["extra_config"], "Coverage") {
494 machineType = MACHINE_TYPE_SMALL
495 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400496 d["machine_type"] = machineType
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500497 }
borenetdb182c72016-09-30 12:53:12 -0700498 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400499 if strings.Contains(parts["os"], "Win") {
500 gpu, ok := map[string]string{
Ben Wagnerf6148b62018-03-15 13:53:25 -0400501 "GT610": "10de:104a-23.21.13.9101",
Ben Wagner96ee1192018-02-28 17:30:19 -0500502 "GTX1070": "10de:1ba1-23.21.13.9101",
503 "GTX660": "10de:11c0-23.21.13.9101",
504 "GTX960": "10de:1401-23.21.13.9101",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500505 "IntelHD4400": "8086:0a16-20.19.15.4835",
Ben Wagner300cf062018-04-11 11:29:59 -0400506 "IntelIris540": "8086:1926-23.20.16.4982",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500507 "IntelIris6100": "8086:162b-20.19.15.4835",
Ben Wagnerf8f18392018-04-24 18:17:02 -0400508 "RadeonHD7770": "1002:683d-23.20.15033.5003",
509 "RadeonR9M470X": "1002:6646-23.20.15033.5003",
Ben Wagnerf6148b62018-03-15 13:53:25 -0400510 "QuadroP400": "10de:1cb3-23.21.13.9103",
Ben Wagner1d060782017-06-14 10:34:18 -0400511 }[parts["cpu_or_gpu_value"]]
512 if !ok {
513 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
514 }
515 d["gpu"] = gpu
Ben Wagner08435892017-02-18 23:28:26 -0500516
Ben Wagner4b1df022017-06-15 12:28:04 -0400517 // Specify cpu dimension for NUCs and ShuttleCs. We temporarily have two
518 // types of machines with a GTX960.
519 cpu, ok := map[string]string{
520 "NUC6i7KYK": "x86-64-i7-6770HQ",
521 "ShuttleC": "x86-64-i7-6700K",
Ben Wagner1d060782017-06-14 10:34:18 -0400522 }[parts["model"]]
523 if ok {
Ben Wagner4b1df022017-06-15 12:28:04 -0400524 d["cpu"] = cpu
Ben Wagner1d060782017-06-14 10:34:18 -0400525 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400526 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400527 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400528 // Intel drivers come from CIPD, so no need to specify the version here.
529 "IntelBayTrail": "8086:0f31",
530 "IntelHD2000": "8086:0102",
531 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500532 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400533 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400534 }[parts["cpu_or_gpu_value"]]
535 if !ok {
536 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
537 }
538 d["gpu"] = gpu
539 } else if strings.Contains(parts["os"], "Mac") {
540 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500541 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500542 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400543 "IntelIris5100": "8086:0a2e",
Ben Wagner1d060782017-06-14 10:34:18 -0400544 }[parts["cpu_or_gpu_value"]]
545 if !ok {
546 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
547 }
548 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500549 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
550 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
551 // Run all tasks on Golo machines for now.
552 d["cpu"] = "x86-64-i7-4578U"
553 }
Ben Wagner1d060782017-06-14 10:34:18 -0400554 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500555 version, ok := map[string]string{
Kevin Lubickff8387f2018-05-01 10:43:35 -0400556 "MaliT604": "10575.22.0",
Kevin Lubicke114e592018-05-01 08:53:52 -0400557 "MaliT764": "10575.22.0",
Kevin Lubicke467d4e2018-05-01 13:12:58 -0400558 "MaliT860": "10575.22.0",
559 "PowerVRGX6250": "10575.22.0",
560 "TegraK1": "10575.22.0",
561 "IntelHDGraphics615": "10575.22.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400562 }[parts["cpu_or_gpu_value"]]
563 if !ok {
564 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
565 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500566 d["gpu"] = parts["cpu_or_gpu_value"]
567 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400568 } else {
569 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500570 }
borenetdb182c72016-09-30 12:53:12 -0700571 }
572 } else {
573 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400574 if d["os"] == DEFAULT_OS_DEBIAN {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400575 // Use many-core machines for Build tasks.
576 return linuxGceDimensions(MACHINE_TYPE_LARGE)
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500577 } else if d["os"] == DEFAULT_OS_WIN {
578 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400579 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagnere99a4b12018-05-04 11:18:01 -0400580 // Use many-core machines for Build tasks.
581 d["machine_type"] = MACHINE_TYPE_LARGE
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500582 } else if d["os"] == DEFAULT_OS_MAC {
583 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400584 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400585 }
borenetdb182c72016-09-30 12:53:12 -0700586 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400587
borenetdb182c72016-09-30 12:53:12 -0700588 rv := make([]string, 0, len(d))
589 for k, v := range d {
590 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
591 }
592 sort.Strings(rv)
593 return rv
594}
595
Eric Boren7e3a3642017-06-14 15:25:31 -0400596// relpath returns the relative path to the given file from the config file.
597func relpath(f string) string {
598 _, filename, _, _ := runtime.Caller(0)
599 dir := path.Dir(filename)
600 rel := dir
601 if *cfgFile != "" {
602 rel = path.Dir(*cfgFile)
603 }
604 rv, err := filepath.Rel(rel, path.Join(dir, f))
605 if err != nil {
606 sklog.Fatal(err)
607 }
608 return rv
609}
610
Eric Boren8b3f9e62017-04-04 09:06:16 -0400611// bundleRecipes generates the task to bundle and isolate the recipes.
612func bundleRecipes(b *specs.TasksCfgBuilder) string {
613 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren9599b0f2018-04-17 15:55:57 -0400614 CipdPackages: CIPD_PKGS_GIT,
615 Command: []string{
616 "/bin/bash", "skia/infra/bots/bundle_recipes.sh", specs.PLACEHOLDER_ISOLATED_OUTDIR,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400617 },
Ben Wagnere99a4b12018-05-04 11:18:01 -0400618 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400619 EnvPrefixes: map[string][]string{
620 "PATH": []string{"cipd_bin_packages", "cipd_bin_packages/bin"},
621 },
622 Isolate: relpath("swarm_recipe.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400623 Priority: 0.7,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400624 })
625 return BUNDLE_RECIPES_NAME
626}
627
Kevin Lubick07072942017-05-11 13:35:23 -0400628type isolateAssetCfg struct {
Eric Boren9599b0f2018-04-17 15:55:57 -0400629 cipdPkg string
630 path string
Kevin Lubick07072942017-05-11 13:35:23 -0400631}
632
633var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500634 ISOLATE_GCLOUD_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400635 cipdPkg: "gcloud_linux",
636 path: "gcloud_linux",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500637 },
638 ISOLATE_GO_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400639 cipdPkg: "go",
640 path: "go",
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500641 },
Kevin Lubick07072942017-05-11 13:35:23 -0400642 ISOLATE_SKIMAGE_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400643 cipdPkg: "skimage",
644 path: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400645 },
646 ISOLATE_SKP_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400647 cipdPkg: "skp",
648 path: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400649 },
650 ISOLATE_SVG_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400651 cipdPkg: "svg",
652 path: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400653 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500654 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400655 cipdPkg: "android_ndk_linux",
656 path: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500657 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500658 ISOLATE_SDK_LINUX_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400659 cipdPkg: "android_sdk_linux",
660 path: "android_sdk_linux",
Stephan Altmueller2a552172018-02-20 11:40:25 -0500661 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500662 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400663 cipdPkg: "win_toolchain",
664 path: "t",
Kevin Lubick814b1492017-11-29 14:45:14 -0500665 },
666 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9599b0f2018-04-17 15:55:57 -0400667 cipdPkg: "win_vulkan_sdk",
668 path: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500669 },
Kevin Lubick07072942017-05-11 13:35:23 -0400670}
671
Eric Boren9599b0f2018-04-17 15:55:57 -0400672// isolateCIPDAsset generates a task to isolate the given CIPD asset.
Kevin Lubick07072942017-05-11 13:35:23 -0400673func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400674 asset := ISOLATE_ASSET_MAPPING[name]
Kevin Lubick07072942017-05-11 13:35:23 -0400675 b.MustAddTask(name, &specs.TaskSpec{
676 CipdPackages: []*specs.CipdPackage{
Eric Boren9599b0f2018-04-17 15:55:57 -0400677 b.MustGetCipdPackageFromAsset(asset.cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400678 },
Eric Boren9599b0f2018-04-17 15:55:57 -0400679 Command: []string{"/bin/cp", "-rL", asset.path, "${ISOLATED_OUTDIR}"},
Ben Wagnere99a4b12018-05-04 11:18:01 -0400680 Dimensions: linuxGceDimensions(MACHINE_TYPE_SMALL),
Eric Boren9599b0f2018-04-17 15:55:57 -0400681 Isolate: relpath("empty.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400682 Priority: 0.7,
683 })
684 return name
685}
686
Kevin Lubick90189522017-05-15 08:30:27 -0400687// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
688// This allows us to save time on I/O bound bots, like the RPIs.
689func getIsolatedCIPDDeps(parts map[string]string) []string {
690 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400691 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
692 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400693 rpiOS := []string{"Android", "ChromeOS", "iOS"}
694
695 if o := parts["os"]; strings.Contains(o, "Chromecast") {
696 // Chromecasts don't have enough disk space to fit all of the content,
697 // so we do a subset of the skps.
698 deps = append(deps, ISOLATE_SKP_NAME)
699 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
700 // Skpbench only needs skps
701 deps = append(deps, ISOLATE_SKP_NAME)
702 } else if util.In(o, rpiOS) {
703 deps = append(deps, ISOLATE_SKP_NAME)
704 deps = append(deps, ISOLATE_SVG_NAME)
705 deps = append(deps, ISOLATE_SKIMAGE_NAME)
706 }
707
708 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400709}
710
Eric Boren5cb5c742018-04-27 13:14:38 -0400711// usesGit adds attributes to tasks which use git.
712func usesGit(t *specs.TaskSpec, name string) {
713 t.Caches = append(t.Caches, CACHES_GIT...)
714 if !strings.Contains(name, "NoDEPS") {
715 t.Caches = append(t.Caches, CACHES_WORKDIR...)
716 }
717 t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
718}
719
720// timeout sets the timeout(s) for this task.
721func timeout(task *specs.TaskSpec, timeout time.Duration) {
722 task.ExecutionTimeout = timeout
723 task.IoTimeout = timeout // With kitchen, step logs don't count toward IoTimeout.
724}
725
borenetdb182c72016-09-30 12:53:12 -0700726// compile generates a compile task. Returns the name of the last task in the
727// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700728func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400729 task := kitchenTask(name, "compile", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, swarmDimensions(parts), nil, OUTPUT_BUILD)
Eric Boren5cb5c742018-04-27 13:14:38 -0400730 usesGit(task, name)
borenetdb182c72016-09-30 12:53:12 -0700731
732 // Android bots require a toolchain.
733 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500734 if parts["extra_config"] == "Android_Framework" {
735 // Do not need a toolchain when building the
736 // Android Framework.
737 } else if strings.Contains(name, "Mac") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400738 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400739 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400740 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
741 pkg.Path = "n"
Eric Boren9599b0f2018-04-17 15:55:57 -0400742 task.CipdPackages = append(task.CipdPackages, pkg)
borenetdb182c72016-09-30 12:53:12 -0700743 } else {
Eric Boren9599b0f2018-04-17 15:55:57 -0400744 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500745 if strings.Contains(name, "SKQP") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400746 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_SDK_LINUX_NAME), isolateCIPDAsset(b, ISOLATE_GO_LINUX_NAME))
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500747 }
borenetdb182c72016-09-30 12:53:12 -0700748 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500749 } else if strings.Contains(name, "Chromecast") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400750 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cast_toolchain"))
751 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400752 } else if strings.Contains(name, "Chromebook") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400753 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400754 if parts["target_arch"] == "x86_64" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400755 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400756 } else if parts["target_arch"] == "arm" {
Eric Boren9599b0f2018-04-17 15:55:57 -0400757 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
758 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400759 }
Eric Boren5cb5c742018-04-27 13:14:38 -0400760 } else if strings.Contains(name, "CommandBuffer") {
761 timeout(task, 2*time.Hour)
Eric Borenbb198fb2017-06-28 11:45:54 -0400762 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500763 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400764 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500765 }
766 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400767 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500768 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400769 if strings.Contains(name, "EMCC") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400770 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("emscripten_sdk"))
Kevin Lubickebf648e2017-09-21 13:45:16 -0400771 }
Ben Wagner9bd736b2018-04-04 15:35:01 -0400772 if parts["target_arch"] == "mips64el" || parts["target_arch"] == "loongson3a" {
773 if parts["compiler"] != "GCC" {
774 glog.Fatalf("mips64el toolchain is GCC, but compiler is %q in %q", parts["compiler"], name)
775 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400776 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("mips64el_toolchain_linux"))
Ben Wagner9bd736b2018-04-04 15:35:01 -0400777 }
Ben Wagnerbbdee1b2018-04-19 17:53:03 -0400778 if strings.Contains(name, "SwiftShader") {
779 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("cmake_linux"))
780 }
Mike Klein27dcee12016-11-09 16:31:42 -0500781 } else if strings.Contains(name, "Win") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400782 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400783 if strings.Contains(name, "Clang") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400784 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_win"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400785 }
borenetdb182c72016-09-30 12:53:12 -0700786 if strings.Contains(name, "Vulkan") {
Eric Boren9599b0f2018-04-17 15:55:57 -0400787 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700788 }
789 }
790
Ben Wagneradeb75d2018-04-19 21:48:55 -0400791 task.MaxAttempts = 1
Eric Borenc2a88702018-04-26 11:56:09 -0400792 if strings.Contains(name, "Win") {
793 task.MaxAttempts = 2
794 }
Ben Wagneradeb75d2018-04-19 21:48:55 -0400795
Eric Borenbd2e1f12018-04-17 11:28:46 +0000796 // Add the task.
Eric Boren9599b0f2018-04-17 15:55:57 -0400797 b.MustAddTask(name, task)
798
Eric Boren8615fe52016-12-12 14:30:12 -0500799 // All compile tasks are runnable as their own Job. Assert that the Job
800 // is listed in JOBS.
801 if !util.In(name, JOBS) {
802 glog.Fatalf("Job %q is missing from the JOBS list!", name)
803 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500804
805 // Upload the skiaserve binary only for Linux Android compile bots.
806 // See skbug.com/7399 for context.
807 if parts["configuration"] == "Release" &&
808 parts["extra_config"] == "Android" &&
809 !strings.Contains(parts["os"], "Win") &&
810 !strings.Contains(parts["os"], "Mac") {
811 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Ben Wagnere99a4b12018-05-04 11:18:01 -0400812 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 -0400813 task.Dependencies = append(task.Dependencies, name)
814 b.MustAddTask(uploadName, task)
Ravi Mistry6f136222017-12-12 17:08:24 -0500815 return uploadName
816 }
817
borenetdb182c72016-09-30 12:53:12 -0700818 return name
819}
820
821// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
822// task in the generated chain of tasks, which the Job should add as a
823// dependency.
Eric Boren27688612018-04-16 13:21:01 +0000824func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400825 task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, linuxGceDimensions(MACHINE_TYPE_LARGE), nil, OUTPUT_NONE)
Eric Borene7950e32018-04-26 08:49:38 -0400826 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400827 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
Eric Boren5cb5c742018-04-27 13:14:38 -0400828 timeout(task, 4*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400829 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700830 return name
831}
832
833// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
834// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000835func ctSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren9599b0f2018-04-17 15:55:57 -0400836 dims := []string{
837 "pool:SkiaCT",
838 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
839 }
840 task := kitchenTask(name, "ct_skps", "skia_repo.isolate", SERVICE_ACCOUNT_CT_SKPS, dims, nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400841 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400842 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
Eric Boren5cb5c742018-04-27 13:14:38 -0400843 timeout(task, 24*time.Hour)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400844 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400845 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700846 return name
847}
848
Eric Borenf7928b42017-07-28 07:35:28 -0400849// checkGeneratedFiles verifies that no generated SKSL files have been edited
850// by hand.
Eric Boren27688612018-04-16 13:21:01 +0000851func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400852 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 -0400853 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400854 b.MustAddTask(name, task)
Eric Borenf7928b42017-07-28 07:35:28 -0400855 return name
856}
857
borenetdb182c72016-09-30 12:53:12 -0700858// housekeeper generates a Housekeeper task. Returns the name of the last task
859// in the generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000860func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400861 task := kitchenTask(name, "housekeeper", "swarm_recipe.isolate", SERVICE_ACCOUNT_HOUSEKEEPER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400862 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400863 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
864 task.Dependencies = append(task.Dependencies, compileTaskName)
865 b.MustAddTask(name, task)
borenetdb182c72016-09-30 12:53:12 -0700866 return name
867}
868
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500869// bookmaker generates a Bookmaker task. Returns the name of the last task
870// in the generated chain of tasks, which the Job should add as a dependency.
871func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400872 task := kitchenTask(name, "bookmaker", "swarm_recipe.isolate", SERVICE_ACCOUNT_BOOKMAKER, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400873 task.Caches = append(task.Caches, CACHES_WORKDIR...)
Eric Borene7950e32018-04-26 08:49:38 -0400874 task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
Eric Boren9599b0f2018-04-17 15:55:57 -0400875 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
876 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -0400877 timeout(task, 2*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400878 b.MustAddTask(name, task)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500879 return name
880}
881
Ravi Mistry5e967422018-02-01 13:38:13 -0500882// androidFrameworkCompile generates an Android Framework Compile task. Returns
883// the name of the last task in the generated chain of tasks, which the Job
884// should add as a dependency.
885func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400886 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 -0400887 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -0400888 timeout(task, time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400889 b.MustAddTask(name, task)
Ravi Mistry5e967422018-02-01 13:38:13 -0500890 return name
891}
892
borenet2dbbfa52016-10-14 06:32:09 -0700893// infra generates an infra_tests task. Returns the name of the last task in the
894// generated chain of tasks, which the Job should add as a dependency.
Eric Boren27688612018-04-16 13:21:01 +0000895func infra(b *specs.TasksCfgBuilder, name string) string {
Ben Wagnere99a4b12018-05-04 11:18:01 -0400896 task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
Eric Boren5cb5c742018-04-27 13:14:38 -0400897 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400898 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
899 b.MustAddTask(name, task)
borenet2dbbfa52016-10-14 06:32:09 -0700900 return name
901}
902
Yuqian Li4a577af2018-01-05 11:13:43 -0500903func getParentRevisionName(compileTaskName string, parts map[string]string) string {
904 if parts["extra_config"] == "" {
905 return compileTaskName + "-ParentRevision"
906 } else {
907 return compileTaskName + "_ParentRevision"
908 }
909}
910
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400911// calmbench generates a calmbench task. Returns the name of the last task in the
912// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9599b0f2018-04-17 15:55:57 -0400913func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName, compileParentName string) string {
914 task := kitchenTask(name, "calmbench", "calmbench.isolate", "", swarmDimensions(parts), nil, OUTPUT_PERF)
Eric Boren5cb5c742018-04-27 13:14:38 -0400915 usesGit(task, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400916 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
917 task.Dependencies = append(task.Dependencies, compileTaskName, compileParentName, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
Ben Wagneradeb75d2018-04-19 21:48:55 -0400918 task.MaxAttempts = 1
Eric Boren9599b0f2018-04-17 15:55:57 -0400919 b.MustAddTask(name, task)
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400920
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400921 // Upload results if necessary.
922 if strings.Contains(name, "Release") && doUpload(name) {
923 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400924 extraProps := map[string]string{
925 "gs_bucket": CONFIG.GsBucketCalm,
926 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400927 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 -0400928 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
929 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
930 b.MustAddTask(uploadName, uploadTask)
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400931 return uploadName
932 }
933
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400934 return name
935}
936
borenetdb182c72016-09-30 12:53:12 -0700937// doUpload indicates whether the given Job should upload its results.
938func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -0500939 for _, s := range CONFIG.NoUpload {
940 m, err := regexp.MatchString(s, name)
941 if err != nil {
942 glog.Fatal(err)
943 }
944 if m {
borenetdb182c72016-09-30 12:53:12 -0700945 return false
946 }
947 }
948 return true
949}
950
951// test generates a Test task. Returns the name of the last task in the
952// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700953func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500954 recipe := "test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500955 if strings.Contains(name, "SKQP") {
956 recipe = "skqp_test"
Stephan Altmueller88df8d22018-03-07 14:44:44 -0500957 }
Eric Boreneb702382018-04-19 09:36:45 -0400958 extraProps := map[string]string{}
959 iid := internalHardwareLabel(parts)
960 if iid != nil {
961 extraProps["internal_hardware_label"] = strconv.Itoa(*iid)
962 }
Eric Borene9a67002018-04-24 13:12:05 -0400963 task := kitchenTask(name, recipe, "test_skia_bundled.isolate", "", swarmDimensions(parts), extraProps, OUTPUT_TEST)
Eric Boren9599b0f2018-04-17 15:55:57 -0400964 task.CipdPackages = append(task.CipdPackages, pkgs...)
965 task.Dependencies = append(task.Dependencies, compileTaskName)
966 if strings.Contains(name, "Android_ASAN") {
967 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
Eric Boren9d78afd2017-12-07 14:54:05 +0000968 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400969 if strings.Contains(name, "SKQP") {
970 task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GCLOUD_LINUX_NAME))
Eric Boren8b3f9e62017-04-04 09:06:16 -0400971 }
Kevin Lubick90189522017-05-15 08:30:27 -0400972 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -0400973 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -0400974 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400975 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -0400976 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -0400977 timeout(task, 4*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -0500978 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -0400979 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -0400980 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -0400981 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
982 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -0500983 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -0400984 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -0400985 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
986 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -0400987 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -0500988 }
Eric Boren9599b0f2018-04-17 15:55:57 -0400989 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -0500990
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400991 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
992 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -0700993 if doUpload(name) {
994 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -0400995 extraProps := map[string]string{
996 "gs_bucket": CONFIG.GsBucketGm,
997 }
Ben Wagnere99a4b12018-05-04 11:18:01 -0400998 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 -0400999 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1000 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1001 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001002 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -04001003 }
1004
1005 return name
1006}
1007
1008func coverage(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
1009 shards := 1
1010 deps := []string{}
1011
1012 tf := parts["test_filter"]
1013 if strings.Contains(tf, "Shard") {
1014 // Expected Shard_NN
1015 shardstr := strings.Split(tf, "_")[1]
1016 var err error
1017 shards, err = strconv.Atoi(shardstr)
1018 if err != nil {
1019 glog.Fatalf("Expected int for number of shards %q in %s: %s", shardstr, name, err)
1020 }
1021 }
1022 for i := 0; i < shards; i++ {
1023 n := strings.Replace(name, tf, fmt.Sprintf("shard_%02d_%02d", i, shards), 1)
Eric Boren9599b0f2018-04-17 15:55:57 -04001024 task := kitchenTask(n, "test", "test_skia_bundled.isolate", "", swarmDimensions(parts), nil, OUTPUT_COVERAGE)
1025 task.CipdPackages = append(task.CipdPackages, pkgs...)
1026 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren5cb5c742018-04-27 13:14:38 -04001027
Eric Boren9599b0f2018-04-17 15:55:57 -04001028 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001029 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001030 timeout(task, 4*time.Hour)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001031 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001032 task.Dependencies = append(task.Dependencies, deps...)
Eric Borenbd2e1f12018-04-17 11:28:46 +00001033 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001034 b.MustAddTask(n, task)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001035 deps = append(deps, n)
borenetdb182c72016-09-30 12:53:12 -07001036 }
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001037
Kevin Lubick32f318b2017-10-17 13:40:52 -04001038 uploadName := fmt.Sprintf("%s%s%s", "Upload", jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001039 extraProps := map[string]string{
1040 "gs_bucket": CONFIG.GsBucketCoverage,
1041 }
Ben Wagner27d5a362018-05-09 15:37:34 -04001042 // Use MACHINE_TYPE_LARGE because this does a bunch of computation before upload.
1043 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 -04001044 usesGit(uploadTask, uploadName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001045 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001046 // We need clang_linux to get access to the llvm-profdata and llvm-cov binaries
1047 // which are used to deal with the raw coverage data output by the Test step.
Eric Boren9599b0f2018-04-17 15:55:57 -04001048 uploadTask.CipdPackages = append(uploadTask.CipdPackages, b.MustGetCipdPackageFromAsset("clang_linux"))
1049 uploadTask.CipdPackages = append(uploadTask.CipdPackages, pkgs...)
1050 // A dependency on compileTaskName makes the TaskScheduler link the
1051 // isolated output of the compile step to the input of the upload step,
1052 // which gives us access to the instrumented binary. The binary is
1053 // needed to figure out symbol names and line numbers.
1054 uploadTask.Dependencies = append(uploadTask.Dependencies, compileTaskName)
1055 uploadTask.Dependencies = append(uploadTask.Dependencies, deps...)
1056 b.MustAddTask(uploadName, uploadTask)
Kevin Lubick32f318b2017-10-17 13:40:52 -04001057 return uploadName
borenetdb182c72016-09-30 12:53:12 -07001058}
1059
1060// perf generates a Perf task. Returns the name of the last task in the
1061// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001062func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001063 recipe := "perf"
Eric Boren9599b0f2018-04-17 15:55:57 -04001064 isolate := relpath("perf_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001065 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001066 recipe = "skpbench"
Eric Boren9599b0f2018-04-17 15:55:57 -04001067 isolate = relpath("skpbench_skia_bundled.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001068 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001069 task := kitchenTask(name, recipe, isolate, "", swarmDimensions(parts), nil, OUTPUT_PERF)
1070 task.CipdPackages = append(task.CipdPackages, pkgs...)
1071 task.Dependencies = append(task.Dependencies, compileTaskName)
Eric Boren9599b0f2018-04-17 15:55:57 -04001072 task.Expiration = 20 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001073 task.MaxAttempts = 1
Eric Boren5cb5c742018-04-27 13:14:38 -04001074 timeout(task, 4*time.Hour)
Kevin Lubick90189522017-05-15 08:30:27 -04001075 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
Eric Boren9599b0f2018-04-17 15:55:57 -04001076 task.Dependencies = append(task.Dependencies, deps...)
Kevin Lubick90189522017-05-15 08:30:27 -04001077 }
1078
Eric Boren4b254b92016-11-08 12:55:32 -05001079 if strings.Contains(parts["extra_config"], "Valgrind") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001080 timeout(task, 9*time.Hour)
Eric Boren9599b0f2018-04-17 15:55:57 -04001081 task.Expiration = 48 * time.Hour
Eric Boren9599b0f2018-04-17 15:55:57 -04001082 task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
1083 task.Dimensions = append(task.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001084 } else if strings.Contains(parts["extra_config"], "MSAN") {
Eric Boren5cb5c742018-04-27 13:14:38 -04001085 timeout(task, 9*time.Hour)
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001086 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1087 // skia:6737
Eric Boren5cb5c742018-04-27 13:14:38 -04001088 timeout(task, 6*time.Hour)
Eric Boren4b254b92016-11-08 12:55:32 -05001089 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001090 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001091 if iid != nil {
Eric Boren9599b0f2018-04-17 15:55:57 -04001092 task.Command = append(task.Command, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001093 }
Eric Boren9599b0f2018-04-17 15:55:57 -04001094 b.MustAddTask(name, task)
Eric Boren4b254b92016-11-08 12:55:32 -05001095
borenetdb182c72016-09-30 12:53:12 -07001096 // Upload results if necessary.
1097 if strings.Contains(name, "Release") && doUpload(name) {
1098 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
Eric Boren9599b0f2018-04-17 15:55:57 -04001099 extraProps := map[string]string{
1100 "gs_bucket": CONFIG.GsBucketNano,
1101 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001102 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 -04001103 uploadTask.CipdPackages = append(uploadTask.CipdPackages, CIPD_PKGS_GSUTIL...)
1104 uploadTask.Dependencies = append(uploadTask.Dependencies, name)
1105 b.MustAddTask(uploadName, uploadTask)
borenetdb182c72016-09-30 12:53:12 -07001106 return uploadName
1107 }
1108 return name
1109}
1110
Eric Borenb66099b2018-04-25 15:09:22 -04001111// Run the presubmit.
1112func presubmit(b *specs.TasksCfgBuilder, name string) string {
1113 extraProps := map[string]string{
1114 "category": "cq",
1115 "patch_gerrit_url": "https://skia-review.googlesource.com",
1116 "patch_project": "skia",
Eric Boren2f62de02018-05-03 09:56:48 -04001117 "patch_ref": specs.PLACEHOLDER_PATCH_REF,
Eric Borenb66099b2018-04-25 15:09:22 -04001118 "reason": "CQ",
1119 "repo_name": "skia",
1120 }
Ben Wagnere99a4b12018-05-04 11:18:01 -04001121 // Use MACHINE_TYPE_LARGE because it seems to save ~1m and we want presubmit to be fast.
1122 task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_LARGE), extraProps, OUTPUT_NONE)
Eric Borenb66099b2018-04-25 15:09:22 -04001123
1124 replaceArg := func(key, value string) {
1125 found := false
1126 for idx, arg := range task.Command {
1127 if arg == key {
1128 task.Command[idx+1] = value
1129 found = true
1130 }
1131 }
1132 if !found {
1133 task.Command = append(task.Command, key, value)
1134 }
1135 }
1136 replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
1137 replaceArg("-revision", "HEAD")
Eric Boren5cb5c742018-04-27 13:14:38 -04001138 usesGit(task, name)
Eric Borenb66099b2018-04-25 15:09:22 -04001139 task.Dependencies = []string{} // No bundled recipes for this one.
1140 b.MustAddTask(name, task)
1141 return name
1142}
1143
borenetdb182c72016-09-30 12:53:12 -07001144// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001145func process(b *specs.TasksCfgBuilder, name string) {
borenetdb182c72016-09-30 12:53:12 -07001146 deps := []string{}
1147
Eric Boren8b3f9e62017-04-04 09:06:16 -04001148 // Bundle Recipes.
1149 if name == BUNDLE_RECIPES_NAME {
1150 deps = append(deps, bundleRecipes(b))
1151 }
1152
Kevin Lubick07072942017-05-11 13:35:23 -04001153 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001154 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1155 deps = append(deps, isolateCIPDAsset(b, name))
1156 }
1157
borenetdb182c72016-09-30 12:53:12 -07001158 parts, err := jobNameSchema.ParseJobName(name)
1159 if err != nil {
1160 glog.Fatal(err)
1161 }
1162
1163 // RecreateSKPs.
1164 if strings.Contains(name, "RecreateSKPs") {
Eric Boren27688612018-04-16 13:21:01 +00001165 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001166 }
1167
1168 // CT bots.
1169 if strings.Contains(name, "-CT_") {
Eric Boren27688612018-04-16 13:21:01 +00001170 deps = append(deps, ctSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001171 }
1172
borenet2dbbfa52016-10-14 06:32:09 -07001173 // Infra tests.
1174 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren27688612018-04-16 13:21:01 +00001175 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001176 }
1177
borenetdb182c72016-09-30 12:53:12 -07001178 // Compile bots.
1179 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001180 if parts["extra_config"] == "Android_Framework" {
1181 // Android Framework compile tasks use a different recipe.
1182 deps = append(deps, androidFrameworkCompile(b, name))
1183 } else {
1184 deps = append(deps, compile(b, name, parts))
1185 }
borenetdb182c72016-09-30 12:53:12 -07001186 }
1187
Eric Borenf5a90e82016-11-15 15:18:20 -05001188 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001189 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001190 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1191 if err != nil {
1192 glog.Fatal(err)
1193 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001194 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1195 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1196 if err != nil {
1197 glog.Fatal(err)
1198 }
1199
Eric Boren628e78b2016-11-17 11:33:27 -05001200 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001201 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001202 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001203 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001204 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Borenb66099b2018-04-25 15:09:22 -04001205 name != "Housekeeper-OnDemand-Presubmit" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001206 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001207 !strings.Contains(name, "RecreateSKPs") &&
Ben Wagner50b84682017-06-12 13:03:29 -04001208 !strings.Contains(name, "-CT_") &&
1209 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") {
boreneted20a702016-10-20 11:04:31 -07001210 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001211 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001212 compile(b, compileParentName, compileParentParts)
1213 }
borenet52383432016-10-17 10:17:53 -07001214 }
borenetdb182c72016-09-30 12:53:12 -07001215
Eric Borenf7928b42017-07-28 07:35:28 -04001216 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001217 if name == "Housekeeper-PerCommit" {
Eric Boren27688612018-04-16 13:21:01 +00001218 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -07001219 }
Eric Borenf7928b42017-07-28 07:35:28 -04001220 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren27688612018-04-16 13:21:01 +00001221 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001222 }
Eric Borenb66099b2018-04-25 15:09:22 -04001223 if name == "Housekeeper-OnDemand-Presubmit" {
1224 deps = append(deps, presubmit(b, name))
1225 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001226 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001227 deps = append(deps, bookmaker(b, name, compileTaskName))
1228 }
borenetdb182c72016-09-30 12:53:12 -07001229
1230 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001231
1232 pkgs := []*specs.CipdPackage{}
1233
Kevin Lubick90189522017-05-15 08:30:27 -04001234 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001235 pkgs = []*specs.CipdPackage{
1236 b.MustGetCipdPackageFromAsset("skimage"),
1237 b.MustGetCipdPackageFromAsset("skp"),
1238 b.MustGetCipdPackageFromAsset("svg"),
1239 }
borenetdb182c72016-09-30 12:53:12 -07001240 }
Kevin Lubick90189522017-05-15 08:30:27 -04001241
Ben Wagner5655ba42017-10-02 10:48:32 -04001242 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1243 if strings.Contains(name, "SAN") {
1244 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1245 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001246 if strings.Contains(name, "Vulkan") {
1247 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1248 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001249 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
1250 if strings.Contains(name, "Release") {
1251 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
1252 } else {
1253 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
1254 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001255 }
1256 }
Ben Wagner299b8822018-03-09 13:42:56 -05001257 if strings.Contains(name, "ProcDump") {
1258 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("procdump_win"))
1259 }
borenetdb182c72016-09-30 12:53:12 -07001260
1261 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001262 if parts["role"] == "Test" {
1263 if strings.Contains(parts["extra_config"], "Coverage") {
1264 deps = append(deps, coverage(b, name, parts, compileTaskName, pkgs))
1265 } else if !strings.Contains(name, "-CT_") {
1266 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
1267 }
1268
borenetdb182c72016-09-30 12:53:12 -07001269 }
1270
1271 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -05001272 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -07001273 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001274 }
1275
Yuqian Li4a577af2018-01-05 11:13:43 -05001276 // Calmbench bots.
1277 if parts["role"] == "Calmbench" {
1278 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1279 }
1280
borenetdb182c72016-09-30 12:53:12 -07001281 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001282 j := &specs.JobSpec{
borenetdb182c72016-09-30 12:53:12 -07001283 Priority: 0.8,
1284 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001285 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001286 }
Eric Borenba937a42017-07-31 10:41:15 -04001287 if strings.Contains(name, "-Nightly-") {
1288 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryf06dae82017-10-16 10:31:41 -04001289 } else if strings.Contains(name, "-Weekly-") || strings.Contains(name, "CT_DM_1m_SKPs") {
Eric Borenba937a42017-07-31 10:41:15 -04001290 j.Trigger = specs.TRIGGER_WEEKLY
Eric Boren44a68b32018-05-04 08:59:16 -04001291 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "CommandBuffer") {
Eric Borenba937a42017-07-31 10:41:15 -04001292 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren1178ea02018-04-26 08:58:26 -04001293 } else if strings.Contains(name, "-OnDemand-") || strings.Contains(name, "Android_Framework") {
Eric Borenb66099b2018-04-25 15:09:22 -04001294 j.Trigger = specs.TRIGGER_ON_DEMAND
Eric Boren71b762f2016-11-30 14:05:16 -05001295 }
Eric Boren8615fe52016-12-12 14:30:12 -05001296 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001297}
1298
Eric Boren27225492017-02-01 15:56:55 -05001299func loadJson(flag *string, defaultFlag string, val interface{}) {
1300 if *flag == "" {
1301 *flag = defaultFlag
1302 }
1303 b, err := ioutil.ReadFile(*flag)
1304 if err != nil {
1305 glog.Fatal(err)
1306 }
1307 if err := json.Unmarshal(b, val); err != nil {
1308 glog.Fatal(err)
1309 }
1310}
1311
borenetdb182c72016-09-30 12:53:12 -07001312// Regenerate the tasks.json file.
1313func main() {
boreneted20a702016-10-20 11:04:31 -07001314 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001315 b.SetAssetsDir(*assetsDir)
1316 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1317
1318 // Load the jobs from a JSON file.
1319 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1320
Eric Boren27225492017-02-01 15:56:55 -05001321 // Load general config information from a JSON file.
1322 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1323
borenetdb182c72016-09-30 12:53:12 -07001324 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001325 if *builderNameSchemaFile == "" {
1326 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1327 }
1328 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001329 if err != nil {
1330 glog.Fatal(err)
1331 }
1332 jobNameSchema = schema
1333
borenetdb182c72016-09-30 12:53:12 -07001334 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001335 for _, name := range JOBS {
1336 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001337 }
1338
boreneted20a702016-10-20 11:04:31 -07001339 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001340}
1341
1342// TODO(borenet): The below really belongs in its own file, probably next to the
1343// builder_name_schema.json file.
1344
Eric Boren8ff86a62018-04-17 14:11:23 -04001345// schema is a sub-struct of JobNameSchema.
1346type schema struct {
1347 Keys []string `json:"keys"`
1348 OptionalKeys []string `json:"optional_keys"`
1349 RecurseRoles []string `json:"recurse_roles"`
1350}
1351
borenetdb182c72016-09-30 12:53:12 -07001352// JobNameSchema is a struct used for (de)constructing Job names in a
1353// predictable format.
1354type JobNameSchema struct {
Eric Boren8ff86a62018-04-17 14:11:23 -04001355 Schema map[string]*schema `json:"builder_name_schema"`
1356 Sep string `json:"builder_name_sep"`
borenetdb182c72016-09-30 12:53:12 -07001357}
1358
1359// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1360// file.
1361func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1362 var rv JobNameSchema
1363 f, err := os.Open(jsonFile)
1364 if err != nil {
1365 return nil, err
1366 }
1367 defer util.Close(f)
1368 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1369 return nil, err
1370 }
1371 return &rv, nil
1372}
1373
1374// ParseJobName splits the given Job name into its component parts, according
1375// to the schema.
1376func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
Eric Boren8ff86a62018-04-17 14:11:23 -04001377 popFront := func(items []string) (string, []string, error) {
1378 if len(items) == 0 {
1379 return "", nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
1380 }
1381 return items[0], items[1:], nil
1382 }
1383
1384 result := map[string]string{}
1385
1386 var parse func(int, string, []string) ([]string, error)
1387 parse = func(depth int, role string, parts []string) ([]string, error) {
1388 s, ok := s.Schema[role]
1389 if !ok {
1390 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1391 }
1392 if depth == 0 {
1393 result["role"] = role
1394 } else {
1395 result[fmt.Sprintf("sub-role-%d", depth)] = role
1396 }
1397 var err error
1398 for _, key := range s.Keys {
1399 var value string
1400 value, parts, err = popFront(parts)
1401 if err != nil {
1402 return nil, err
1403 }
1404 result[key] = value
1405 }
1406 for _, subRole := range s.RecurseRoles {
1407 if len(parts) > 0 && parts[0] == subRole {
1408 parts, err = parse(depth+1, parts[0], parts[1:])
1409 if err != nil {
1410 return nil, err
1411 }
1412 }
1413 }
1414 for _, key := range s.OptionalKeys {
1415 if len(parts) > 0 {
1416 var value string
1417 value, parts, err = popFront(parts)
1418 if err != nil {
1419 return nil, err
1420 }
1421 result[key] = value
1422 }
1423 }
1424 if len(parts) > 0 {
1425 return nil, fmt.Errorf("Invalid job name: %s (too many parts)", n)
1426 }
1427 return parts, nil
1428 }
1429
borenetdb182c72016-09-30 12:53:12 -07001430 split := strings.Split(n, s.Sep)
1431 if len(split) < 2 {
Eric Boren8ff86a62018-04-17 14:11:23 -04001432 return nil, fmt.Errorf("Invalid job name: %s (not enough parts)", n)
borenetdb182c72016-09-30 12:53:12 -07001433 }
1434 role := split[0]
1435 split = split[1:]
Eric Boren8ff86a62018-04-17 14:11:23 -04001436 _, err := parse(0, role, split)
1437 return result, err
borenetdb182c72016-09-30 12:53:12 -07001438}
1439
1440// MakeJobName assembles the given parts of a Job name, according to the schema.
1441func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
borenetdb182c72016-09-30 12:53:12 -07001442 rvParts := make([]string, 0, len(parts))
Eric Boren8ff86a62018-04-17 14:11:23 -04001443
1444 var process func(int, map[string]string) (map[string]string, error)
1445 process = func(depth int, parts map[string]string) (map[string]string, error) {
1446 roleKey := "role"
1447 if depth != 0 {
1448 roleKey = fmt.Sprintf("sub-role-%d", depth)
borenetdb182c72016-09-30 12:53:12 -07001449 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001450 role, ok := parts[roleKey]
1451 if !ok {
1452 return nil, fmt.Errorf("Invalid job parts; missing key %q", roleKey)
1453 }
1454
1455 s, ok := s.Schema[role]
1456 if !ok {
1457 return nil, fmt.Errorf("Invalid job parts; unknown role %q", role)
1458 }
1459 rvParts = append(rvParts, role)
1460 delete(parts, roleKey)
1461
1462 for _, key := range s.Keys {
1463 value, ok := parts[key]
1464 if !ok {
1465 return nil, fmt.Errorf("Invalid job parts; missing %q", key)
1466 }
1467 rvParts = append(rvParts, value)
1468 delete(parts, key)
1469 }
1470
1471 if len(s.RecurseRoles) > 0 {
1472 subRoleKey := fmt.Sprintf("sub-role-%d", depth+1)
1473 subRole, ok := parts[subRoleKey]
1474 if !ok {
1475 return nil, fmt.Errorf("Invalid job parts; missing %q", subRoleKey)
1476 }
1477 rvParts = append(rvParts, subRole)
1478 delete(parts, subRoleKey)
1479 found := false
1480 for _, recurseRole := range s.RecurseRoles {
1481 if recurseRole == subRole {
1482 found = true
1483 var err error
1484 parts, err = process(depth+1, parts)
1485 if err != nil {
1486 return nil, err
1487 }
1488 break
1489 }
1490 }
1491 if !found {
1492 return nil, fmt.Errorf("Invalid job parts; unknown sub-role %q", subRole)
1493 }
1494 }
1495 for _, key := range s.OptionalKeys {
1496 if value, ok := parts[key]; ok {
1497 rvParts = append(rvParts, value)
1498 delete(parts, key)
1499 }
1500 }
1501 if len(parts) > 0 {
1502 return nil, fmt.Errorf("Invalid job parts: too many parts: %v", parts)
1503 }
1504 return parts, nil
borenetdb182c72016-09-30 12:53:12 -07001505 }
Eric Boren8ff86a62018-04-17 14:11:23 -04001506
1507 // Copy the parts map, so that we can modify at will.
1508 partsCpy := make(map[string]string, len(parts))
1509 for k, v := range parts {
1510 partsCpy[k] = v
1511 }
1512 if _, err := process(0, partsCpy); err != nil {
1513 return "", err
borenetdb182c72016-09-30 12:53:12 -07001514 }
1515 return strings.Join(rvParts, s.Sep), nil
1516}