blob: c1c8698bfb77b1772345e6a7ea28a68cc98614c2 [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"
22 "strings"
Eric Boren4b254b92016-11-08 12:55:32 -050023 "time"
borenetdb182c72016-09-30 12:53:12 -070024
25 "github.com/skia-dev/glog"
Eric Boren7e3a3642017-06-14 15:25:31 -040026 "go.skia.org/infra/go/sklog"
borenetdb182c72016-09-30 12:53:12 -070027 "go.skia.org/infra/go/util"
28 "go.skia.org/infra/task_scheduler/go/specs"
29)
30
31const (
Kevin Lubick07072942017-05-11 13:35:23 -040032 BUNDLE_RECIPES_NAME = "Housekeeper-PerCommit-BundleRecipes"
33 ISOLATE_SKIMAGE_NAME = "Housekeeper-PerCommit-IsolateSkImage"
34 ISOLATE_SKP_NAME = "Housekeeper-PerCommit-IsolateSKP"
35 ISOLATE_SVG_NAME = "Housekeeper-PerCommit-IsolateSVG"
Eric Boren8b3f9e62017-04-04 09:06:16 -040036
Ben Wagner82cbdba2017-08-01 15:12:49 -040037 DEFAULT_OS_DEBIAN = "Debian-9.1"
Eric Borenbb198fb2017-06-28 11:45:54 -040038 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
borenetdb182c72016-09-30 12:53:12 -070039
borenetdb182c72016-09-30 12:53:12 -070040 // Name prefix for upload jobs.
41 PREFIX_UPLOAD = "Upload"
42)
43
44var (
45 // "Constants"
46
Eric Boren27225492017-02-01 15:56:55 -050047 // Top-level list of all jobs to run at each commit; loaded from
48 // jobs.json.
49 JOBS []string
50
Eric Boren27225492017-02-01 15:56:55 -050051 // General configuration information.
52 CONFIG struct {
Eric Boren965861b2017-02-06 15:38:41 -050053 GsBucketGm string `json:"gs_bucket_gm"`
54 GsBucketNano string `json:"gs_bucket_nano"`
55 NoUpload []string `json:"no_upload"`
56 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070057 }
58
Ben Wagner3d2a2f72017-06-13 17:01:16 -040059 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
60 // dimensions for the given task.
61 alternateSwarmDimensions func(parts map[string]string) []string
62
borenetdb182c72016-09-30 12:53:12 -070063 // Defines the structure of job names.
64 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -050065
Eric Borenf4a5fc72017-06-06 08:27:09 -040066 // Git 2.13.
67 cipdGit1 = &specs.CipdPackage{
68 Name: fmt.Sprintf("infra/git/${platform}"),
69 Path: "git",
70 Version: fmt.Sprintf("version:2.13.0.chromium9"),
71 }
72 cipdGit2 = &specs.CipdPackage{
73 Name: fmt.Sprintf("infra/tools/git/${platform}"),
74 Path: "git",
75 Version: fmt.Sprintf("git_revision:a78b5f3658c0578a017db48df97d20ac09822bcd"),
76 }
77
Eric Boren27225492017-02-01 15:56:55 -050078 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -050079 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.")
80 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
81 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -050082 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -070083)
84
Eric Boren27225492017-02-01 15:56:55 -050085// linuxGceDimensions are the Swarming dimensions for Linux GCE
86// instances.
87func linuxGceDimensions() []string {
88 return []string{
89 "cpu:x86-64-avx2",
90 "gpu:none",
Eric Borenbb198fb2017-06-28 11:45:54 -040091 fmt.Sprintf("os:%s", DEFAULT_OS_DEBIAN),
Eric Boren27225492017-02-01 15:56:55 -050092 fmt.Sprintf("pool:%s", CONFIG.Pool),
93 }
94}
95
borenetdb182c72016-09-30 12:53:12 -070096// deriveCompileTaskName returns the name of a compile task based on the given
97// job name.
98func deriveCompileTaskName(jobName string, parts map[string]string) string {
99 if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400100 return "Build-Debian9-GCC-x86_64-Release-Shared"
borenetdb182c72016-09-30 12:53:12 -0700101 } else if parts["role"] == "Test" || parts["role"] == "Perf" {
102 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400103 ec := []string{}
104 if val := parts["extra_config"]; val != "" {
105 ec = strings.Split(val, "_")
Chris Dalton97598a52017-07-18 10:49:07 -0600106 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400107 keep := make([]string, 0, len(ec))
108 for _, part := range ec {
109 if !util.In(part, ignore) {
110 keep = append(keep, part)
111 }
112 }
113 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400114 }
borenetdb182c72016-09-30 12:53:12 -0700115 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400116 if !util.In("Android", ec) {
117 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700118 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400119 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500120 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400121 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400122 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400123 } else if strings.Contains(task_os, "ChromeOS") {
Ben Wagner988d15e2017-04-27 13:08:50 -0400124 ec = append([]string{"Chromebook", "ARM", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400125 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700126 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400127 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700128 task_os = "Mac"
129 } else if strings.Contains(task_os, "Win") {
130 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400131 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
132 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700133 }
Eric Boren50831302016-11-18 13:10:51 -0500134 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700135 "role": "Build",
136 "os": task_os,
137 "compiler": parts["compiler"],
138 "target_arch": parts["arch"],
139 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500140 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400141 if len(ec) > 0 {
142 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500143 }
144 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700145 if err != nil {
146 glog.Fatal(err)
147 }
148 return name
149 } else {
150 return jobName
151 }
152}
153
154// swarmDimensions generates swarming bot dimensions for the given task.
155func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400156 if alternateSwarmDimensions != nil {
157 return alternateSwarmDimensions(parts)
158 }
159 return defaultSwarmDimensions(parts)
160}
161
162// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
163func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700164 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500165 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700166 }
167 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400168 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400169 "Android": "Android",
170 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400171 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400172 "Debian9": DEFAULT_OS_DEBIAN,
Kevin Lubick291547d2017-03-21 09:25:34 -0400173 "Mac": "Mac-10.11",
Eric Borenbb198fb2017-06-28 11:45:54 -0400174 "Ubuntu14": DEFAULT_OS_UBUNTU,
Kevin Lubick291547d2017-03-21 09:25:34 -0400175 "Ubuntu16": "Ubuntu-16.10",
Eric Boren810c2b62017-07-11 08:11:15 -0400176 "Ubuntu17": "Ubuntu-17.04",
Kevin Lubick291547d2017-03-21 09:25:34 -0400177 "Win": "Windows-2008ServerR2-SP1",
Ben Wagner40226b42017-05-02 13:13:13 -0400178 "Win10": "Windows-10-15063",
Kevin Lubick291547d2017-03-21 09:25:34 -0400179 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagner56738d82017-04-18 15:38:15 -0400180 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400181 "Win8": "Windows-8.1-SP0",
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400182 "iOS": "iOS-10.3.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500183 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400184 if !ok {
185 glog.Fatalf("Entry %q not found in OS mapping.", os)
186 }
Ben Wagnerae532f62017-08-02 23:24:16 -0400187 // These machines have a different Windows image.
188 if parts["model"] == "Golo" && os == "Win10" && parts["cpu_or_gpu_value"] == "GT610" {
Ben Wagner73557372016-12-29 16:27:03 -0500189 d["os"] = "Windows-10-10586"
Ben Wagner17f811b2016-12-22 08:40:14 -0500190 }
borenetdb182c72016-09-30 12:53:12 -0700191 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400192 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700193 }
borenetdb182c72016-09-30 12:53:12 -0700194 if parts["role"] == "Test" || parts["role"] == "Perf" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400195 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700196 // For Android, the device type is a better dimension
197 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400198 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400199 "AndroidOne": {"sprout", "MOB30Q"},
200 "Chorizo": {"chorizo", "1.24_82923"},
201 "Ci20": {"ci20", "NRD90M"},
202 "GalaxyJ5": {"j5xnlte", "MMB29M"},
203 "GalaxyS6": {"zerofltetmo", "MMB29K"},
204 "GalaxyS7_G930A": {"heroqlteatt", "NRD90M_G930AUCS4BQC2"},
205 "GalaxyS7_G930FD": {"herolte", "NRD90M_G930FXXU1DQAS"},
206 "GalaxyTab3": {"goyawifi", "JDQ39"},
207 "MotoG4": {"athene", "NPJ25.93-14"},
208 "NVIDIA_Shield": {"foster", "NRD90M"},
209 "Nexus10": {"manta", "LMY49J"},
210 "Nexus5": {"hammerhead", "M4B30Z"},
211 "Nexus6": {"shamu", "M"},
212 "Nexus6p": {"angler", "OPP1.170223.012"},
213 "Nexus7": {"grouper", "LMY47V"},
214 "Nexus7v2": {"flo", "M"},
215 "NexusPlayer": {"fugu", "OPP2.170420.017"},
216 "Pixel": {"sailfish", "NMF26Q"},
217 "PixelC": {"dragon", "N2G47D"},
Greg Danielc34aeb72017-06-14 11:09:19 -0400218 "PixelXL": {"marlin", "OPP3.170518.006"},
Ben Wagner36682782017-06-14 10:01:45 -0400219 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500220 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400221 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500222 }
Eric Boren4b254b92016-11-08 12:55:32 -0500223 d["device_type"] = deviceInfo[0]
224 d["device_os"] = deviceInfo[1]
borenetdb182c72016-09-30 12:53:12 -0700225 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400226 device, ok := map[string]string{
Eric Boren792079cf2016-11-09 14:03:20 -0500227 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400228 "iPhone6": "iPhone7,2",
229 "iPhone7": "iPhone9,1",
230 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700231 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400232 if !ok {
233 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
234 }
235 d["device"] = device
borenetdb182c72016-09-30 12:53:12 -0700236 } else if parts["cpu_or_gpu"] == "CPU" {
237 d["gpu"] = "none"
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400238 cpu, ok := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700239 "AVX": "x86-64",
240 "AVX2": "x86-64-avx2",
241 "SSE4": "x86-64",
242 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400243 if !ok {
244 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
245 }
246 d["cpu"] = cpu
borenetdb182c72016-09-30 12:53:12 -0700247 if strings.Contains(parts["os"], "Win") && parts["cpu_or_gpu_value"] == "AVX2" {
248 // AVX2 is not correctly detected on Windows. Fall back on other
249 // dimensions to ensure that we correctly target machines which we know
250 // have AVX2 support.
Eric Boren085bf7c2017-04-06 17:32:44 +0000251 d["cpu"] = "x86-64"
Ben Wagner56738d82017-04-18 15:38:15 -0400252 if parts["model"] != "GCE" {
253 glog.Fatalf("Please double-check that %q supports AVX2 and update this assertion.", parts["model"])
254 }
borenetdb182c72016-09-30 12:53:12 -0700255 }
256 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400257 if strings.Contains(parts["os"], "Win") {
258 gpu, ok := map[string]string{
259 "AMDHD7770": "1002:683d-22.19.165.512",
Ben Wagner0d2b0912017-08-15 12:43:55 -0400260 "GT610": "10de:104a-22.21.13.8205",
Ben Wagner1d060782017-06-14 10:34:18 -0400261 "GTX1070": "10de:1ba1-22.21.13.8205",
262 "GTX660": "10de:11c0-22.21.13.8205",
263 "GTX960": "10de:1401-22.21.13.8205",
264 "IntelHD530": "8086:1912-21.20.16.4590",
Ben Wagner5698b002017-08-04 11:25:33 -0400265 "IntelHD4400": "8086:0a16-20.19.15.4703",
Ben Wagner3c286532017-08-11 10:35:57 -0400266 "IntelHD4600": "8086:0412-20.19.15.4703",
Ben Wagner8ab8f612017-08-17 13:53:09 -0400267 "IntelHD615": "8086:591e-21.20.16.4590",
Ben Wagner1d060782017-06-14 10:34:18 -0400268 "IntelIris540": "8086:1926-21.20.16.4590",
Ben Wagner3c286532017-08-11 10:35:57 -0400269 "IntelIris6100": "8086:162b-20.19.15.4703",
Ben Wagner1d060782017-06-14 10:34:18 -0400270 "RadeonR9M470X": "1002:6646-22.19.165.512",
Ben Wagnerae532f62017-08-02 23:24:16 -0400271 "QuadroP400": "10de:1cb3-22.21.13.8205",
Ben Wagner1d060782017-06-14 10:34:18 -0400272 }[parts["cpu_or_gpu_value"]]
273 if !ok {
274 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
275 }
276 d["gpu"] = gpu
Ben Wagner08435892017-02-18 23:28:26 -0500277
Ben Wagner4b1df022017-06-15 12:28:04 -0400278 // Specify cpu dimension for NUCs and ShuttleCs. We temporarily have two
279 // types of machines with a GTX960.
280 cpu, ok := map[string]string{
281 "NUC6i7KYK": "x86-64-i7-6770HQ",
282 "ShuttleC": "x86-64-i7-6700K",
Ben Wagner1d060782017-06-14 10:34:18 -0400283 }[parts["model"]]
284 if ok {
Ben Wagner4b1df022017-06-15 12:28:04 -0400285 d["cpu"] = cpu
Ben Wagner1d060782017-06-14 10:34:18 -0400286 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400287 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400288 gpu, ok := map[string]string{
Ben Wagner2c600fb2017-08-14 14:58:19 -0400289 "GT610": "10de:104a-384.59",
290 "GTX550Ti": "10de:1244-384.59",
291 "GTX660": "10de:11c0-384.59",
292 "GTX960": "10de:1401-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400293 // Intel drivers come from CIPD, so no need to specify the version here.
294 "IntelBayTrail": "8086:0f31",
295 "IntelHD2000": "8086:0102",
296 "IntelHD405": "8086:22b1",
297 "IntelIris540": "8086:1926",
Ben Wagnerfef8fdd2017-08-11 14:13:56 -0400298 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400299 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400300 }[parts["cpu_or_gpu_value"]]
301 if !ok {
302 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
303 }
304 d["gpu"] = gpu
305 } else if strings.Contains(parts["os"], "Mac") {
306 gpu, ok := map[string]string{
307 // TODO(benjaminwagner): GPU name doesn't match device ID.
308 "IntelHD4000": "8086:0a2e",
309 }[parts["cpu_or_gpu_value"]]
310 if !ok {
311 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
312 }
313 d["gpu"] = gpu
314 } else if strings.Contains(parts["os"], "ChromeOS") {
315 gpu, ok := map[string]string{
Kevin Lubickc14e5a72017-08-15 13:22:19 -0400316 "MaliT604": "MaliT604",
317 "MaliT764": "MaliT764",
318 "MaliT860": "MaliT860",
319 "PowerVRGX6250": "PowerVRGX6250",
320 "TegraK1": "TegraK1",
Ben Wagner1d060782017-06-14 10:34:18 -0400321 }[parts["cpu_or_gpu_value"]]
322 if !ok {
323 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
324 }
325 d["gpu"] = gpu
326 } else {
327 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500328 }
borenetdb182c72016-09-30 12:53:12 -0700329 }
330 } else {
331 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400332 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400333 return linuxGceDimensions()
334 }
borenetdb182c72016-09-30 12:53:12 -0700335 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400336
borenetdb182c72016-09-30 12:53:12 -0700337 rv := make([]string, 0, len(d))
338 for k, v := range d {
339 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
340 }
341 sort.Strings(rv)
342 return rv
343}
344
Eric Boren7e3a3642017-06-14 15:25:31 -0400345// relpath returns the relative path to the given file from the config file.
346func relpath(f string) string {
347 _, filename, _, _ := runtime.Caller(0)
348 dir := path.Dir(filename)
349 rel := dir
350 if *cfgFile != "" {
351 rel = path.Dir(*cfgFile)
352 }
353 rv, err := filepath.Rel(rel, path.Join(dir, f))
354 if err != nil {
355 sklog.Fatal(err)
356 }
357 return rv
358}
359
Eric Boren8b3f9e62017-04-04 09:06:16 -0400360// bundleRecipes generates the task to bundle and isolate the recipes.
361func bundleRecipes(b *specs.TasksCfgBuilder) string {
362 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Borenf4a5fc72017-06-06 08:27:09 -0400363 CipdPackages: []*specs.CipdPackage{cipdGit1, cipdGit2},
Eric Boren8b3f9e62017-04-04 09:06:16 -0400364 Dimensions: linuxGceDimensions(),
365 ExtraArgs: []string{
366 "--workdir", "../../..", "bundle_recipes",
Eric Boren8b3f9e62017-04-04 09:06:16 -0400367 fmt.Sprintf("buildername=%s", BUNDLE_RECIPES_NAME),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400368 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400369 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400370 Isolate: relpath("bundle_recipes.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400371 Priority: 0.7,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400372 })
373 return BUNDLE_RECIPES_NAME
374}
375
Eric Boren23a6ec62017-04-07 08:31:22 -0400376// useBundledRecipes returns true iff the given bot should use bundled recipes
377// instead of syncing recipe DEPS itself.
378func useBundledRecipes(parts map[string]string) bool {
379 // Use bundled recipes for all test/perf tasks.
380 return true
381}
382
Kevin Lubick07072942017-05-11 13:35:23 -0400383type isolateAssetCfg struct {
384 isolateFile string
385 cipdPkg string
386}
387
388var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
389 ISOLATE_SKIMAGE_NAME: {
390 isolateFile: "isolate_skimage.isolate",
391 cipdPkg: "skimage",
392 },
393 ISOLATE_SKP_NAME: {
394 isolateFile: "isolate_skp.isolate",
395 cipdPkg: "skp",
396 },
397 ISOLATE_SVG_NAME: {
398 isolateFile: "isolate_svg.isolate",
399 cipdPkg: "svg",
400 },
401}
402
403// bundleRecipes generates the task to bundle and isolate the recipes.
404func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
405 b.MustAddTask(name, &specs.TaskSpec{
406 CipdPackages: []*specs.CipdPackage{
407 b.MustGetCipdPackageFromAsset(ISOLATE_ASSET_MAPPING[name].cipdPkg),
408 },
409 Dimensions: linuxGceDimensions(),
Eric Boren7e3a3642017-06-14 15:25:31 -0400410 Isolate: relpath(ISOLATE_ASSET_MAPPING[name].isolateFile),
Kevin Lubick07072942017-05-11 13:35:23 -0400411 Priority: 0.7,
412 })
413 return name
414}
415
Kevin Lubick90189522017-05-15 08:30:27 -0400416// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
417// This allows us to save time on I/O bound bots, like the RPIs.
418func getIsolatedCIPDDeps(parts map[string]string) []string {
419 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400420 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
421 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400422 rpiOS := []string{"Android", "ChromeOS", "iOS"}
423
424 if o := parts["os"]; strings.Contains(o, "Chromecast") {
425 // Chromecasts don't have enough disk space to fit all of the content,
426 // so we do a subset of the skps.
427 deps = append(deps, ISOLATE_SKP_NAME)
428 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
429 // Skpbench only needs skps
430 deps = append(deps, ISOLATE_SKP_NAME)
431 } else if util.In(o, rpiOS) {
432 deps = append(deps, ISOLATE_SKP_NAME)
433 deps = append(deps, ISOLATE_SVG_NAME)
434 deps = append(deps, ISOLATE_SKIMAGE_NAME)
435 }
436
437 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400438}
439
borenetdb182c72016-09-30 12:53:12 -0700440// compile generates a compile task. Returns the name of the last task in the
441// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700442func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
borenetdb182c72016-09-30 12:53:12 -0700443 // Collect the necessary CIPD packages.
444 pkgs := []*specs.CipdPackage{}
445
446 // Android bots require a toolchain.
447 if strings.Contains(name, "Android") {
borenetdb182c72016-09-30 12:53:12 -0700448 if strings.Contains(name, "Mac") {
boreneted20a702016-10-20 11:04:31 -0700449 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400450 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400451 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
452 pkg.Path = "n"
453 pkgs = append(pkgs, pkg)
borenetdb182c72016-09-30 12:53:12 -0700454 } else {
boreneted20a702016-10-20 11:04:31 -0700455 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("android_ndk_linux"))
borenetdb182c72016-09-30 12:53:12 -0700456 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500457 } else if strings.Contains(name, "Chromecast") {
458 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("cast_toolchain"))
Kevin Lubickffce0792017-05-24 15:30:35 -0400459 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400460 } else if strings.Contains(name, "Chromebook") {
461 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
462 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
Kevin Lubick671cd722017-04-12 10:50:18 -0400463 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Eric Borenbb198fb2017-06-28 11:45:54 -0400464 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500465 if strings.Contains(name, "Clang") {
466 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
467 }
468 if strings.Contains(name, "Vulkan") {
469 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
470 }
Mike Klein27dcee12016-11-09 16:31:42 -0500471 } else if strings.Contains(name, "Win") {
boreneted20a702016-10-20 11:04:31 -0700472 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("win_toolchain"))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400473 if strings.Contains(name, "Clang") {
474 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_win"))
475 }
borenetdb182c72016-09-30 12:53:12 -0700476 if strings.Contains(name, "Vulkan") {
boreneted20a702016-10-20 11:04:31 -0700477 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("win_vulkan_sdk"))
borenetdb182c72016-09-30 12:53:12 -0700478 }
479 }
480
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400481 // TODO(stephana): Remove this once all Mac machines are on the same
482 // OS version again. Move the call to swarmDimensions back to the
483 // creation of the TaskSpec struct below.
484 dimensions := swarmDimensions(parts)
485 if strings.Contains(name, "Mac") {
486 for idx, dim := range dimensions {
487 if strings.HasPrefix(dim, "os") {
488 dimensions[idx] = "os:Mac-10.12"
489 break
490 }
491 }
492 }
493
borenetdb182c72016-09-30 12:53:12 -0700494 // Add the task.
boreneted20a702016-10-20 11:04:31 -0700495 b.MustAddTask(name, &specs.TaskSpec{
borenetdb182c72016-09-30 12:53:12 -0700496 CipdPackages: pkgs,
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400497 Dimensions: dimensions,
borenetdb182c72016-09-30 12:53:12 -0700498 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400499 "--workdir", "../../..", "compile",
skia.buildbots2478c732016-11-04 14:37:26 -0400500 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700501 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700502 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
503 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400504 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700505 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400506 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
507 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700508 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400509 Isolate: relpath("compile_skia.isolate"),
borenetdb182c72016-09-30 12:53:12 -0700510 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700511 })
Eric Boren8615fe52016-12-12 14:30:12 -0500512 // All compile tasks are runnable as their own Job. Assert that the Job
513 // is listed in JOBS.
514 if !util.In(name, JOBS) {
515 glog.Fatalf("Job %q is missing from the JOBS list!", name)
516 }
borenetdb182c72016-09-30 12:53:12 -0700517 return name
518}
519
520// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
521// task in the generated chain of tasks, which the Job should add as a
522// dependency.
boreneted20a702016-10-20 11:04:31 -0700523func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500524 b.MustAddTask(name, &specs.TaskSpec{
Eric Borenf9c09042017-04-17 07:50:20 -0400525 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
Eric Boren27225492017-02-01 15:56:55 -0500526 Dimensions: linuxGceDimensions(),
Eric Borenf5a90e82016-11-15 15:18:20 -0500527 ExecutionTimeout: 4 * time.Hour,
Eric Boren4b254b92016-11-08 12:55:32 -0500528 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400529 "--workdir", "../../..", "recreate_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500530 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
531 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500532 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
533 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400534 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500535 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
536 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
537 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
538 },
Eric Borenf5a90e82016-11-15 15:18:20 -0500539 IoTimeout: 40 * time.Minute,
Eric Boren7e3a3642017-06-14 15:25:31 -0400540 Isolate: relpath("compile_skia.isolate"),
Eric Borenf5a90e82016-11-15 15:18:20 -0500541 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500542 })
borenetdb182c72016-09-30 12:53:12 -0700543 return name
544}
545
Ravi Mistry01b48e72017-05-17 14:28:06 -0400546// updateMetaConfig generates a UpdateMetaConfig task. Returns the name of the
547// last task in the generated chain of tasks, which the Job should add as a
548// dependency.
549func updateMetaConfig(b *specs.TasksCfgBuilder, name string) string {
550 b.MustAddTask(name, &specs.TaskSpec{
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400551 CipdPackages: []*specs.CipdPackage{},
552 Dimensions: linuxGceDimensions(),
Ravi Mistry01b48e72017-05-17 14:28:06 -0400553 ExtraArgs: []string{
554 "--workdir", "../../..", "update_meta_config",
555 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
556 fmt.Sprintf("buildername=%s", name),
557 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
558 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
559 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
560 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
561 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
562 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
563 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400564 Isolate: relpath("meta_config.isolate"),
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400565 Priority: 0.8,
Ravi Mistry01b48e72017-05-17 14:28:06 -0400566 })
567 return name
568}
569
borenetdb182c72016-09-30 12:53:12 -0700570// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
571// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700572func ctSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500573 b.MustAddTask(name, &specs.TaskSpec{
Ben Wagner21c3fb92017-08-04 14:13:27 -0400574 CipdPackages: []*specs.CipdPackage{},
575 Dimensions: []string{
576 "pool:SkiaCT",
Ravi Mistry0ac06e42017-08-08 07:39:09 -0400577 "os:Debian-9.1",
Ben Wagner21c3fb92017-08-04 14:13:27 -0400578 },
Eric Boren4b254b92016-11-08 12:55:32 -0500579 ExecutionTimeout: 24 * time.Hour,
580 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400581 "--workdir", "../../..", "ct_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500582 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
583 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500584 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
585 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400586 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500587 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
588 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
589 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
590 },
591 IoTimeout: time.Hour,
Eric Boren7e3a3642017-06-14 15:25:31 -0400592 Isolate: relpath("ct_skps_skia.isolate"),
Eric Boren4b254b92016-11-08 12:55:32 -0500593 Priority: 0.8,
594 })
borenetdb182c72016-09-30 12:53:12 -0700595 return name
596}
597
Eric Borenf7928b42017-07-28 07:35:28 -0400598// checkGeneratedFiles verifies that no generated SKSL files have been edited
599// by hand.
600func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
601 b.MustAddTask(name, &specs.TaskSpec{
602 CipdPackages: []*specs.CipdPackage{},
603 Dimensions: linuxGceDimensions(),
604 ExtraArgs: []string{
605 "--workdir", "../../..", "check_generated_files",
606 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
607 fmt.Sprintf("buildername=%s", name),
608 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
609 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
610 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
611 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
612 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
613 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
614 },
615 Isolate: relpath("compile_skia.isolate"),
616 Priority: 0.8,
617 })
618 return name
619}
620
borenetdb182c72016-09-30 12:53:12 -0700621// housekeeper generates a Housekeeper task. Returns the name of the last task
622// in the generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700623func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500624 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren22f5ef72016-12-02 11:01:33 -0500625 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
Eric Boren4b254b92016-11-08 12:55:32 -0500626 Dependencies: []string{compileTaskName},
Eric Boren27225492017-02-01 15:56:55 -0500627 Dimensions: linuxGceDimensions(),
Eric Boren4b254b92016-11-08 12:55:32 -0500628 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400629 "--workdir", "../../..", "housekeeper",
Eric Boren4b254b92016-11-08 12:55:32 -0500630 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
631 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500632 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
633 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400634 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500635 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
636 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
637 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
638 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400639 Isolate: relpath("housekeeper_skia.isolate"),
Eric Boren4b254b92016-11-08 12:55:32 -0500640 Priority: 0.8,
641 })
borenetdb182c72016-09-30 12:53:12 -0700642 return name
643}
644
borenet2dbbfa52016-10-14 06:32:09 -0700645// infra generates an infra_tests task. Returns the name of the last task in the
646// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700647func infra(b *specs.TasksCfgBuilder, name string) string {
648 b.MustAddTask(name, &specs.TaskSpec{
Eric Borenade69202017-04-13 10:00:43 -0400649 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
Eric Boren27225492017-02-01 15:56:55 -0500650 Dimensions: linuxGceDimensions(),
borenet2dbbfa52016-10-14 06:32:09 -0700651 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400652 "--workdir", "../../..", "infra",
skia.buildbots2478c732016-11-04 14:37:26 -0400653 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700654 fmt.Sprintf("buildername=%s", name),
borenet2dbbfa52016-10-14 06:32:09 -0700655 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
656 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400657 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700658 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400659 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
660 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenet2dbbfa52016-10-14 06:32:09 -0700661 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400662 Isolate: relpath("infra_skia.isolate"),
borenet2dbbfa52016-10-14 06:32:09 -0700663 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700664 })
borenet2dbbfa52016-10-14 06:32:09 -0700665 return name
666}
667
borenetdb182c72016-09-30 12:53:12 -0700668// doUpload indicates whether the given Job should upload its results.
669func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -0500670 for _, s := range CONFIG.NoUpload {
671 m, err := regexp.MatchString(s, name)
672 if err != nil {
673 glog.Fatal(err)
674 }
675 if m {
borenetdb182c72016-09-30 12:53:12 -0700676 return false
677 }
678 }
679 return true
680}
681
682// test generates a Test task. Returns the name of the last task in the
683// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700684func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500685 s := &specs.TaskSpec{
Eric Boren1f2f64b2016-11-09 18:35:15 -0500686 CipdPackages: pkgs,
687 Dependencies: []string{compileTaskName},
688 Dimensions: swarmDimensions(parts),
689 ExecutionTimeout: 4 * time.Hour,
690 Expiration: 20 * time.Hour,
borenetdb182c72016-09-30 12:53:12 -0700691 ExtraArgs: []string{
Eric Boren768f52f2017-04-10 08:14:33 -0400692 "--workdir", "../../..", "test",
skia.buildbots2478c732016-11-04 14:37:26 -0400693 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700694 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700695 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
696 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400697 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700698 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400699 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
700 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700701 },
Eric Boren5d9f3bf2017-02-22 08:36:03 -0500702 IoTimeout: 40 * time.Minute,
Eric Boren7e3a3642017-06-14 15:25:31 -0400703 Isolate: relpath("test_skia.isolate"),
Eric Boren5d9f3bf2017-02-22 08:36:03 -0500704 MaxAttempts: 1,
705 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500706 }
Eric Boren23a6ec62017-04-07 08:31:22 -0400707 if useBundledRecipes(parts) {
Eric Boren8b3f9e62017-04-04 09:06:16 -0400708 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
Eric Boren23a6ec62017-04-07 08:31:22 -0400709 if strings.Contains(parts["os"], "Win") {
Eric Boren7e3a3642017-06-14 15:25:31 -0400710 s.Isolate = relpath("test_skia_bundled_win.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400711 } else {
Eric Boren7e3a3642017-06-14 15:25:31 -0400712 s.Isolate = relpath("test_skia_bundled_unix.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400713 }
Eric Boren8b3f9e62017-04-04 09:06:16 -0400714 }
Kevin Lubick90189522017-05-15 08:30:27 -0400715 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
716 s.Dependencies = append(s.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -0400717 }
Eric Boren4b254b92016-11-08 12:55:32 -0500718 if strings.Contains(parts["extra_config"], "Valgrind") {
719 s.ExecutionTimeout = 9 * time.Hour
720 s.Expiration = 48 * time.Hour
721 s.IoTimeout = time.Hour
Eric Borend696df72017-05-31 15:09:10 -0400722 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Eric Boren4b254b92016-11-08 12:55:32 -0500723 } else if strings.Contains(parts["extra_config"], "MSAN") {
724 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -0400725 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
726 // skia:6737
727 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -0500728 }
729 b.MustAddTask(name, s)
730
borenetdb182c72016-09-30 12:53:12 -0700731 // Upload results if necessary.
732 if doUpload(name) {
733 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -0700734 b.MustAddTask(uploadName, &specs.TaskSpec{
borenetdb182c72016-09-30 12:53:12 -0700735 Dependencies: []string{name},
Eric Boren27225492017-02-01 15:56:55 -0500736 Dimensions: linuxGceDimensions(),
borenetdb182c72016-09-30 12:53:12 -0700737 ExtraArgs: []string{
738 "--workdir", "../../..", "upload_dm_results",
skia.buildbots2478c732016-11-04 14:37:26 -0400739 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700740 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700741 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
742 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400743 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700744 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400745 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
746 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -0500747 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketGm),
borenetdb182c72016-09-30 12:53:12 -0700748 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400749 Isolate: relpath("upload_dm_results.isolate"),
borenetdb182c72016-09-30 12:53:12 -0700750 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700751 })
borenetdb182c72016-09-30 12:53:12 -0700752 return uploadName
753 }
754 return name
755}
756
757// perf generates a Perf task. Returns the name of the last task in the
758// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700759func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -0400760 recipe := "perf"
Eric Boren7e3a3642017-06-14 15:25:31 -0400761 isolate := relpath("perf_skia.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -0500762 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -0400763 recipe = "skpbench"
Eric Boren7e3a3642017-06-14 15:25:31 -0400764 isolate = relpath("skpbench_skia.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400765 if useBundledRecipes(parts) {
766 if strings.Contains(parts["os"], "Win") {
Eric Boren7e3a3642017-06-14 15:25:31 -0400767 isolate = relpath("skpbench_skia_bundled_win.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400768 } else {
Eric Boren7e3a3642017-06-14 15:25:31 -0400769 isolate = relpath("skpbench_skia_bundled_unix.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400770 }
Eric Boren8b3f9e62017-04-04 09:06:16 -0400771 }
Eric Boren23a6ec62017-04-07 08:31:22 -0400772 } else if useBundledRecipes(parts) {
773 if strings.Contains(parts["os"], "Win") {
Eric Boren7e3a3642017-06-14 15:25:31 -0400774 isolate = relpath("perf_skia_bundled_win.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400775 } else {
Eric Boren7e3a3642017-06-14 15:25:31 -0400776 isolate = relpath("perf_skia_bundled_unix.isolate")
Eric Boren23a6ec62017-04-07 08:31:22 -0400777 }
Kevin Lubickb03b5ac2016-11-14 13:42:27 -0500778 }
Eric Boren4b254b92016-11-08 12:55:32 -0500779 s := &specs.TaskSpec{
Eric Boren1f2f64b2016-11-09 18:35:15 -0500780 CipdPackages: pkgs,
781 Dependencies: []string{compileTaskName},
782 Dimensions: swarmDimensions(parts),
783 ExecutionTimeout: 4 * time.Hour,
784 Expiration: 20 * time.Hour,
borenetdb182c72016-09-30 12:53:12 -0700785 ExtraArgs: []string{
Kevin Lubickb03b5ac2016-11-14 13:42:27 -0500786 "--workdir", "../../..", recipe,
skia.buildbots2478c732016-11-04 14:37:26 -0400787 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700788 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700789 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
790 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400791 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700792 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400793 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
794 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700795 },
Eric Boren5d9f3bf2017-02-22 08:36:03 -0500796 IoTimeout: 40 * time.Minute,
797 Isolate: isolate,
798 MaxAttempts: 1,
799 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500800 }
Eric Boren23a6ec62017-04-07 08:31:22 -0400801 if useBundledRecipes(parts) {
Eric Boren8b3f9e62017-04-04 09:06:16 -0400802 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
803 }
Kevin Lubick90189522017-05-15 08:30:27 -0400804 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
805 s.Dependencies = append(s.Dependencies, deps...)
806 }
807
Eric Boren4b254b92016-11-08 12:55:32 -0500808 if strings.Contains(parts["extra_config"], "Valgrind") {
809 s.ExecutionTimeout = 9 * time.Hour
810 s.Expiration = 48 * time.Hour
811 s.IoTimeout = time.Hour
Eric Borenc5a073d2017-06-01 07:13:33 -0400812 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Eric Boren4b254b92016-11-08 12:55:32 -0500813 } else if strings.Contains(parts["extra_config"], "MSAN") {
814 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -0400815 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
816 // skia:6737
817 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -0500818 }
819 b.MustAddTask(name, s)
820
borenetdb182c72016-09-30 12:53:12 -0700821 // Upload results if necessary.
822 if strings.Contains(name, "Release") && doUpload(name) {
823 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -0700824 b.MustAddTask(uploadName, &specs.TaskSpec{
borenetdb182c72016-09-30 12:53:12 -0700825 Dependencies: []string{name},
Eric Boren27225492017-02-01 15:56:55 -0500826 Dimensions: linuxGceDimensions(),
borenetdb182c72016-09-30 12:53:12 -0700827 ExtraArgs: []string{
828 "--workdir", "../../..", "upload_nano_results",
skia.buildbots2478c732016-11-04 14:37:26 -0400829 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700830 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700831 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
832 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400833 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700834 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400835 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
836 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -0500837 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketNano),
borenetdb182c72016-09-30 12:53:12 -0700838 },
Eric Boren7e3a3642017-06-14 15:25:31 -0400839 Isolate: relpath("upload_nano_results.isolate"),
borenetdb182c72016-09-30 12:53:12 -0700840 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700841 })
borenetdb182c72016-09-30 12:53:12 -0700842 return uploadName
843 }
844 return name
845}
846
847// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -0700848func process(b *specs.TasksCfgBuilder, name string) {
borenetdb182c72016-09-30 12:53:12 -0700849 deps := []string{}
850
Eric Boren8b3f9e62017-04-04 09:06:16 -0400851 // Bundle Recipes.
852 if name == BUNDLE_RECIPES_NAME {
853 deps = append(deps, bundleRecipes(b))
854 }
855
Kevin Lubick07072942017-05-11 13:35:23 -0400856 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -0400857 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
858 deps = append(deps, isolateCIPDAsset(b, name))
859 }
860
borenetdb182c72016-09-30 12:53:12 -0700861 parts, err := jobNameSchema.ParseJobName(name)
862 if err != nil {
863 glog.Fatal(err)
864 }
865
866 // RecreateSKPs.
867 if strings.Contains(name, "RecreateSKPs") {
boreneted20a702016-10-20 11:04:31 -0700868 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -0700869 }
870
Ravi Mistry01b48e72017-05-17 14:28:06 -0400871 // UpdateMetaConfig bot.
872 if strings.Contains(name, "UpdateMetaConfig") {
873 deps = append(deps, updateMetaConfig(b, name))
874 }
875
borenetdb182c72016-09-30 12:53:12 -0700876 // CT bots.
877 if strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -0700878 deps = append(deps, ctSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -0700879 }
880
borenet2dbbfa52016-10-14 06:32:09 -0700881 // Infra tests.
882 if name == "Housekeeper-PerCommit-InfraTests" {
boreneted20a702016-10-20 11:04:31 -0700883 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -0700884 }
885
borenetdb182c72016-09-30 12:53:12 -0700886 // Compile bots.
887 if parts["role"] == "Build" {
boreneted20a702016-10-20 11:04:31 -0700888 deps = append(deps, compile(b, name, parts))
borenetdb182c72016-09-30 12:53:12 -0700889 }
890
Eric Borenf5a90e82016-11-15 15:18:20 -0500891 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -0700892 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -0700893 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
894 if err != nil {
895 glog.Fatal(err)
896 }
Eric Boren628e78b2016-11-17 11:33:27 -0500897 // These bots do not need a compile task.
Eric Borenf5a90e82016-11-15 15:18:20 -0500898 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -0400899 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -0500900 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -0400901 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Boren71b762f2016-11-30 14:05:16 -0500902 !strings.Contains(name, "RecreateSKPs") &&
Ravi Mistry01b48e72017-05-17 14:28:06 -0400903 !strings.Contains(name, "UpdateMetaConfig") &&
Ben Wagner50b84682017-06-12 13:03:29 -0400904 !strings.Contains(name, "-CT_") &&
905 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") {
boreneted20a702016-10-20 11:04:31 -0700906 compile(b, compileTaskName, compileTaskParts)
borenet52383432016-10-17 10:17:53 -0700907 }
borenetdb182c72016-09-30 12:53:12 -0700908
Eric Borenf7928b42017-07-28 07:35:28 -0400909 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -0500910 if name == "Housekeeper-PerCommit" {
boreneted20a702016-10-20 11:04:31 -0700911 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -0700912 }
Eric Borenf7928b42017-07-28 07:35:28 -0400913 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
914 deps = append(deps, checkGeneratedFiles(b, name))
915 }
borenetdb182c72016-09-30 12:53:12 -0700916
917 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -0400918
919 pkgs := []*specs.CipdPackage{}
920
Kevin Lubick90189522017-05-15 08:30:27 -0400921 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -0400922 pkgs = []*specs.CipdPackage{
923 b.MustGetCipdPackageFromAsset("skimage"),
924 b.MustGetCipdPackageFromAsset("skp"),
925 b.MustGetCipdPackageFromAsset("svg"),
926 }
borenetdb182c72016-09-30 12:53:12 -0700927 }
Kevin Lubick90189522017-05-15 08:30:27 -0400928
Eric Boren25062cf2017-06-29 15:22:46 -0400929 if (strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian")) && strings.Contains(name, "SAN") {
Eric Boren4b254b92016-11-08 12:55:32 -0500930 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
931 }
Kevin Lubick35115eb2017-02-17 10:25:34 -0500932 if strings.Contains(name, "Ubuntu16") {
933 if strings.Contains(name, "Vulkan") {
934 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
935 }
Kevin Lubick0a51b482017-02-06 12:45:29 -0500936 if strings.Contains(name, "Release") {
937 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
938 } else {
939 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
940 }
941 }
borenetdb182c72016-09-30 12:53:12 -0700942
943 // Test bots.
Eric Boren71b762f2016-11-30 14:05:16 -0500944 if parts["role"] == "Test" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -0700945 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -0700946 }
947
948 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -0500949 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -0700950 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -0700951 }
952
953 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -0500954 j := &specs.JobSpec{
borenetdb182c72016-09-30 12:53:12 -0700955 Priority: 0.8,
956 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -0400957 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -0500958 }
Eric Borenba937a42017-07-31 10:41:15 -0400959 if strings.Contains(name, "-Nightly-") {
960 j.Trigger = specs.TRIGGER_NIGHTLY
961 } else if strings.Contains(name, "-Weekly-") || name == "Test-Ubuntu14-GCC-GCE-CPU-AVX2-x86_64-Debug-CT_DM_1m_SKPs" {
962 j.Trigger = specs.TRIGGER_WEEKLY
963 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "PDFium") || strings.Contains(name, "CommandBuffer") {
964 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren71b762f2016-11-30 14:05:16 -0500965 }
Eric Boren8615fe52016-12-12 14:30:12 -0500966 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -0700967}
968
Eric Boren27225492017-02-01 15:56:55 -0500969func loadJson(flag *string, defaultFlag string, val interface{}) {
970 if *flag == "" {
971 *flag = defaultFlag
972 }
973 b, err := ioutil.ReadFile(*flag)
974 if err != nil {
975 glog.Fatal(err)
976 }
977 if err := json.Unmarshal(b, val); err != nil {
978 glog.Fatal(err)
979 }
980}
981
borenetdb182c72016-09-30 12:53:12 -0700982// Regenerate the tasks.json file.
983func main() {
boreneted20a702016-10-20 11:04:31 -0700984 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -0500985 b.SetAssetsDir(*assetsDir)
986 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
987
988 // Load the jobs from a JSON file.
989 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
990
Eric Boren27225492017-02-01 15:56:55 -0500991 // Load general config information from a JSON file.
992 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
993
borenetdb182c72016-09-30 12:53:12 -0700994 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -0500995 if *builderNameSchemaFile == "" {
996 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
997 }
998 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -0700999 if err != nil {
1000 glog.Fatal(err)
1001 }
1002 jobNameSchema = schema
1003
borenetdb182c72016-09-30 12:53:12 -07001004 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001005 for _, name := range JOBS {
1006 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001007 }
1008
boreneted20a702016-10-20 11:04:31 -07001009 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001010}
1011
1012// TODO(borenet): The below really belongs in its own file, probably next to the
1013// builder_name_schema.json file.
1014
1015// JobNameSchema is a struct used for (de)constructing Job names in a
1016// predictable format.
1017type JobNameSchema struct {
1018 Schema map[string][]string `json:"builder_name_schema"`
1019 Sep string `json:"builder_name_sep"`
1020}
1021
1022// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1023// file.
1024func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1025 var rv JobNameSchema
1026 f, err := os.Open(jsonFile)
1027 if err != nil {
1028 return nil, err
1029 }
1030 defer util.Close(f)
1031 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1032 return nil, err
1033 }
1034 return &rv, nil
1035}
1036
1037// ParseJobName splits the given Job name into its component parts, according
1038// to the schema.
1039func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
1040 split := strings.Split(n, s.Sep)
1041 if len(split) < 2 {
1042 return nil, fmt.Errorf("Invalid job name: %q", n)
1043 }
1044 role := split[0]
1045 split = split[1:]
1046 keys, ok := s.Schema[role]
1047 if !ok {
1048 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1049 }
1050 extraConfig := ""
1051 if len(split) == len(keys)+1 {
1052 extraConfig = split[len(split)-1]
1053 split = split[:len(split)-1]
1054 }
1055 if len(split) != len(keys) {
1056 return nil, fmt.Errorf("Invalid job name; %q has incorrect number of parts.", n)
1057 }
1058 rv := make(map[string]string, len(keys)+2)
1059 rv["role"] = role
1060 if extraConfig != "" {
1061 rv["extra_config"] = extraConfig
1062 }
1063 for i, k := range keys {
1064 rv[k] = split[i]
1065 }
1066 return rv, nil
1067}
1068
1069// MakeJobName assembles the given parts of a Job name, according to the schema.
1070func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
1071 role, ok := parts["role"]
1072 if !ok {
1073 return "", fmt.Errorf("Invalid job parts; jobs must have a role.")
1074 }
1075 keys, ok := s.Schema[role]
1076 if !ok {
1077 return "", fmt.Errorf("Invalid job parts; unknown role %q", role)
1078 }
1079 rvParts := make([]string, 0, len(parts))
1080 rvParts = append(rvParts, role)
1081 for _, k := range keys {
1082 v, ok := parts[k]
1083 if !ok {
1084 return "", fmt.Errorf("Invalid job parts; missing %q", k)
1085 }
1086 rvParts = append(rvParts, v)
1087 }
1088 if _, ok := parts["extra_config"]; ok {
1089 rvParts = append(rvParts, parts["extra_config"])
1090 }
1091 return strings.Join(rvParts, s.Sep), nil
1092}