blob: 6041f9441d1c31a53d5b1b08d3b871f6c9082bf3 [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"
34 ISOLATE_SKIMAGE_NAME = "Housekeeper-PerCommit-IsolateSkImage"
35 ISOLATE_SKP_NAME = "Housekeeper-PerCommit-IsolateSKP"
36 ISOLATE_SVG_NAME = "Housekeeper-PerCommit-IsolateSVG"
37 ISOLATE_NDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidNDKLinux"
Stephan Altmueller2a552172018-02-20 11:40:25 -050038 ISOLATE_SDK_LINUX_NAME = "Housekeeper-PerCommit-IsolateAndroidSDKLinux"
Kevin Lubick814b1492017-11-29 14:45:14 -050039 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
40 ISOLATE_WIN_VULKAN_SDK_NAME = "Housekeeper-PerCommit-IsolateWinVulkanSDK"
Eric Boren8b3f9e62017-04-04 09:06:16 -040041
Eric Boren170c39c2017-11-15 11:22:57 -050042 DEFAULT_OS_DEBIAN = "Debian-9.1"
43 DEFAULT_OS_LINUX_GCE = "Debian-9.2"
Ben Wagner5a9df182018-02-09 11:21:15 -050044 DEFAULT_OS_MAC = "Mac-10.13.3"
Eric Boren170c39c2017-11-15 11:22:57 -050045 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
46 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070047
borenetdb182c72016-09-30 12:53:12 -070048 // Name prefix for upload jobs.
49 PREFIX_UPLOAD = "Upload"
50)
51
52var (
53 // "Constants"
54
Eric Boren27225492017-02-01 15:56:55 -050055 // Top-level list of all jobs to run at each commit; loaded from
56 // jobs.json.
57 JOBS []string
58
Eric Boren27225492017-02-01 15:56:55 -050059 // General configuration information.
60 CONFIG struct {
Kevin Lubickc795a4c2017-10-09 15:26:19 -040061 GsBucketCoverage string `json:"gs_bucket_coverage"`
62 GsBucketGm string `json:"gs_bucket_gm"`
63 GsBucketNano string `json:"gs_bucket_nano"`
Yuqian Li2ebf3d12017-10-24 09:43:21 -040064 GsBucketCalm string `json:"gs_bucket_calm"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040065 NoUpload []string `json:"no_upload"`
66 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070067 }
68
Ben Wagner3d2a2f72017-06-13 17:01:16 -040069 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
70 // dimensions for the given task.
71 alternateSwarmDimensions func(parts map[string]string) []string
72
Eric Borenfd4d60e2017-09-15 10:35:44 -040073 // internalHardwareLabelFn can be set in an init function to provide an
74 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -040075 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -040076
borenetdb182c72016-09-30 12:53:12 -070077 // Defines the structure of job names.
78 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -050079
Eric Borenf4a5fc72017-06-06 08:27:09 -040080 // Git 2.13.
Eric Boren9d78afd2017-12-07 14:54:05 +000081 cipdGit1 = &specs.CipdPackage{
82 Name: fmt.Sprintf("infra/git/${platform}"),
83 Path: "git",
84 Version: fmt.Sprintf("version:2.13.0.chromium9"),
Eric Borenf4a5fc72017-06-06 08:27:09 -040085 }
Eric Boren9d78afd2017-12-07 14:54:05 +000086 cipdGit2 = &specs.CipdPackage{
87 Name: fmt.Sprintf("infra/tools/git/${platform}"),
88 Path: "git",
89 Version: fmt.Sprintf("git_revision:a78b5f3658c0578a017db48df97d20ac09822bcd"),
90 }
Eric Borenf4a5fc72017-06-06 08:27:09 -040091
Eric Boren27225492017-02-01 15:56:55 -050092 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -050093 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.")
94 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
95 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -050096 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -070097)
98
Eric Borenfd4d60e2017-09-15 10:35:44 -040099// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400100func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400101 if internalHardwareLabelFn != nil {
102 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400103 }
104 return nil
105}
106
Eric Boren27225492017-02-01 15:56:55 -0500107// linuxGceDimensions are the Swarming dimensions for Linux GCE
108// instances.
109func linuxGceDimensions() []string {
110 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400111 // Specify CPU to avoid running builds on bots with a more unique CPU.
112 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500113 "gpu:none",
Eric Boren170c39c2017-11-15 11:22:57 -0500114 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500115 fmt.Sprintf("pool:%s", CONFIG.Pool),
116 }
117}
118
borenetdb182c72016-09-30 12:53:12 -0700119// deriveCompileTaskName returns the name of a compile task based on the given
120// job name.
121func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500122 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500123 return "Build-Debian9-GCC-x86_64-Release"
124 } else if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400125 return "Build-Debian9-GCC-x86_64-Release-Shared"
Yuqian Li4a577af2018-01-05 11:13:43 -0500126 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700127 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400128 ec := []string{}
129 if val := parts["extra_config"]; val != "" {
130 ec = strings.Split(val, "_")
Ben Wagnerdba0bc82017-12-11 13:27:27 -0500131 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR", "FSAA", "FAAA", "FDAA", "NativeFonts", "GDI", "NoGPUThreads"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400132 keep := make([]string, 0, len(ec))
133 for _, part := range ec {
134 if !util.In(part, ignore) {
135 keep = append(keep, part)
136 }
137 }
138 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400139 }
borenetdb182c72016-09-30 12:53:12 -0700140 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400141 if !util.In("Android", ec) {
142 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700143 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400144 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500145 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400146 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400147 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400148 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400149 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400150 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700151 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400152 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700153 task_os = "Mac"
154 } else if strings.Contains(task_os, "Win") {
155 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400156 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
157 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700158 }
Eric Boren50831302016-11-18 13:10:51 -0500159 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700160 "role": "Build",
161 "os": task_os,
162 "compiler": parts["compiler"],
163 "target_arch": parts["arch"],
164 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500165 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400166 if len(ec) > 0 {
167 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500168 }
169 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700170 if err != nil {
171 glog.Fatal(err)
172 }
173 return name
174 } else {
175 return jobName
176 }
177}
178
179// swarmDimensions generates swarming bot dimensions for the given task.
180func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400181 if alternateSwarmDimensions != nil {
182 return alternateSwarmDimensions(parts)
183 }
184 return defaultSwarmDimensions(parts)
185}
186
187// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
188func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700189 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500190 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700191 }
192 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400193 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400194 "Android": "Android",
195 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400196 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400197 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500198 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400199 "Ubuntu14": DEFAULT_OS_UBUNTU,
Kevin Lubick291547d2017-03-21 09:25:34 -0400200 "Ubuntu16": "Ubuntu-16.10",
Eric Boren810c2b62017-07-11 08:11:15 -0400201 "Ubuntu17": "Ubuntu-17.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500202 "Win": DEFAULT_OS_WIN,
Ben Wagnerbc989202018-02-28 14:22:27 -0500203 "Win10": "Windows-10-16299.248",
Kevin Lubick291547d2017-03-21 09:25:34 -0400204 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500205 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400206 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400207 "Win8": "Windows-8.1-SP0",
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400208 "iOS": "iOS-10.3.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500209 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400210 if !ok {
211 glog.Fatalf("Entry %q not found in OS mapping.", os)
212 }
Ben Wagnerbc989202018-02-28 14:22:27 -0500213 if os == "Win10" && parts["model"] == "Golo" {
214 // Golo/MTV lab bots have Windows 10 version 1703, whereas Skolo bots have Windows 10 version
215 // 1709.
216 d["os"] = "Windows-10-15063"
Ben Wagnerb3c90fc2018-02-23 11:17:03 -0500217 }
borenetdb182c72016-09-30 12:53:12 -0700218 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400219 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700220 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400221 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400222 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700223 // For Android, the device type is a better dimension
224 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400225 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400226 "AndroidOne": {"sprout", "MOB30Q"},
Kevin Lubickc2f3e8d2018-01-24 15:48:26 -0500227 "Chorizo": {"chorizo", "1.30_109591"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500228 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400229 "GalaxyS7_G930A": {"heroqlteatt", "NRD90M_G930AUCS4BQC2"},
230 "GalaxyS7_G930FD": {"herolte", "NRD90M_G930FXXU1DQAS"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400231 "MotoG4": {"athene", "NPJ25.93-14"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500232 "NVIDIA_Shield": {"foster", "NRD90M_1915764_848"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500233 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500234 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500235 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner9539a8c2017-11-02 14:09:32 -0400236 "NexusPlayer": {"fugu", "OPR6.170623.021"},
Kevin Lubickb5d82b42018-02-20 10:29:45 -0500237 "Pixel": {"sailfish", "OPM1.171019.016"},
Kevin Lubickb018f7b2017-10-31 14:44:08 -0400238 "Pixel2XL": {"taimen", "OPD1.170816.023"},
Kevin Lubick674027a2017-10-31 09:47:38 -0400239 "PixelC": {"dragon", "OPR1.170623.034"},
Ben Wagner36682782017-06-14 10:01:45 -0400240 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500241 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400242 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500243 }
Eric Boren4b254b92016-11-08 12:55:32 -0500244 d["device_type"] = deviceInfo[0]
245 d["device_os"] = deviceInfo[1]
Kevin Lubick4fd283e2017-12-07 11:19:31 -0500246 // TODO(kjlubick): Remove the python dimension after we have removed the
247 // Nexus5x devices from the local lab (on Monday, Dec 11, 2017 should be fine).
Kevin Lubick0f727ff2017-12-06 15:05:29 -0500248 d["python"] = "2.7.9" // This indicates a RPI, e.g. in Skolo. Golo is 2.7.12
Kevin Lubick4fd283e2017-12-07 11:19:31 -0500249 if parts["model"] == "Nexus5x" {
250 d["python"] = "2.7.12"
251 }
borenetdb182c72016-09-30 12:53:12 -0700252 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400253 device, ok := map[string]string{
Eric Boren792079c2016-11-09 14:03:20 -0500254 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400255 "iPhone6": "iPhone7,2",
256 "iPhone7": "iPhone9,1",
257 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700258 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400259 if !ok {
260 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
261 }
262 d["device"] = device
borenetdb182c72016-09-30 12:53:12 -0700263 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400264 modelMapping, ok := map[string]map[string]string{
265 "AVX": {
266 "MacMini7.1": "x86-64-E5-2697_v2",
267 "Golo": "x86-64-E5-2670",
268 },
269 "AVX2": {
Ben Wagner85fb42a2017-11-07 16:57:37 -0500270 "GCE": "x86-64-Haswell_GCE",
Mike Klein9a01a212017-11-03 12:19:54 -0400271 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400272 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400273 "AVX512": {
274 "GCE": "x86-64-Skylake_GCE",
275 },
borenetdb182c72016-09-30 12:53:12 -0700276 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400277 if !ok {
278 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
279 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400280 cpu, ok := modelMapping[parts["model"]]
281 if !ok {
282 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700283 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400284 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500285 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
286 d["os"] = DEFAULT_OS_LINUX_GCE
287 }
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500288 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_WIN {
Ben Wagner832415e2017-12-15 11:23:40 -0500289 // Use normal-size machines for Test and Perf tasks on Win GCE.
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500290 d["machine_type"] = "n1-standard-16"
291 }
borenetdb182c72016-09-30 12:53:12 -0700292 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400293 if strings.Contains(parts["os"], "Win") {
294 gpu, ok := map[string]string{
Ben Wagner0d2b0912017-08-15 12:43:55 -0400295 "GT610": "10de:104a-22.21.13.8205",
Ben Wagner85fb42a2017-11-07 16:57:37 -0500296 "GTX1070": "10de:1ba1-23.21.13.8813",
297 "GTX660": "10de:11c0-23.21.13.8813",
298 "GTX960": "10de:1401-23.21.13.8813",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500299 "IntelHD4400": "8086:0a16-20.19.15.4835",
Ben Wagner7897a612018-02-28 21:18:57 +0000300 "IntelIris540": "8086:1926-21.20.16.4590",
Ben Wagner90e88aa2018-02-26 23:38:52 -0500301 "IntelIris6100": "8086:162b-20.19.15.4835",
Ben Wagner84447e02018-02-28 15:51:30 -0500302 "RadeonHD7770": "1002:683d-23.20.15017.4003",
303 "RadeonR9M470X": "1002:6646-23.20.15017.4003",
Ben Wagnerae532f62017-08-02 23:24:16 -0400304 "QuadroP400": "10de:1cb3-22.21.13.8205",
Ben Wagner1d060782017-06-14 10:34:18 -0400305 }[parts["cpu_or_gpu_value"]]
306 if !ok {
307 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
308 }
309 d["gpu"] = gpu
Ben Wagner08435892017-02-18 23:28:26 -0500310
Ben Wagner4b1df022017-06-15 12:28:04 -0400311 // Specify cpu dimension for NUCs and ShuttleCs. We temporarily have two
312 // types of machines with a GTX960.
313 cpu, ok := map[string]string{
314 "NUC6i7KYK": "x86-64-i7-6770HQ",
315 "ShuttleC": "x86-64-i7-6700K",
Ben Wagner1d060782017-06-14 10:34:18 -0400316 }[parts["model"]]
317 if ok {
Ben Wagner4b1df022017-06-15 12:28:04 -0400318 d["cpu"] = cpu
Ben Wagner1d060782017-06-14 10:34:18 -0400319 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400320 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400321 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400322 // Intel drivers come from CIPD, so no need to specify the version here.
323 "IntelBayTrail": "8086:0f31",
324 "IntelHD2000": "8086:0102",
325 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500326 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400327 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400328 }[parts["cpu_or_gpu_value"]]
329 if !ok {
330 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
331 }
332 d["gpu"] = gpu
333 } else if strings.Contains(parts["os"], "Mac") {
334 gpu, ok := map[string]string{
Ben Wagner1d8726f2018-02-02 14:47:31 -0500335 "IntelHD6000": "8086:1626",
Ben Wagnerdf430052018-02-08 16:57:04 -0500336 "IntelHD615": "8086:591e",
Ben Wagnercc4221b2017-08-17 17:29:04 -0400337 "IntelIris5100": "8086:0a2e",
Ben Wagner1d060782017-06-14 10:34:18 -0400338 }[parts["cpu_or_gpu_value"]]
339 if !ok {
340 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
341 }
342 d["gpu"] = gpu
Ben Wagnere7b8fea2018-02-09 10:29:09 -0500343 // Yuck. We have two different types of MacMini7,1 with the same GPU but different CPUs.
344 if parts["cpu_or_gpu_value"] == "IntelIris5100" {
345 // Run all tasks on Golo machines for now.
346 d["cpu"] = "x86-64-i7-4578U"
347 }
Ben Wagner1d060782017-06-14 10:34:18 -0400348 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500349 version, ok := map[string]string{
350 "MaliT604": "9901.12.0",
351 "MaliT764": "10172.0.0",
352 "MaliT860": "10172.0.0",
Kevin Lubick0b1b9c22017-12-08 14:14:38 -0500353 "PowerVRGX6250": "10176.5.0",
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500354 "TegraK1": "10172.0.0",
355 "IntelHDGraphics615": "10032.17.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400356 }[parts["cpu_or_gpu_value"]]
357 if !ok {
358 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
359 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500360 d["gpu"] = parts["cpu_or_gpu_value"]
361 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400362 } else {
363 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500364 }
borenetdb182c72016-09-30 12:53:12 -0700365 }
366 } else {
367 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400368 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400369 return linuxGceDimensions()
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500370 } else if d["os"] == DEFAULT_OS_WIN {
371 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400372 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagner832415e2017-12-15 11:23:40 -0500373 // Use many-core machines for Build tasks on Win GCE, except for Goma.
374 if strings.Contains(parts["extra_config"], "Goma") {
375 d["machine_type"] = "n1-standard-16"
376 } else {
377 d["machine_type"] = "n1-highcpu-64"
378 }
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500379 } else if d["os"] == DEFAULT_OS_MAC {
380 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400381 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400382 }
borenetdb182c72016-09-30 12:53:12 -0700383 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400384
borenetdb182c72016-09-30 12:53:12 -0700385 rv := make([]string, 0, len(d))
386 for k, v := range d {
387 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
388 }
389 sort.Strings(rv)
390 return rv
391}
392
Eric Boren7e3a3642017-06-14 15:25:31 -0400393// relpath returns the relative path to the given file from the config file.
394func relpath(f string) string {
395 _, filename, _, _ := runtime.Caller(0)
396 dir := path.Dir(filename)
397 rel := dir
398 if *cfgFile != "" {
399 rel = path.Dir(*cfgFile)
400 }
401 rv, err := filepath.Rel(rel, path.Join(dir, f))
402 if err != nil {
403 sklog.Fatal(err)
404 }
405 return rv
406}
407
Eric Boren8b3f9e62017-04-04 09:06:16 -0400408// bundleRecipes generates the task to bundle and isolate the recipes.
409func bundleRecipes(b *specs.TasksCfgBuilder) string {
410 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000411 CipdPackages: []*specs.CipdPackage{cipdGit1, cipdGit2},
412 Dimensions: linuxGceDimensions(),
413 ExtraArgs: []string{
414 "--workdir", "../../..", "bundle_recipes",
415 fmt.Sprintf("buildername=%s", BUNDLE_RECIPES_NAME),
416 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400417 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000418 Isolate: relpath("bundle_recipes.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400419 Priority: 0.7,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400420 })
421 return BUNDLE_RECIPES_NAME
422}
423
Eric Boren23a6ec62017-04-07 08:31:22 -0400424// useBundledRecipes returns true iff the given bot should use bundled recipes
425// instead of syncing recipe DEPS itself.
426func useBundledRecipes(parts map[string]string) bool {
427 // Use bundled recipes for all test/perf tasks.
428 return true
429}
430
Kevin Lubick07072942017-05-11 13:35:23 -0400431type isolateAssetCfg struct {
Eric Boren9d78afd2017-12-07 14:54:05 +0000432 isolateFile string
433 cipdPkg string
Kevin Lubick07072942017-05-11 13:35:23 -0400434}
435
436var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
437 ISOLATE_SKIMAGE_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000438 isolateFile: "isolate_skimage.isolate",
439 cipdPkg: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400440 },
441 ISOLATE_SKP_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000442 isolateFile: "isolate_skp.isolate",
443 cipdPkg: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400444 },
445 ISOLATE_SVG_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000446 isolateFile: "isolate_svg.isolate",
447 cipdPkg: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400448 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500449 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000450 isolateFile: "isolate_ndk_linux.isolate",
451 cipdPkg: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500452 },
Stephan Altmueller2a552172018-02-20 11:40:25 -0500453 ISOLATE_SDK_LINUX_NAME: {
454 isolateFile: "isolate_android_sdk_linux.isolate",
455 cipdPkg: "android_sdk_linux",
456 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500457 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000458 isolateFile: "isolate_win_toolchain.isolate",
459 cipdPkg: "win_toolchain",
Kevin Lubick814b1492017-11-29 14:45:14 -0500460 },
461 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000462 isolateFile: "isolate_win_vulkan_sdk.isolate",
463 cipdPkg: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500464 },
Kevin Lubick07072942017-05-11 13:35:23 -0400465}
466
Eric Boren9d78afd2017-12-07 14:54:05 +0000467// bundleRecipes generates the task to bundle and isolate the recipes.
Kevin Lubick07072942017-05-11 13:35:23 -0400468func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
469 b.MustAddTask(name, &specs.TaskSpec{
470 CipdPackages: []*specs.CipdPackage{
Eric Boren9d78afd2017-12-07 14:54:05 +0000471 b.MustGetCipdPackageFromAsset(ISOLATE_ASSET_MAPPING[name].cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400472 },
473 Dimensions: linuxGceDimensions(),
Eric Boren9d78afd2017-12-07 14:54:05 +0000474 Isolate: relpath(ISOLATE_ASSET_MAPPING[name].isolateFile),
Kevin Lubick07072942017-05-11 13:35:23 -0400475 Priority: 0.7,
476 })
477 return name
478}
479
Kevin Lubick90189522017-05-15 08:30:27 -0400480// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
481// This allows us to save time on I/O bound bots, like the RPIs.
482func getIsolatedCIPDDeps(parts map[string]string) []string {
483 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400484 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
485 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400486 rpiOS := []string{"Android", "ChromeOS", "iOS"}
487
488 if o := parts["os"]; strings.Contains(o, "Chromecast") {
489 // Chromecasts don't have enough disk space to fit all of the content,
490 // so we do a subset of the skps.
491 deps = append(deps, ISOLATE_SKP_NAME)
492 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
493 // Skpbench only needs skps
494 deps = append(deps, ISOLATE_SKP_NAME)
495 } else if util.In(o, rpiOS) {
496 deps = append(deps, ISOLATE_SKP_NAME)
497 deps = append(deps, ISOLATE_SVG_NAME)
498 deps = append(deps, ISOLATE_SKIMAGE_NAME)
499 }
500
501 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400502}
503
borenetdb182c72016-09-30 12:53:12 -0700504// compile generates a compile task. Returns the name of the last task in the
505// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700506func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
borenetdb182c72016-09-30 12:53:12 -0700507 // Collect the necessary CIPD packages.
508 pkgs := []*specs.CipdPackage{}
Eric Boren9d78afd2017-12-07 14:54:05 +0000509 deps := []string{}
borenetdb182c72016-09-30 12:53:12 -0700510
511 // Android bots require a toolchain.
512 if strings.Contains(name, "Android") {
Ravi Mistry5e967422018-02-01 13:38:13 -0500513 if parts["extra_config"] == "Android_Framework" {
514 // Do not need a toolchain when building the
515 // Android Framework.
516 } else if strings.Contains(name, "Mac") {
boreneted20a702016-10-20 11:04:31 -0700517 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400518 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400519 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
520 pkg.Path = "n"
521 pkgs = append(pkgs, pkg)
borenetdb182c72016-09-30 12:53:12 -0700522 } else {
Kevin Lubick814b1492017-11-29 14:45:14 -0500523 deps = append(deps, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
borenetdb182c72016-09-30 12:53:12 -0700524 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500525 } else if strings.Contains(name, "Chromecast") {
526 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("cast_toolchain"))
Kevin Lubickffce0792017-05-24 15:30:35 -0400527 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400528 } else if strings.Contains(name, "Chromebook") {
529 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400530 if parts["target_arch"] == "x86_64" {
531 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
532 } else if parts["target_arch"] == "arm" {
533 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
534 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
535 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400536 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500537 if strings.Contains(name, "Clang") {
538 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
539 }
540 if strings.Contains(name, "Vulkan") {
541 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
542 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400543 if strings.Contains(name, "EMCC") {
544 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("emscripten_sdk"))
545 }
Mike Klein27dcee12016-11-09 16:31:42 -0500546 } else if strings.Contains(name, "Win") {
Kevin Lubick814b1492017-11-29 14:45:14 -0500547 deps = append(deps, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400548 if strings.Contains(name, "Clang") {
549 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_win"))
550 }
borenetdb182c72016-09-30 12:53:12 -0700551 if strings.Contains(name, "Vulkan") {
Kevin Lubick814b1492017-11-29 14:45:14 -0500552 deps = append(deps, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700553 }
554 }
555
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400556 dimensions := swarmDimensions(parts)
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400557
borenetdb182c72016-09-30 12:53:12 -0700558 // Add the task.
boreneted20a702016-10-20 11:04:31 -0700559 b.MustAddTask(name, &specs.TaskSpec{
borenetdb182c72016-09-30 12:53:12 -0700560 CipdPackages: pkgs,
Eric Boren9d78afd2017-12-07 14:54:05 +0000561 Dimensions: dimensions,
562 Dependencies: deps,
563 ExtraArgs: []string{
564 "--workdir", "../../..", "compile",
skia.buildbots2478c732016-11-04 14:37:26 -0400565 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700566 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700567 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
568 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400569 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700570 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400571 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
572 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700573 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000574 Isolate: relpath("compile_skia.isolate"),
575 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700576 })
Eric Boren8615fe52016-12-12 14:30:12 -0500577 // All compile tasks are runnable as their own Job. Assert that the Job
578 // is listed in JOBS.
579 if !util.In(name, JOBS) {
580 glog.Fatalf("Job %q is missing from the JOBS list!", name)
581 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500582
583 // Upload the skiaserve binary only for Linux Android compile bots.
584 // See skbug.com/7399 for context.
585 if parts["configuration"] == "Release" &&
586 parts["extra_config"] == "Android" &&
587 !strings.Contains(parts["os"], "Win") &&
588 !strings.Contains(parts["os"], "Mac") {
589 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
590 b.MustAddTask(uploadName, &specs.TaskSpec{
591 Dependencies: []string{name},
592 Dimensions: linuxGceDimensions(),
593 ExtraArgs: []string{
594 "--workdir", "../../..", "upload_skiaserve",
595 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
596 fmt.Sprintf("buildername=%s", name),
597 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
598 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
599 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
600 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
601 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
602 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
603 },
604 // We're using the same isolate as upload_dm_results
605 Isolate: relpath("upload_dm_results.isolate"),
606 Priority: 0.8,
607 })
608 return uploadName
609 }
610
borenetdb182c72016-09-30 12:53:12 -0700611 return name
612}
613
614// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
615// task in the generated chain of tasks, which the Job should add as a
616// dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000617func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500618 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000619 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
620 Dimensions: linuxGceDimensions(),
621 ExecutionTimeout: 4 * time.Hour,
622 ExtraArgs: []string{
623 "--workdir", "../../..", "recreate_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500624 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
625 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500626 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
627 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400628 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500629 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
630 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
631 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
632 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000633 IoTimeout: 40 * time.Minute,
634 Isolate: relpath("compile_skia.isolate"),
635 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500636 })
borenetdb182c72016-09-30 12:53:12 -0700637 return name
638}
639
Ravi Mistry01b48e72017-05-17 14:28:06 -0400640// updateMetaConfig generates a UpdateMetaConfig task. Returns the name of the
641// last task in the generated chain of tasks, which the Job should add as a
642// dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000643func updateMetaConfig(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry01b48e72017-05-17 14:28:06 -0400644 b.MustAddTask(name, &specs.TaskSpec{
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400645 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000646 Dimensions: linuxGceDimensions(),
647 ExtraArgs: []string{
648 "--workdir", "../../..", "update_meta_config",
Ravi Mistry01b48e72017-05-17 14:28:06 -0400649 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
650 fmt.Sprintf("buildername=%s", name),
651 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
652 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
653 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
654 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
655 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
656 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
657 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000658 Isolate: relpath("meta_config.isolate"),
659 Priority: 0.8,
Ravi Mistry01b48e72017-05-17 14:28:06 -0400660 })
661 return name
662}
663
borenetdb182c72016-09-30 12:53:12 -0700664// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
665// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000666func ctSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500667 b.MustAddTask(name, &specs.TaskSpec{
Ben Wagner21c3fb92017-08-04 14:13:27 -0400668 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000669 Dimensions: []string{
670 "pool:SkiaCT",
671 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
672 },
673 ExecutionTimeout: 24 * time.Hour,
674 ExtraArgs: []string{
675 "--workdir", "../../..", "ct_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500676 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
677 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500678 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
679 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400680 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500681 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
682 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
683 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
684 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000685 IoTimeout: time.Hour,
686 Isolate: relpath("ct_skps_skia.isolate"),
687 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500688 })
borenetdb182c72016-09-30 12:53:12 -0700689 return name
690}
691
Eric Borenf7928b42017-07-28 07:35:28 -0400692// checkGeneratedFiles verifies that no generated SKSL files have been edited
693// by hand.
Eric Boren9d78afd2017-12-07 14:54:05 +0000694func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Eric Borenf7928b42017-07-28 07:35:28 -0400695 b.MustAddTask(name, &specs.TaskSpec{
696 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000697 Dimensions: linuxGceDimensions(),
698 ExtraArgs: []string{
699 "--workdir", "../../..", "check_generated_files",
Eric Borenf7928b42017-07-28 07:35:28 -0400700 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
701 fmt.Sprintf("buildername=%s", name),
702 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
703 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
704 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
705 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
706 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
707 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
708 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000709 Isolate: relpath("compile_skia.isolate"),
710 Priority: 0.8,
Eric Borenf7928b42017-07-28 07:35:28 -0400711 })
712 return name
713}
714
borenetdb182c72016-09-30 12:53:12 -0700715// housekeeper generates a Housekeeper task. Returns the name of the last task
716// in the generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000717func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500718 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren22f5ef72016-12-02 11:01:33 -0500719 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
Eric Boren9d78afd2017-12-07 14:54:05 +0000720 Dependencies: []string{compileTaskName},
721 Dimensions: linuxGceDimensions(),
722 ExtraArgs: []string{
723 "--workdir", "../../..", "housekeeper",
Eric Boren4b254b92016-11-08 12:55:32 -0500724 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
725 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500726 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
727 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400728 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500729 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
730 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
731 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
732 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000733 Isolate: relpath("housekeeper_skia.isolate"),
734 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500735 })
borenetdb182c72016-09-30 12:53:12 -0700736 return name
737}
738
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500739// bookmaker generates a Bookmaker task. Returns the name of the last task
740// in the generated chain of tasks, which the Job should add as a dependency.
741func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
742 b.MustAddTask(name, &specs.TaskSpec{
743 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
744 Dependencies: []string{compileTaskName},
745 Dimensions: linuxGceDimensions(),
746 ExtraArgs: []string{
747 "--workdir", "../../..", "bookmaker",
748 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
749 fmt.Sprintf("buildername=%s", name),
750 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
751 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
752 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
753 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
754 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
755 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
756 },
757 Isolate: relpath("compile_skia.isolate"),
758 Priority: 0.8,
759 ExecutionTimeout: 2 * time.Hour,
760 IoTimeout: 2 * time.Hour,
761 })
762 return name
763}
764
Ravi Mistry5e967422018-02-01 13:38:13 -0500765// androidFrameworkCompile generates an Android Framework Compile task. Returns
766// the name of the last task in the generated chain of tasks, which the Job
767// should add as a dependency.
768func androidFrameworkCompile(b *specs.TasksCfgBuilder, name string) string {
769 b.MustAddTask(name, &specs.TaskSpec{
770 Dimensions: linuxGceDimensions(),
771 ExtraArgs: []string{
772 "--workdir", "../../..", "android_compile",
773 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
774 fmt.Sprintf("buildername=%s", name),
775 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
776 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
777 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
778 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
779 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
780 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
781 },
782 Isolate: relpath("compile_skia.isolate"),
783 Priority: 0.8,
784 })
785 return name
786}
787
borenet2dbbfa52016-10-14 06:32:09 -0700788// infra generates an infra_tests task. Returns the name of the last task in the
789// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000790func infra(b *specs.TasksCfgBuilder, name string) string {
boreneted20a702016-10-20 11:04:31 -0700791 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000792 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
793 Dimensions: linuxGceDimensions(),
794 ExtraArgs: []string{
795 "--workdir", "../../..", "infra",
skia.buildbots2478c732016-11-04 14:37:26 -0400796 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700797 fmt.Sprintf("buildername=%s", name),
borenet2dbbfa52016-10-14 06:32:09 -0700798 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
799 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400800 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700801 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400802 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
803 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenet2dbbfa52016-10-14 06:32:09 -0700804 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000805 Isolate: relpath("infra_skia.isolate"),
806 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700807 })
borenet2dbbfa52016-10-14 06:32:09 -0700808 return name
809}
810
Yuqian Li4a577af2018-01-05 11:13:43 -0500811func getParentRevisionName(compileTaskName string, parts map[string]string) string {
812 if parts["extra_config"] == "" {
813 return compileTaskName + "-ParentRevision"
814 } else {
815 return compileTaskName + "_ParentRevision"
816 }
817}
818
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400819// calmbench generates a calmbench task. Returns the name of the last task in the
820// generated chain of tasks, which the Job should add as a dependency.
Yuqian Li4a577af2018-01-05 11:13:43 -0500821func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, compileParentName string) string {
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400822 s := &specs.TaskSpec{
Yuqian Li4a577af2018-01-05 11:13:43 -0500823 Dependencies: []string{compileTaskName, compileParentName},
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400824 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("clang_linux")},
Eric Boren9d78afd2017-12-07 14:54:05 +0000825 Dimensions: swarmDimensions(parts),
826 ExtraArgs: []string{
827 "--workdir", "../../..", "calmbench",
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400828 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
829 fmt.Sprintf("buildername=%s", name),
830 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
831 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
832 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
833 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
834 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
835 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
836 },
Yuqian Li4a577af2018-01-05 11:13:43 -0500837 Isolate: relpath("calmbench.isolate"),
Eric Boren9d78afd2017-12-07 14:54:05 +0000838 Priority: 0.8,
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400839 }
840
841 s.Dependencies = append(s.Dependencies, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
842
843 b.MustAddTask(name, s)
844
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400845 // Upload results if necessary.
846 if strings.Contains(name, "Release") && doUpload(name) {
847 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
848 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000849 Dependencies: []string{name},
850 Dimensions: linuxGceDimensions(),
851 ExtraArgs: []string{
852 "--workdir", "../../..", "upload_calmbench_results",
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400853 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
854 fmt.Sprintf("buildername=%s", name),
855 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
856 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
857 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
858 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
859 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
860 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
861 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketCalm),
862 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000863 // We're using the same isolate as upload_nano_results
864 Isolate: relpath("upload_nano_results.isolate"),
865 Priority: 0.8,
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400866 })
867 return uploadName
868 }
869
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400870 return name
871}
872
borenetdb182c72016-09-30 12:53:12 -0700873// doUpload indicates whether the given Job should upload its results.
874func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -0500875 for _, s := range CONFIG.NoUpload {
876 m, err := regexp.MatchString(s, name)
877 if err != nil {
878 glog.Fatal(err)
879 }
880 if m {
borenetdb182c72016-09-30 12:53:12 -0700881 return false
882 }
883 }
884 return true
885}
886
887// test generates a Test task. Returns the name of the last task in the
888// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700889func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500890 deps := []string{compileTaskName}
891 if strings.Contains(name, "Android_ASAN") {
892 deps = append(deps, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
893 }
894
Eric Boren4b254b92016-11-08 12:55:32 -0500895 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000896 CipdPackages: pkgs,
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500897 Dependencies: deps,
Eric Boren9d78afd2017-12-07 14:54:05 +0000898 Dimensions: swarmDimensions(parts),
899 ExecutionTimeout: 4 * time.Hour,
900 Expiration: 20 * time.Hour,
901 ExtraArgs: []string{
902 "--workdir", "../../..", "test",
skia.buildbots2478c732016-11-04 14:37:26 -0400903 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
Eric Boren9a9e3872017-11-29 12:33:22 -0500904 fmt.Sprintf("buildbucket_build_id=%s", specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID),
borenetdb182c72016-09-30 12:53:12 -0700905 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700906 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
907 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400908 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700909 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400910 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
911 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700912 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000913 IoTimeout: 40 * time.Minute,
914 Isolate: relpath("test_skia.isolate"),
915 MaxAttempts: 1,
916 Priority: 0.8,
917 }
918 if useBundledRecipes(parts) {
919 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
920 if strings.Contains(parts["os"], "Win") {
921 s.Isolate = relpath("test_skia_bundled_win.isolate")
922 } else {
923 s.Isolate = relpath("test_skia_bundled_unix.isolate")
924 }
Eric Boren8b3f9e62017-04-04 09:06:16 -0400925 }
Kevin Lubick90189522017-05-15 08:30:27 -0400926 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
927 s.Dependencies = append(s.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -0400928 }
Eric Boren4b254b92016-11-08 12:55:32 -0500929 if strings.Contains(parts["extra_config"], "Valgrind") {
930 s.ExecutionTimeout = 9 * time.Hour
931 s.Expiration = 48 * time.Hour
932 s.IoTimeout = time.Hour
Eric Borend696df72017-05-31 15:09:10 -0400933 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Kevin Lubickea613822017-12-04 10:20:23 -0500934 s.Dimensions = append(s.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -0500935 } else if strings.Contains(parts["extra_config"], "MSAN") {
936 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -0400937 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
938 // skia:6737
939 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -0500940 }
Eric Borenfd4d60e2017-09-15 10:35:44 -0400941 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400942 if iid != nil {
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400943 s.ExtraArgs = append(s.ExtraArgs, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -0400944 }
Eric Boren4b254b92016-11-08 12:55:32 -0500945 b.MustAddTask(name, s)
946
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400947 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
948 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -0700949 if doUpload(name) {
950 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -0700951 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000952 Dependencies: []string{name},
953 Dimensions: linuxGceDimensions(),
954 ExtraArgs: []string{
955 "--workdir", "../../..", "upload_dm_results",
skia.buildbots2478c732016-11-04 14:37:26 -0400956 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700957 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700958 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
959 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400960 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700961 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400962 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
963 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -0500964 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketGm),
borenetdb182c72016-09-30 12:53:12 -0700965 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000966 Isolate: relpath("upload_dm_results.isolate"),
967 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700968 })
borenetdb182c72016-09-30 12:53:12 -0700969 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -0400970 }
971
972 return name
973}
974
975func coverage(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
976 shards := 1
977 deps := []string{}
978
979 tf := parts["test_filter"]
980 if strings.Contains(tf, "Shard") {
981 // Expected Shard_NN
982 shardstr := strings.Split(tf, "_")[1]
983 var err error
984 shards, err = strconv.Atoi(shardstr)
985 if err != nil {
986 glog.Fatalf("Expected int for number of shards %q in %s: %s", shardstr, name, err)
987 }
988 }
989 for i := 0; i < shards; i++ {
990 n := strings.Replace(name, tf, fmt.Sprintf("shard_%02d_%02d", i, shards), 1)
991 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000992 CipdPackages: pkgs,
993 Dependencies: []string{compileTaskName},
994 Dimensions: swarmDimensions(parts),
995 ExecutionTimeout: 4 * time.Hour,
996 Expiration: 20 * time.Hour,
997 ExtraArgs: []string{
998 "--workdir", "../../..", "test",
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400999 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
Kevin Lubick32f318b2017-10-17 13:40:52 -04001000 fmt.Sprintf("buildername=%s", n),
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001001 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1002 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
1003 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
1004 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
1005 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1006 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001007 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001008 IoTimeout: 40 * time.Minute,
1009 Isolate: relpath("test_skia.isolate"),
1010 MaxAttempts: 1,
1011 Priority: 0.8,
1012 }
1013 if useBundledRecipes(parts) {
1014 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
1015 if strings.Contains(parts["os"], "Win") {
1016 s.Isolate = relpath("test_skia_bundled_win.isolate")
1017 } else {
1018 s.Isolate = relpath("test_skia_bundled_unix.isolate")
1019 }
Kevin Lubick32f318b2017-10-17 13:40:52 -04001020 }
1021 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
1022 s.Dependencies = append(s.Dependencies, deps...)
1023 }
1024 b.MustAddTask(n, s)
1025 deps = append(deps, n)
borenetdb182c72016-09-30 12:53:12 -07001026 }
Kevin Lubickc795a4c2017-10-09 15:26:19 -04001027
Kevin Lubick32f318b2017-10-17 13:40:52 -04001028 uploadName := fmt.Sprintf("%s%s%s", "Upload", jobNameSchema.Sep, name)
1029 // We need clang_linux to get access to the llvm-profdata and llvm-cov binaries
1030 // which are used to deal with the raw coverage data output by the Test step.
1031 pkgs = append([]*specs.CipdPackage{}, b.MustGetCipdPackageFromAsset("clang_linux"))
1032 deps = append(deps, compileTaskName)
1033
1034 b.MustAddTask(uploadName, &specs.TaskSpec{
1035 // A dependency on compileTaskName makes the TaskScheduler link the
1036 // isolated output of the compile step to the input of the upload step,
1037 // which gives us access to the instrumented binary. The binary is
1038 // needed to figure out symbol names and line numbers.
1039 Dependencies: deps,
1040 Dimensions: linuxGceDimensions(),
1041 CipdPackages: pkgs,
Eric Boren9d78afd2017-12-07 14:54:05 +00001042 ExtraArgs: []string{
1043 "--workdir", "../../..", "upload_coverage_results",
Kevin Lubick32f318b2017-10-17 13:40:52 -04001044 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
1045 fmt.Sprintf("buildername=%s", name),
1046 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1047 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
1048 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
1049 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
1050 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1051 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
1052 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketCoverage),
1053 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001054 Isolate: relpath("upload_coverage_results.isolate"),
Kevin Lubick32f318b2017-10-17 13:40:52 -04001055 Priority: 0.8,
1056 })
1057 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 Boren9d78afd2017-12-07 14:54:05 +00001064 isolate := relpath("perf_skia.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 Boren9d78afd2017-12-07 14:54:05 +00001067 isolate = relpath("skpbench_skia.isolate")
1068 if useBundledRecipes(parts) {
1069 if strings.Contains(parts["os"], "Win") {
1070 isolate = relpath("skpbench_skia_bundled_win.isolate")
1071 } else {
1072 isolate = relpath("skpbench_skia_bundled_unix.isolate")
1073 }
1074 }
1075 } else if useBundledRecipes(parts) {
1076 if strings.Contains(parts["os"], "Win") {
1077 isolate = relpath("perf_skia_bundled_win.isolate")
1078 } else {
1079 isolate = relpath("perf_skia_bundled_unix.isolate")
1080 }
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001081 }
Eric Boren4b254b92016-11-08 12:55:32 -05001082 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +00001083 CipdPackages: pkgs,
1084 Dependencies: []string{compileTaskName},
1085 Dimensions: swarmDimensions(parts),
1086 ExecutionTimeout: 4 * time.Hour,
1087 Expiration: 20 * time.Hour,
1088 ExtraArgs: []string{
1089 "--workdir", "../../..", recipe,
skia.buildbots2478c732016-11-04 14:37:26 -04001090 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -07001091 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -07001092 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1093 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -04001094 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -07001095 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -04001096 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1097 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -07001098 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001099 IoTimeout: 40 * time.Minute,
1100 Isolate: isolate,
1101 MaxAttempts: 1,
1102 Priority: 0.8,
1103 }
1104 if useBundledRecipes(parts) {
1105 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
Eric Boren8b3f9e62017-04-04 09:06:16 -04001106 }
Kevin Lubick90189522017-05-15 08:30:27 -04001107 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
1108 s.Dependencies = append(s.Dependencies, deps...)
1109 }
1110
Eric Boren4b254b92016-11-08 12:55:32 -05001111 if strings.Contains(parts["extra_config"], "Valgrind") {
1112 s.ExecutionTimeout = 9 * time.Hour
1113 s.Expiration = 48 * time.Hour
1114 s.IoTimeout = time.Hour
Eric Borenc5a073d2017-06-01 07:13:33 -04001115 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Kevin Lubickea613822017-12-04 10:20:23 -05001116 s.Dimensions = append(s.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001117 } else if strings.Contains(parts["extra_config"], "MSAN") {
1118 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001119 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1120 // skia:6737
1121 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -05001122 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001123 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001124 if iid != nil {
Eric Boren4dc4aaf2017-09-15 14:09:07 -04001125 s.ExtraArgs = append(s.ExtraArgs, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001126 }
Eric Boren4b254b92016-11-08 12:55:32 -05001127 b.MustAddTask(name, s)
1128
borenetdb182c72016-09-30 12:53:12 -07001129 // Upload results if necessary.
1130 if strings.Contains(name, "Release") && doUpload(name) {
1131 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -07001132 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +00001133 Dependencies: []string{name},
1134 Dimensions: linuxGceDimensions(),
1135 ExtraArgs: []string{
1136 "--workdir", "../../..", "upload_nano_results",
skia.buildbots2478c732016-11-04 14:37:26 -04001137 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -07001138 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -07001139 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1140 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -04001141 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -07001142 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -04001143 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1144 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -05001145 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketNano),
borenetdb182c72016-09-30 12:53:12 -07001146 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001147 Isolate: relpath("upload_nano_results.isolate"),
1148 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -07001149 })
borenetdb182c72016-09-30 12:53:12 -07001150 return uploadName
1151 }
1152 return name
1153}
1154
1155// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001156func process(b *specs.TasksCfgBuilder, name string) {
borenetdb182c72016-09-30 12:53:12 -07001157 deps := []string{}
1158
Eric Boren8b3f9e62017-04-04 09:06:16 -04001159 // Bundle Recipes.
1160 if name == BUNDLE_RECIPES_NAME {
1161 deps = append(deps, bundleRecipes(b))
1162 }
1163
Kevin Lubick07072942017-05-11 13:35:23 -04001164 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001165 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1166 deps = append(deps, isolateCIPDAsset(b, name))
1167 }
1168
borenetdb182c72016-09-30 12:53:12 -07001169 parts, err := jobNameSchema.ParseJobName(name)
1170 if err != nil {
1171 glog.Fatal(err)
1172 }
1173
1174 // RecreateSKPs.
1175 if strings.Contains(name, "RecreateSKPs") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001176 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001177 }
1178
Ravi Mistry01b48e72017-05-17 14:28:06 -04001179 // UpdateMetaConfig bot.
1180 if strings.Contains(name, "UpdateMetaConfig") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001181 deps = append(deps, updateMetaConfig(b, name))
Ravi Mistry01b48e72017-05-17 14:28:06 -04001182 }
1183
borenetdb182c72016-09-30 12:53:12 -07001184 // CT bots.
1185 if strings.Contains(name, "-CT_") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001186 deps = append(deps, ctSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001187 }
1188
borenet2dbbfa52016-10-14 06:32:09 -07001189 // Infra tests.
1190 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001191 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001192 }
1193
borenetdb182c72016-09-30 12:53:12 -07001194 // Compile bots.
1195 if parts["role"] == "Build" {
Ravi Mistry5e967422018-02-01 13:38:13 -05001196 if parts["extra_config"] == "Android_Framework" {
1197 // Android Framework compile tasks use a different recipe.
1198 deps = append(deps, androidFrameworkCompile(b, name))
1199 } else {
1200 deps = append(deps, compile(b, name, parts))
1201 }
borenetdb182c72016-09-30 12:53:12 -07001202 }
1203
Eric Borenf5a90e82016-11-15 15:18:20 -05001204 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001205 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001206 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1207 if err != nil {
1208 glog.Fatal(err)
1209 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001210 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1211 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1212 if err != nil {
1213 glog.Fatal(err)
1214 }
1215
Eric Boren628e78b2016-11-17 11:33:27 -05001216 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001217 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001218 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001219 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001220 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Ravi Mistry5e967422018-02-01 13:38:13 -05001221 !strings.Contains(name, "Android_Framework") &&
Eric Boren71b762f2016-11-30 14:05:16 -05001222 !strings.Contains(name, "RecreateSKPs") &&
Ravi Mistry01b48e72017-05-17 14:28:06 -04001223 !strings.Contains(name, "UpdateMetaConfig") &&
Ben Wagner50b84682017-06-12 13:03:29 -04001224 !strings.Contains(name, "-CT_") &&
1225 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") {
boreneted20a702016-10-20 11:04:31 -07001226 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001227 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001228 compile(b, compileParentName, compileParentParts)
1229 }
borenet52383432016-10-17 10:17:53 -07001230 }
borenetdb182c72016-09-30 12:53:12 -07001231
Eric Borenf7928b42017-07-28 07:35:28 -04001232 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001233 if name == "Housekeeper-PerCommit" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001234 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -07001235 }
Eric Borenf7928b42017-07-28 07:35:28 -04001236 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001237 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001238 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001239 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001240 deps = append(deps, bookmaker(b, name, compileTaskName))
1241 }
borenetdb182c72016-09-30 12:53:12 -07001242
1243 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001244
1245 pkgs := []*specs.CipdPackage{}
1246
Kevin Lubick90189522017-05-15 08:30:27 -04001247 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001248 pkgs = []*specs.CipdPackage{
1249 b.MustGetCipdPackageFromAsset("skimage"),
1250 b.MustGetCipdPackageFromAsset("skp"),
1251 b.MustGetCipdPackageFromAsset("svg"),
1252 }
borenetdb182c72016-09-30 12:53:12 -07001253 }
Kevin Lubick90189522017-05-15 08:30:27 -04001254
Ben Wagner5655ba42017-10-02 10:48:32 -04001255 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1256 if strings.Contains(name, "SAN") {
1257 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1258 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001259 if strings.Contains(name, "Vulkan") {
1260 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1261 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001262 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
1263 if strings.Contains(name, "Release") {
1264 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
1265 } else {
1266 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
1267 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001268 }
1269 }
borenetdb182c72016-09-30 12:53:12 -07001270
1271 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001272
1273 if parts["role"] == "Test" {
1274 if strings.Contains(parts["extra_config"], "Coverage") {
1275 deps = append(deps, coverage(b, name, parts, compileTaskName, pkgs))
1276 } else if !strings.Contains(name, "-CT_") {
1277 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
1278 }
1279
borenetdb182c72016-09-30 12:53:12 -07001280 }
1281
1282 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -05001283 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -07001284 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001285 }
1286
Yuqian Li4a577af2018-01-05 11:13:43 -05001287 // Calmbench bots.
1288 if parts["role"] == "Calmbench" {
1289 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1290 }
1291
borenetdb182c72016-09-30 12:53:12 -07001292 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001293 j := &specs.JobSpec{
borenetdb182c72016-09-30 12:53:12 -07001294 Priority: 0.8,
1295 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001296 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001297 }
Eric Borenba937a42017-07-31 10:41:15 -04001298 if strings.Contains(name, "-Nightly-") {
1299 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryf06dae82017-10-16 10:31:41 -04001300 } else if strings.Contains(name, "-Weekly-") || strings.Contains(name, "CT_DM_1m_SKPs") {
Eric Borenba937a42017-07-31 10:41:15 -04001301 j.Trigger = specs.TRIGGER_WEEKLY
1302 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "PDFium") || strings.Contains(name, "CommandBuffer") {
1303 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren71b762f2016-11-30 14:05:16 -05001304 }
Eric Boren8615fe52016-12-12 14:30:12 -05001305 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001306}
1307
Eric Boren27225492017-02-01 15:56:55 -05001308func loadJson(flag *string, defaultFlag string, val interface{}) {
1309 if *flag == "" {
1310 *flag = defaultFlag
1311 }
1312 b, err := ioutil.ReadFile(*flag)
1313 if err != nil {
1314 glog.Fatal(err)
1315 }
1316 if err := json.Unmarshal(b, val); err != nil {
1317 glog.Fatal(err)
1318 }
1319}
1320
borenetdb182c72016-09-30 12:53:12 -07001321// Regenerate the tasks.json file.
1322func main() {
boreneted20a702016-10-20 11:04:31 -07001323 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001324 b.SetAssetsDir(*assetsDir)
1325 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1326
1327 // Load the jobs from a JSON file.
1328 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1329
Eric Boren27225492017-02-01 15:56:55 -05001330 // Load general config information from a JSON file.
1331 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1332
borenetdb182c72016-09-30 12:53:12 -07001333 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001334 if *builderNameSchemaFile == "" {
1335 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1336 }
1337 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001338 if err != nil {
1339 glog.Fatal(err)
1340 }
1341 jobNameSchema = schema
1342
borenetdb182c72016-09-30 12:53:12 -07001343 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001344 for _, name := range JOBS {
1345 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001346 }
1347
boreneted20a702016-10-20 11:04:31 -07001348 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001349}
1350
1351// TODO(borenet): The below really belongs in its own file, probably next to the
1352// builder_name_schema.json file.
1353
1354// JobNameSchema is a struct used for (de)constructing Job names in a
1355// predictable format.
1356type JobNameSchema struct {
1357 Schema map[string][]string `json:"builder_name_schema"`
1358 Sep string `json:"builder_name_sep"`
1359}
1360
1361// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1362// file.
1363func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1364 var rv JobNameSchema
1365 f, err := os.Open(jsonFile)
1366 if err != nil {
1367 return nil, err
1368 }
1369 defer util.Close(f)
1370 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1371 return nil, err
1372 }
1373 return &rv, nil
1374}
1375
1376// ParseJobName splits the given Job name into its component parts, according
1377// to the schema.
1378func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
1379 split := strings.Split(n, s.Sep)
1380 if len(split) < 2 {
1381 return nil, fmt.Errorf("Invalid job name: %q", n)
1382 }
1383 role := split[0]
1384 split = split[1:]
1385 keys, ok := s.Schema[role]
1386 if !ok {
1387 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1388 }
1389 extraConfig := ""
1390 if len(split) == len(keys)+1 {
1391 extraConfig = split[len(split)-1]
1392 split = split[:len(split)-1]
1393 }
1394 if len(split) != len(keys) {
1395 return nil, fmt.Errorf("Invalid job name; %q has incorrect number of parts.", n)
1396 }
1397 rv := make(map[string]string, len(keys)+2)
1398 rv["role"] = role
1399 if extraConfig != "" {
1400 rv["extra_config"] = extraConfig
1401 }
1402 for i, k := range keys {
1403 rv[k] = split[i]
1404 }
1405 return rv, nil
1406}
1407
1408// MakeJobName assembles the given parts of a Job name, according to the schema.
1409func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
1410 role, ok := parts["role"]
1411 if !ok {
1412 return "", fmt.Errorf("Invalid job parts; jobs must have a role.")
1413 }
1414 keys, ok := s.Schema[role]
1415 if !ok {
1416 return "", fmt.Errorf("Invalid job parts; unknown role %q", role)
1417 }
1418 rvParts := make([]string, 0, len(parts))
1419 rvParts = append(rvParts, role)
1420 for _, k := range keys {
1421 v, ok := parts[k]
1422 if !ok {
1423 return "", fmt.Errorf("Invalid job parts; missing %q", k)
1424 }
1425 rvParts = append(rvParts, v)
1426 }
1427 if _, ok := parts["extra_config"]; ok {
1428 rvParts = append(rvParts, parts["extra_config"])
1429 }
1430 return strings.Join(rvParts, s.Sep), nil
1431}