blob: 6534fe922137de9a8c620fa15fb604bb8a2ae8be [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"
38 ISOLATE_WIN_TOOLCHAIN_NAME = "Housekeeper-PerCommit-IsolateWinToolchain"
39 ISOLATE_WIN_VULKAN_SDK_NAME = "Housekeeper-PerCommit-IsolateWinVulkanSDK"
Eric Boren8b3f9e62017-04-04 09:06:16 -040040
Eric Boren170c39c2017-11-15 11:22:57 -050041 DEFAULT_OS_DEBIAN = "Debian-9.1"
42 DEFAULT_OS_LINUX_GCE = "Debian-9.2"
Ben Wagnere463d982018-01-03 16:15:33 -050043 DEFAULT_OS_MAC = "Mac-10.13.2"
Eric Boren170c39c2017-11-15 11:22:57 -050044 DEFAULT_OS_UBUNTU = "Ubuntu-14.04"
45 DEFAULT_OS_WIN = "Windows-2016Server-14393"
borenetdb182c72016-09-30 12:53:12 -070046
borenetdb182c72016-09-30 12:53:12 -070047 // Name prefix for upload jobs.
48 PREFIX_UPLOAD = "Upload"
49)
50
51var (
52 // "Constants"
53
Eric Boren27225492017-02-01 15:56:55 -050054 // Top-level list of all jobs to run at each commit; loaded from
55 // jobs.json.
56 JOBS []string
57
Eric Boren27225492017-02-01 15:56:55 -050058 // General configuration information.
59 CONFIG struct {
Kevin Lubickc795a4c2017-10-09 15:26:19 -040060 GsBucketCoverage string `json:"gs_bucket_coverage"`
61 GsBucketGm string `json:"gs_bucket_gm"`
62 GsBucketNano string `json:"gs_bucket_nano"`
Yuqian Li2ebf3d12017-10-24 09:43:21 -040063 GsBucketCalm string `json:"gs_bucket_calm"`
Kevin Lubickc795a4c2017-10-09 15:26:19 -040064 NoUpload []string `json:"no_upload"`
65 Pool string `json:"pool"`
borenetdb182c72016-09-30 12:53:12 -070066 }
67
Ben Wagner3d2a2f72017-06-13 17:01:16 -040068 // alternateSwarmDimensions can be set in an init function to override the default swarming bot
69 // dimensions for the given task.
70 alternateSwarmDimensions func(parts map[string]string) []string
71
Eric Borenfd4d60e2017-09-15 10:35:44 -040072 // internalHardwareLabelFn can be set in an init function to provide an
73 // internal_hardware_label variable to the recipe.
Eric Boren4dc4aaf2017-09-15 14:09:07 -040074 internalHardwareLabelFn func(parts map[string]string) *int
Eric Boren053d7a42017-09-15 08:35:31 -040075
borenetdb182c72016-09-30 12:53:12 -070076 // Defines the structure of job names.
77 jobNameSchema *JobNameSchema
Eric Boren27225492017-02-01 15:56:55 -050078
Eric Borenf4a5fc72017-06-06 08:27:09 -040079 // Git 2.13.
Eric Boren9d78afd2017-12-07 14:54:05 +000080 cipdGit1 = &specs.CipdPackage{
81 Name: fmt.Sprintf("infra/git/${platform}"),
82 Path: "git",
83 Version: fmt.Sprintf("version:2.13.0.chromium9"),
Eric Borenf4a5fc72017-06-06 08:27:09 -040084 }
Eric Boren9d78afd2017-12-07 14:54:05 +000085 cipdGit2 = &specs.CipdPackage{
86 Name: fmt.Sprintf("infra/tools/git/${platform}"),
87 Path: "git",
88 Version: fmt.Sprintf("git_revision:a78b5f3658c0578a017db48df97d20ac09822bcd"),
89 }
Eric Borenf4a5fc72017-06-06 08:27:09 -040090
Eric Boren27225492017-02-01 15:56:55 -050091 // Flags.
Eric Boren1f8be682017-02-07 09:16:30 -050092 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.")
93 assetsDir = flag.String("assets_dir", "", "Directory containing assets.")
94 cfgFile = flag.String("cfg_file", "", "JSON file containing general configuration information.")
Eric Boren1f8be682017-02-07 09:16:30 -050095 jobsFile = flag.String("jobs", "", "JSON file containing jobs to run.")
borenetdb182c72016-09-30 12:53:12 -070096)
97
Eric Borenfd4d60e2017-09-15 10:35:44 -040098// internalHardwareLabel returns the internal ID for the bot, if any.
Eric Boren4dc4aaf2017-09-15 14:09:07 -040099func internalHardwareLabel(parts map[string]string) *int {
Eric Borenfd4d60e2017-09-15 10:35:44 -0400100 if internalHardwareLabelFn != nil {
101 return internalHardwareLabelFn(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400102 }
103 return nil
104}
105
Eric Boren27225492017-02-01 15:56:55 -0500106// linuxGceDimensions are the Swarming dimensions for Linux GCE
107// instances.
108func linuxGceDimensions() []string {
109 return []string{
Ben Wagner4c9842e2017-09-25 12:56:53 -0400110 // Specify CPU to avoid running builds on bots with a more unique CPU.
111 "cpu:x86-64-Haswell_GCE",
Eric Boren27225492017-02-01 15:56:55 -0500112 "gpu:none",
Eric Boren170c39c2017-11-15 11:22:57 -0500113 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
Eric Boren27225492017-02-01 15:56:55 -0500114 fmt.Sprintf("pool:%s", CONFIG.Pool),
115 }
116}
117
borenetdb182c72016-09-30 12:53:12 -0700118// deriveCompileTaskName returns the name of a compile task based on the given
119// job name.
120func deriveCompileTaskName(jobName string, parts map[string]string) string {
Ravi Mistryd4731e92018-01-02 14:54:43 -0500121 if strings.Contains(jobName, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500122 return "Build-Debian9-GCC-x86_64-Release"
123 } else if parts["role"] == "Housekeeper" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400124 return "Build-Debian9-GCC-x86_64-Release-Shared"
Yuqian Li4a577af2018-01-05 11:13:43 -0500125 } else if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
borenetdb182c72016-09-30 12:53:12 -0700126 task_os := parts["os"]
Ben Wagner988d15e2017-04-27 13:08:50 -0400127 ec := []string{}
128 if val := parts["extra_config"]; val != "" {
129 ec = strings.Split(val, "_")
Ben Wagnerdba0bc82017-12-11 13:27:27 -0500130 ignore := []string{"Skpbench", "AbandonGpuContext", "PreAbandonGpuContext", "Valgrind", "ReleaseAndAbandonGpuContext", "CCPR", "FSAA", "FAAA", "FDAA", "NativeFonts", "GDI", "NoGPUThreads"}
Ben Wagner988d15e2017-04-27 13:08:50 -0400131 keep := make([]string, 0, len(ec))
132 for _, part := range ec {
133 if !util.In(part, ignore) {
134 keep = append(keep, part)
135 }
136 }
137 ec = keep
Eric Boren6ec17e32017-04-26 14:25:29 -0400138 }
borenetdb182c72016-09-30 12:53:12 -0700139 if task_os == "Android" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400140 if !util.In("Android", ec) {
141 ec = append([]string{"Android"}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700142 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400143 task_os = "Debian9"
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500144 } else if task_os == "Chromecast" {
Eric Borenbb198fb2017-06-28 11:45:54 -0400145 task_os = "Debian9"
Ben Wagner988d15e2017-04-27 13:08:50 -0400146 ec = append([]string{"Chromecast"}, ec...)
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400147 } else if strings.Contains(task_os, "ChromeOS") {
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400148 ec = append([]string{"Chromebook", "GLES"}, ec...)
Eric Borenbb198fb2017-06-28 11:45:54 -0400149 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700150 } else if task_os == "iOS" {
Ben Wagner988d15e2017-04-27 13:08:50 -0400151 ec = append([]string{task_os}, ec...)
borenetdb182c72016-09-30 12:53:12 -0700152 task_os = "Mac"
153 } else if strings.Contains(task_os, "Win") {
154 task_os = "Win"
Eric Borenbb198fb2017-06-28 11:45:54 -0400155 } else if strings.Contains(task_os, "Ubuntu") || strings.Contains(task_os, "Debian") {
156 task_os = "Debian9"
borenetdb182c72016-09-30 12:53:12 -0700157 }
Eric Boren50831302016-11-18 13:10:51 -0500158 jobNameMap := map[string]string{
borenetdb182c72016-09-30 12:53:12 -0700159 "role": "Build",
160 "os": task_os,
161 "compiler": parts["compiler"],
162 "target_arch": parts["arch"],
163 "configuration": parts["configuration"],
Eric Boren50831302016-11-18 13:10:51 -0500164 }
Ben Wagner988d15e2017-04-27 13:08:50 -0400165 if len(ec) > 0 {
166 jobNameMap["extra_config"] = strings.Join(ec, "_")
Eric Boren50831302016-11-18 13:10:51 -0500167 }
168 name, err := jobNameSchema.MakeJobName(jobNameMap)
borenetdb182c72016-09-30 12:53:12 -0700169 if err != nil {
170 glog.Fatal(err)
171 }
172 return name
173 } else {
174 return jobName
175 }
176}
177
178// swarmDimensions generates swarming bot dimensions for the given task.
179func swarmDimensions(parts map[string]string) []string {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400180 if alternateSwarmDimensions != nil {
181 return alternateSwarmDimensions(parts)
182 }
183 return defaultSwarmDimensions(parts)
184}
185
186// defaultSwarmDimensions generates default swarming bot dimensions for the given task.
187func defaultSwarmDimensions(parts map[string]string) []string {
borenetdb182c72016-09-30 12:53:12 -0700188 d := map[string]string{
Eric Boren27225492017-02-01 15:56:55 -0500189 "pool": CONFIG.Pool,
borenetdb182c72016-09-30 12:53:12 -0700190 }
191 if os, ok := parts["os"]; ok {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400192 d["os"], ok = map[string]string{
Kevin Lubick291547d2017-03-21 09:25:34 -0400193 "Android": "Android",
194 "Chromecast": "Android",
Kevin Lubickcb6f3982017-04-07 10:04:08 -0400195 "ChromeOS": "ChromeOS",
Eric Borenbb198fb2017-06-28 11:45:54 -0400196 "Debian9": DEFAULT_OS_DEBIAN,
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500197 "Mac": DEFAULT_OS_MAC,
Eric Borenbb198fb2017-06-28 11:45:54 -0400198 "Ubuntu14": DEFAULT_OS_UBUNTU,
Kevin Lubick291547d2017-03-21 09:25:34 -0400199 "Ubuntu16": "Ubuntu-16.10",
Eric Boren810c2b62017-07-11 08:11:15 -0400200 "Ubuntu17": "Ubuntu-17.04",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500201 "Win": DEFAULT_OS_WIN,
Ben Wagner40226b42017-05-02 13:13:13 -0400202 "Win10": "Windows-10-15063",
Kevin Lubick291547d2017-03-21 09:25:34 -0400203 "Win2k8": "Windows-2008ServerR2-SP1",
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500204 "Win2016": DEFAULT_OS_WIN,
Ben Wagner56738d82017-04-18 15:38:15 -0400205 "Win7": "Windows-7-SP1",
Kevin Lubick291547d2017-03-21 09:25:34 -0400206 "Win8": "Windows-8.1-SP0",
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400207 "iOS": "iOS-10.3.1",
Eric Boren54ff2fc2016-12-02 12:09:10 -0500208 }[os]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400209 if !ok {
210 glog.Fatalf("Entry %q not found in OS mapping.", os)
211 }
borenetdb182c72016-09-30 12:53:12 -0700212 } else {
Eric Borenbb198fb2017-06-28 11:45:54 -0400213 d["os"] = DEFAULT_OS_DEBIAN
borenetdb182c72016-09-30 12:53:12 -0700214 }
Yuqian Liab246cb2017-11-02 13:48:23 -0400215 if parts["role"] == "Test" || parts["role"] == "Perf" || parts["role"] == "Calmbench" {
Kevin Lubick291547d2017-03-21 09:25:34 -0400216 if strings.Contains(parts["os"], "Android") || strings.Contains(parts["os"], "Chromecast") {
borenetdb182c72016-09-30 12:53:12 -0700217 // For Android, the device type is a better dimension
218 // than CPU or GPU.
Ben Wagner36682782017-06-14 10:01:45 -0400219 deviceInfo, ok := map[string][]string{
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400220 "AndroidOne": {"sprout", "MOB30Q"},
221 "Chorizo": {"chorizo", "1.24_82923"},
Ben Wagner0762bdf2017-11-28 09:41:48 -0500222 "GalaxyS6": {"zerofltetmo", "NRD90M_G920TUVU5FQK1"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400223 "GalaxyS7_G930A": {"heroqlteatt", "NRD90M_G930AUCS4BQC2"},
224 "GalaxyS7_G930FD": {"herolte", "NRD90M_G930FXXU1DQAS"},
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400225 "MotoG4": {"athene", "NPJ25.93-14"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500226 "NVIDIA_Shield": {"foster", "NRD90M_1915764_848"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500227 "Nexus5": {"hammerhead", "M4B30Z_3437181"},
Ben Wagnereb549c82017-11-17 08:59:44 -0500228 "Nexus5x": {"bullhead", "OPR6.170623.023"},
Ben Wagneree3123c2017-12-06 16:29:04 -0500229 "Nexus7": {"grouper", "LMY47V_1836172"}, // 2012 Nexus 7
Ben Wagner9539a8c2017-11-02 14:09:32 -0400230 "NexusPlayer": {"fugu", "OPR6.170623.021"},
Kevin Lubick832b2222017-09-26 14:07:38 -0400231 "Pixel": {"sailfish", "OPR3.170623.008"},
Kevin Lubickb018f7b2017-10-31 14:44:08 -0400232 "Pixel2XL": {"taimen", "OPD1.170816.023"},
Kevin Lubick674027a2017-10-31 09:47:38 -0400233 "PixelC": {"dragon", "OPR1.170623.034"},
Kevin Lubick832b2222017-09-26 14:07:38 -0400234 "PixelXL": {"marlin", "OPR3.170623.008"},
Ben Wagner36682782017-06-14 10:01:45 -0400235 }[parts["model"]]
Eric Boren27225492017-02-01 15:56:55 -0500236 if !ok {
Ben Wagner36682782017-06-14 10:01:45 -0400237 glog.Fatalf("Entry %q not found in Android mapping.", parts["model"])
Eric Boren27225492017-02-01 15:56:55 -0500238 }
Eric Boren4b254b92016-11-08 12:55:32 -0500239 d["device_type"] = deviceInfo[0]
240 d["device_os"] = deviceInfo[1]
Kevin Lubick4fd283e2017-12-07 11:19:31 -0500241 // TODO(kjlubick): Remove the python dimension after we have removed the
242 // Nexus5x devices from the local lab (on Monday, Dec 11, 2017 should be fine).
Kevin Lubick0f727ff2017-12-06 15:05:29 -0500243 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 -0500244 if parts["model"] == "Nexus5x" {
245 d["python"] = "2.7.12"
246 }
borenetdb182c72016-09-30 12:53:12 -0700247 } else if strings.Contains(parts["os"], "iOS") {
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400248 device, ok := map[string]string{
Eric Boren792079c2016-11-09 14:03:20 -0500249 "iPadMini4": "iPad5,1",
Stephan Altmueller63e843d2017-04-25 11:38:38 -0400250 "iPhone6": "iPhone7,2",
251 "iPhone7": "iPhone9,1",
252 "iPadPro": "iPad6,3",
borenetdb182c72016-09-30 12:53:12 -0700253 }[parts["model"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400254 if !ok {
255 glog.Fatalf("Entry %q not found in iOS mapping.", parts["model"])
256 }
257 d["device"] = device
borenetdb182c72016-09-30 12:53:12 -0700258 } else if parts["cpu_or_gpu"] == "CPU" {
Ben Wagner4c9842e2017-09-25 12:56:53 -0400259 modelMapping, ok := map[string]map[string]string{
260 "AVX": {
261 "MacMini7.1": "x86-64-E5-2697_v2",
262 "Golo": "x86-64-E5-2670",
263 },
264 "AVX2": {
Ben Wagner85fb42a2017-11-07 16:57:37 -0500265 "GCE": "x86-64-Haswell_GCE",
Mike Klein9a01a212017-11-03 12:19:54 -0400266 "NUC5i7RYH": "x86-64-i7-5557U",
Ben Wagner4c9842e2017-09-25 12:56:53 -0400267 },
Ben Wagnerb268d232017-09-28 16:38:34 -0400268 "AVX512": {
269 "GCE": "x86-64-Skylake_GCE",
270 },
borenetdb182c72016-09-30 12:53:12 -0700271 }[parts["cpu_or_gpu_value"]]
Ben Wagner3d2a2f72017-06-13 17:01:16 -0400272 if !ok {
273 glog.Fatalf("Entry %q not found in CPU mapping.", parts["cpu_or_gpu_value"])
274 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400275 cpu, ok := modelMapping[parts["model"]]
276 if !ok {
277 glog.Fatalf("Entry %q not found in %q model mapping.", parts["model"], parts["cpu_or_gpu_value"])
borenetdb182c72016-09-30 12:53:12 -0700278 }
Ben Wagner4c9842e2017-09-25 12:56:53 -0400279 d["cpu"] = cpu
Eric Boren170c39c2017-11-15 11:22:57 -0500280 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_DEBIAN {
281 d["os"] = DEFAULT_OS_LINUX_GCE
282 }
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500283 if parts["model"] == "GCE" && d["os"] == DEFAULT_OS_WIN {
Ben Wagner832415e2017-12-15 11:23:40 -0500284 // Use normal-size machines for Test and Perf tasks on Win GCE.
Ben Wagnerf53e6c92017-12-14 13:15:01 -0500285 d["machine_type"] = "n1-standard-16"
286 }
borenetdb182c72016-09-30 12:53:12 -0700287 } else {
Ben Wagner1d060782017-06-14 10:34:18 -0400288 if strings.Contains(parts["os"], "Win") {
289 gpu, ok := map[string]string{
Ben Wagner0d2b0912017-08-15 12:43:55 -0400290 "GT610": "10de:104a-22.21.13.8205",
Ben Wagner85fb42a2017-11-07 16:57:37 -0500291 "GTX1070": "10de:1ba1-23.21.13.8813",
292 "GTX660": "10de:11c0-23.21.13.8813",
293 "GTX960": "10de:1401-23.21.13.8813",
Ben Wagner1d060782017-06-14 10:34:18 -0400294 "IntelHD530": "8086:1912-21.20.16.4590",
Ben Wagner5698b002017-08-04 11:25:33 -0400295 "IntelHD4400": "8086:0a16-20.19.15.4703",
Ben Wagner3c286532017-08-11 10:35:57 -0400296 "IntelHD4600": "8086:0412-20.19.15.4703",
Ben Wagner1d060782017-06-14 10:34:18 -0400297 "IntelIris540": "8086:1926-21.20.16.4590",
Ben Wagner3c286532017-08-11 10:35:57 -0400298 "IntelIris6100": "8086:162b-20.19.15.4703",
Ben Wagner2040ed22017-11-22 11:22:22 -0500299 "RadeonHD7770": "1002:683d-22.19.165.512",
Ben Wagner1d060782017-06-14 10:34:18 -0400300 "RadeonR9M470X": "1002:6646-22.19.165.512",
Ben Wagnerae532f62017-08-02 23:24:16 -0400301 "QuadroP400": "10de:1cb3-22.21.13.8205",
Ben Wagner1d060782017-06-14 10:34:18 -0400302 }[parts["cpu_or_gpu_value"]]
303 if !ok {
304 glog.Fatalf("Entry %q not found in Win GPU mapping.", parts["cpu_or_gpu_value"])
305 }
306 d["gpu"] = gpu
Ben Wagner08435892017-02-18 23:28:26 -0500307
Ben Wagner4b1df022017-06-15 12:28:04 -0400308 // Specify cpu dimension for NUCs and ShuttleCs. We temporarily have two
309 // types of machines with a GTX960.
310 cpu, ok := map[string]string{
311 "NUC6i7KYK": "x86-64-i7-6770HQ",
312 "ShuttleC": "x86-64-i7-6700K",
Ben Wagner1d060782017-06-14 10:34:18 -0400313 }[parts["model"]]
314 if ok {
Ben Wagner4b1df022017-06-15 12:28:04 -0400315 d["cpu"] = cpu
Ben Wagner1d060782017-06-14 10:34:18 -0400316 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400317 } else if strings.Contains(parts["os"], "Ubuntu") || strings.Contains(parts["os"], "Debian") {
Ben Wagner1d060782017-06-14 10:34:18 -0400318 gpu, ok := map[string]string{
Ben Wagner1d060782017-06-14 10:34:18 -0400319 // Intel drivers come from CIPD, so no need to specify the version here.
320 "IntelBayTrail": "8086:0f31",
321 "IntelHD2000": "8086:0102",
322 "IntelHD405": "8086:22b1",
Ben Wagnerab10c822017-12-19 15:14:12 -0500323 "IntelIris640": "8086:5926",
Ben Wagnerc274ec42017-08-03 22:29:22 -0400324 "QuadroP400": "10de:1cb3-384.59",
Ben Wagner1d060782017-06-14 10:34:18 -0400325 }[parts["cpu_or_gpu_value"]]
326 if !ok {
327 glog.Fatalf("Entry %q not found in Ubuntu GPU mapping.", parts["cpu_or_gpu_value"])
328 }
329 d["gpu"] = gpu
330 } else if strings.Contains(parts["os"], "Mac") {
331 gpu, ok := map[string]string{
Ben Wagnercc4221b2017-08-17 17:29:04 -0400332 "IntelIris5100": "8086:0a2e",
Ben Wagner1d060782017-06-14 10:34:18 -0400333 }[parts["cpu_or_gpu_value"]]
334 if !ok {
335 glog.Fatalf("Entry %q not found in Mac GPU mapping.", parts["cpu_or_gpu_value"])
336 }
337 d["gpu"] = gpu
Ben Wagnere463d982018-01-03 16:15:33 -0500338 // TODO(benjaminwagner): Mac GPU bots haven't been upgraded.
339 d["os"] = "Mac-10.13.1"
Ben Wagner1d060782017-06-14 10:34:18 -0400340 } else if strings.Contains(parts["os"], "ChromeOS") {
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500341 version, ok := map[string]string{
342 "MaliT604": "9901.12.0",
343 "MaliT764": "10172.0.0",
344 "MaliT860": "10172.0.0",
Kevin Lubick0b1b9c22017-12-08 14:14:38 -0500345 "PowerVRGX6250": "10176.5.0",
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500346 "TegraK1": "10172.0.0",
347 "IntelHDGraphics615": "10032.17.0",
Ben Wagner1d060782017-06-14 10:34:18 -0400348 }[parts["cpu_or_gpu_value"]]
349 if !ok {
350 glog.Fatalf("Entry %q not found in ChromeOS GPU mapping.", parts["cpu_or_gpu_value"])
351 }
Kevin Lubick64ca6be2017-12-04 15:43:31 -0500352 d["gpu"] = parts["cpu_or_gpu_value"]
353 d["release_version"] = version
Ben Wagner1d060782017-06-14 10:34:18 -0400354 } else {
355 glog.Fatalf("Unknown GPU mapping for OS %q.", parts["os"])
Ben Wagner08435892017-02-18 23:28:26 -0500356 }
borenetdb182c72016-09-30 12:53:12 -0700357 }
358 } else {
359 d["gpu"] = "none"
Eric Borenbb198fb2017-06-28 11:45:54 -0400360 if d["os"] == DEFAULT_OS_DEBIAN {
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400361 return linuxGceDimensions()
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500362 } else if d["os"] == DEFAULT_OS_WIN {
363 // Windows CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400364 d["cpu"] = "x86-64-Haswell_GCE"
Ben Wagner832415e2017-12-15 11:23:40 -0500365 // Use many-core machines for Build tasks on Win GCE, except for Goma.
366 if strings.Contains(parts["extra_config"], "Goma") {
367 d["machine_type"] = "n1-standard-16"
368 } else {
369 d["machine_type"] = "n1-highcpu-64"
370 }
Ben Wagnerd3fdcc92017-11-14 13:30:04 -0500371 } else if d["os"] == DEFAULT_OS_MAC {
372 // Mac CPU bots.
Ben Wagnera78f1bc2017-09-26 18:19:56 -0400373 d["cpu"] = "x86-64-E5-2697_v2"
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400374 }
borenetdb182c72016-09-30 12:53:12 -0700375 }
Kevin Lubick4610a9b2017-03-22 15:54:54 -0400376
borenetdb182c72016-09-30 12:53:12 -0700377 rv := make([]string, 0, len(d))
378 for k, v := range d {
379 rv = append(rv, fmt.Sprintf("%s:%s", k, v))
380 }
381 sort.Strings(rv)
382 return rv
383}
384
Eric Boren7e3a3642017-06-14 15:25:31 -0400385// relpath returns the relative path to the given file from the config file.
386func relpath(f string) string {
387 _, filename, _, _ := runtime.Caller(0)
388 dir := path.Dir(filename)
389 rel := dir
390 if *cfgFile != "" {
391 rel = path.Dir(*cfgFile)
392 }
393 rv, err := filepath.Rel(rel, path.Join(dir, f))
394 if err != nil {
395 sklog.Fatal(err)
396 }
397 return rv
398}
399
Eric Boren8b3f9e62017-04-04 09:06:16 -0400400// bundleRecipes generates the task to bundle and isolate the recipes.
401func bundleRecipes(b *specs.TasksCfgBuilder) string {
402 b.MustAddTask(BUNDLE_RECIPES_NAME, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000403 CipdPackages: []*specs.CipdPackage{cipdGit1, cipdGit2},
404 Dimensions: linuxGceDimensions(),
405 ExtraArgs: []string{
406 "--workdir", "../../..", "bundle_recipes",
407 fmt.Sprintf("buildername=%s", BUNDLE_RECIPES_NAME),
408 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
Eric Boren8b3f9e62017-04-04 09:06:16 -0400409 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000410 Isolate: relpath("bundle_recipes.isolate"),
Kevin Lubick07072942017-05-11 13:35:23 -0400411 Priority: 0.7,
Eric Boren8b3f9e62017-04-04 09:06:16 -0400412 })
413 return BUNDLE_RECIPES_NAME
414}
415
Eric Boren23a6ec62017-04-07 08:31:22 -0400416// useBundledRecipes returns true iff the given bot should use bundled recipes
417// instead of syncing recipe DEPS itself.
418func useBundledRecipes(parts map[string]string) bool {
419 // Use bundled recipes for all test/perf tasks.
420 return true
421}
422
Kevin Lubick07072942017-05-11 13:35:23 -0400423type isolateAssetCfg struct {
Eric Boren9d78afd2017-12-07 14:54:05 +0000424 isolateFile string
425 cipdPkg string
Kevin Lubick07072942017-05-11 13:35:23 -0400426}
427
428var ISOLATE_ASSET_MAPPING = map[string]isolateAssetCfg{
429 ISOLATE_SKIMAGE_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000430 isolateFile: "isolate_skimage.isolate",
431 cipdPkg: "skimage",
Kevin Lubick07072942017-05-11 13:35:23 -0400432 },
433 ISOLATE_SKP_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000434 isolateFile: "isolate_skp.isolate",
435 cipdPkg: "skp",
Kevin Lubick07072942017-05-11 13:35:23 -0400436 },
437 ISOLATE_SVG_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000438 isolateFile: "isolate_svg.isolate",
439 cipdPkg: "svg",
Kevin Lubick07072942017-05-11 13:35:23 -0400440 },
Kevin Lubick814b1492017-11-29 14:45:14 -0500441 ISOLATE_NDK_LINUX_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000442 isolateFile: "isolate_ndk_linux.isolate",
443 cipdPkg: "android_ndk_linux",
Kevin Lubick814b1492017-11-29 14:45:14 -0500444 },
445 ISOLATE_WIN_TOOLCHAIN_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000446 isolateFile: "isolate_win_toolchain.isolate",
447 cipdPkg: "win_toolchain",
Kevin Lubick814b1492017-11-29 14:45:14 -0500448 },
449 ISOLATE_WIN_VULKAN_SDK_NAME: {
Eric Boren9d78afd2017-12-07 14:54:05 +0000450 isolateFile: "isolate_win_vulkan_sdk.isolate",
451 cipdPkg: "win_vulkan_sdk",
Kevin Lubick814b1492017-11-29 14:45:14 -0500452 },
Kevin Lubick07072942017-05-11 13:35:23 -0400453}
454
Eric Boren9d78afd2017-12-07 14:54:05 +0000455// bundleRecipes generates the task to bundle and isolate the recipes.
Kevin Lubick07072942017-05-11 13:35:23 -0400456func isolateCIPDAsset(b *specs.TasksCfgBuilder, name string) string {
457 b.MustAddTask(name, &specs.TaskSpec{
458 CipdPackages: []*specs.CipdPackage{
Eric Boren9d78afd2017-12-07 14:54:05 +0000459 b.MustGetCipdPackageFromAsset(ISOLATE_ASSET_MAPPING[name].cipdPkg),
Kevin Lubick07072942017-05-11 13:35:23 -0400460 },
461 Dimensions: linuxGceDimensions(),
Eric Boren9d78afd2017-12-07 14:54:05 +0000462 Isolate: relpath(ISOLATE_ASSET_MAPPING[name].isolateFile),
Kevin Lubick07072942017-05-11 13:35:23 -0400463 Priority: 0.7,
464 })
465 return name
466}
467
Kevin Lubick90189522017-05-15 08:30:27 -0400468// getIsolatedCIPDDeps returns the slice of Isolate_* tasks a given task needs.
469// This allows us to save time on I/O bound bots, like the RPIs.
470func getIsolatedCIPDDeps(parts map[string]string) []string {
471 deps := []string{}
Kevin Lubick07072942017-05-11 13:35:23 -0400472 // Only do this on the RPIs for now. Other, faster machines shouldn't see much
473 // benefit and we don't need the extra complexity, for now
Kevin Lubick90189522017-05-15 08:30:27 -0400474 rpiOS := []string{"Android", "ChromeOS", "iOS"}
475
476 if o := parts["os"]; strings.Contains(o, "Chromecast") {
477 // Chromecasts don't have enough disk space to fit all of the content,
478 // so we do a subset of the skps.
479 deps = append(deps, ISOLATE_SKP_NAME)
480 } else if e := parts["extra_config"]; strings.Contains(e, "Skpbench") {
481 // Skpbench only needs skps
482 deps = append(deps, ISOLATE_SKP_NAME)
483 } else if util.In(o, rpiOS) {
484 deps = append(deps, ISOLATE_SKP_NAME)
485 deps = append(deps, ISOLATE_SVG_NAME)
486 deps = append(deps, ISOLATE_SKIMAGE_NAME)
487 }
488
489 return deps
Kevin Lubick07072942017-05-11 13:35:23 -0400490}
491
borenetdb182c72016-09-30 12:53:12 -0700492// compile generates a compile task. Returns the name of the last task in the
493// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700494func compile(b *specs.TasksCfgBuilder, name string, parts map[string]string) string {
borenetdb182c72016-09-30 12:53:12 -0700495 // Collect the necessary CIPD packages.
496 pkgs := []*specs.CipdPackage{}
Eric Boren9d78afd2017-12-07 14:54:05 +0000497 deps := []string{}
borenetdb182c72016-09-30 12:53:12 -0700498
499 // Android bots require a toolchain.
500 if strings.Contains(name, "Android") {
borenetdb182c72016-09-30 12:53:12 -0700501 if strings.Contains(name, "Mac") {
boreneted20a702016-10-20 11:04:31 -0700502 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("android_ndk_darwin"))
Mike Klein86c2c0f2016-11-02 13:13:16 -0400503 } else if strings.Contains(name, "Win") {
Mike Kleine9215f02016-11-02 15:44:26 -0400504 pkg := b.MustGetCipdPackageFromAsset("android_ndk_windows")
505 pkg.Path = "n"
506 pkgs = append(pkgs, pkg)
borenetdb182c72016-09-30 12:53:12 -0700507 } else {
Kevin Lubick814b1492017-11-29 14:45:14 -0500508 deps = append(deps, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
borenetdb182c72016-09-30 12:53:12 -0700509 }
Kevin Lubickdcd2a902017-03-08 14:01:01 -0500510 } else if strings.Contains(name, "Chromecast") {
511 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("cast_toolchain"))
Kevin Lubickffce0792017-05-24 15:30:35 -0400512 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
Kevin Lubick261ea192017-04-05 07:32:45 -0400513 } else if strings.Contains(name, "Chromebook") {
514 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
Kevin Lubickb718fbb2017-11-02 09:34:08 -0400515 if parts["target_arch"] == "x86_64" {
516 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_x86_64_gles"))
517 } else if parts["target_arch"] == "arm" {
518 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("armhf_sysroot"))
519 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("chromebook_arm_gles"))
520 }
Eric Borenbb198fb2017-06-28 11:45:54 -0400521 } else if strings.Contains(name, "Debian") {
Kevin Lubick9c7dcac2017-01-18 09:24:56 -0500522 if strings.Contains(name, "Clang") {
523 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
524 }
525 if strings.Contains(name, "Vulkan") {
526 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
527 }
Kevin Lubickebf648e2017-09-21 13:45:16 -0400528 if strings.Contains(name, "EMCC") {
529 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("emscripten_sdk"))
530 }
Mike Klein27dcee12016-11-09 16:31:42 -0500531 } else if strings.Contains(name, "Win") {
Kevin Lubick814b1492017-11-29 14:45:14 -0500532 deps = append(deps, isolateCIPDAsset(b, ISOLATE_WIN_TOOLCHAIN_NAME))
Mike Klein8e3c42b2017-07-31 14:57:20 -0400533 if strings.Contains(name, "Clang") {
534 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_win"))
535 }
borenetdb182c72016-09-30 12:53:12 -0700536 if strings.Contains(name, "Vulkan") {
Kevin Lubick814b1492017-11-29 14:45:14 -0500537 deps = append(deps, isolateCIPDAsset(b, ISOLATE_WIN_VULKAN_SDK_NAME))
borenetdb182c72016-09-30 12:53:12 -0700538 }
539 }
540
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400541 dimensions := swarmDimensions(parts)
Stephan Altmueller5f3b9402017-03-20 13:38:45 -0400542
borenetdb182c72016-09-30 12:53:12 -0700543 // Add the task.
boreneted20a702016-10-20 11:04:31 -0700544 b.MustAddTask(name, &specs.TaskSpec{
borenetdb182c72016-09-30 12:53:12 -0700545 CipdPackages: pkgs,
Eric Boren9d78afd2017-12-07 14:54:05 +0000546 Dimensions: dimensions,
547 Dependencies: deps,
548 ExtraArgs: []string{
549 "--workdir", "../../..", "compile",
skia.buildbots2478c732016-11-04 14:37:26 -0400550 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700551 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700552 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
553 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400554 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700555 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400556 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
557 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700558 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000559 Isolate: relpath("compile_skia.isolate"),
560 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700561 })
Eric Boren8615fe52016-12-12 14:30:12 -0500562 // All compile tasks are runnable as their own Job. Assert that the Job
563 // is listed in JOBS.
564 if !util.In(name, JOBS) {
565 glog.Fatalf("Job %q is missing from the JOBS list!", name)
566 }
Ravi Mistry6f136222017-12-12 17:08:24 -0500567
568 // Upload the skiaserve binary only for Linux Android compile bots.
569 // See skbug.com/7399 for context.
570 if parts["configuration"] == "Release" &&
571 parts["extra_config"] == "Android" &&
572 !strings.Contains(parts["os"], "Win") &&
573 !strings.Contains(parts["os"], "Mac") {
574 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
575 b.MustAddTask(uploadName, &specs.TaskSpec{
576 Dependencies: []string{name},
577 Dimensions: linuxGceDimensions(),
578 ExtraArgs: []string{
579 "--workdir", "../../..", "upload_skiaserve",
580 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
581 fmt.Sprintf("buildername=%s", name),
582 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
583 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
584 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
585 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
586 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
587 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
588 },
589 // We're using the same isolate as upload_dm_results
590 Isolate: relpath("upload_dm_results.isolate"),
591 Priority: 0.8,
592 })
593 return uploadName
594 }
595
borenetdb182c72016-09-30 12:53:12 -0700596 return name
597}
598
599// recreateSKPs generates a RecreateSKPs task. Returns the name of the last
600// task in the generated chain of tasks, which the Job should add as a
601// dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000602func recreateSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500603 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000604 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
605 Dimensions: linuxGceDimensions(),
606 ExecutionTimeout: 4 * time.Hour,
607 ExtraArgs: []string{
608 "--workdir", "../../..", "recreate_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500609 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
610 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500611 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
612 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400613 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500614 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
615 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
616 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
617 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000618 IoTimeout: 40 * time.Minute,
619 Isolate: relpath("compile_skia.isolate"),
620 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500621 })
borenetdb182c72016-09-30 12:53:12 -0700622 return name
623}
624
Ravi Mistry01b48e72017-05-17 14:28:06 -0400625// updateMetaConfig generates a UpdateMetaConfig task. Returns the name of the
626// last task in the generated chain of tasks, which the Job should add as a
627// dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000628func updateMetaConfig(b *specs.TasksCfgBuilder, name string) string {
Ravi Mistry01b48e72017-05-17 14:28:06 -0400629 b.MustAddTask(name, &specs.TaskSpec{
Stephan Altmuellerddad85b2017-05-19 13:08:19 -0400630 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000631 Dimensions: linuxGceDimensions(),
632 ExtraArgs: []string{
633 "--workdir", "../../..", "update_meta_config",
Ravi Mistry01b48e72017-05-17 14:28:06 -0400634 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
635 fmt.Sprintf("buildername=%s", name),
636 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
637 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
638 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
639 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
640 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
641 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
642 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000643 Isolate: relpath("meta_config.isolate"),
644 Priority: 0.8,
Ravi Mistry01b48e72017-05-17 14:28:06 -0400645 })
646 return name
647}
648
borenetdb182c72016-09-30 12:53:12 -0700649// ctSKPs generates a CT SKPs task. Returns the name of the last task in the
650// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000651func ctSKPs(b *specs.TasksCfgBuilder, name string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500652 b.MustAddTask(name, &specs.TaskSpec{
Ben Wagner21c3fb92017-08-04 14:13:27 -0400653 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000654 Dimensions: []string{
655 "pool:SkiaCT",
656 fmt.Sprintf("os:%s", DEFAULT_OS_LINUX_GCE),
657 },
658 ExecutionTimeout: 24 * time.Hour,
659 ExtraArgs: []string{
660 "--workdir", "../../..", "ct_skps",
Eric Boren4b254b92016-11-08 12:55:32 -0500661 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
662 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500663 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
664 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400665 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500666 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
667 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
668 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
669 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000670 IoTimeout: time.Hour,
671 Isolate: relpath("ct_skps_skia.isolate"),
672 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500673 })
borenetdb182c72016-09-30 12:53:12 -0700674 return name
675}
676
Eric Borenf7928b42017-07-28 07:35:28 -0400677// checkGeneratedFiles verifies that no generated SKSL files have been edited
678// by hand.
Eric Boren9d78afd2017-12-07 14:54:05 +0000679func checkGeneratedFiles(b *specs.TasksCfgBuilder, name string) string {
Eric Borenf7928b42017-07-28 07:35:28 -0400680 b.MustAddTask(name, &specs.TaskSpec{
681 CipdPackages: []*specs.CipdPackage{},
Eric Boren9d78afd2017-12-07 14:54:05 +0000682 Dimensions: linuxGceDimensions(),
683 ExtraArgs: []string{
684 "--workdir", "../../..", "check_generated_files",
Eric Borenf7928b42017-07-28 07:35:28 -0400685 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
686 fmt.Sprintf("buildername=%s", name),
687 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
688 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
689 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
690 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
691 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
692 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
693 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000694 Isolate: relpath("compile_skia.isolate"),
695 Priority: 0.8,
Eric Borenf7928b42017-07-28 07:35:28 -0400696 })
697 return name
698}
699
borenetdb182c72016-09-30 12:53:12 -0700700// housekeeper generates a Housekeeper task. Returns the name of the last task
701// in the generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000702func housekeeper(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
Eric Boren4b254b92016-11-08 12:55:32 -0500703 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren22f5ef72016-12-02 11:01:33 -0500704 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
Eric Boren9d78afd2017-12-07 14:54:05 +0000705 Dependencies: []string{compileTaskName},
706 Dimensions: linuxGceDimensions(),
707 ExtraArgs: []string{
708 "--workdir", "../../..", "housekeeper",
Eric Boren4b254b92016-11-08 12:55:32 -0500709 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
710 fmt.Sprintf("buildername=%s", name),
Eric Boren4b254b92016-11-08 12:55:32 -0500711 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
712 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400713 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
Eric Boren4b254b92016-11-08 12:55:32 -0500714 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
715 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
716 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
717 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000718 Isolate: relpath("housekeeper_skia.isolate"),
719 Priority: 0.8,
Eric Boren4b254b92016-11-08 12:55:32 -0500720 })
borenetdb182c72016-09-30 12:53:12 -0700721 return name
722}
723
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500724// bookmaker generates a Bookmaker task. Returns the name of the last task
725// in the generated chain of tasks, which the Job should add as a dependency.
726func bookmaker(b *specs.TasksCfgBuilder, name, compileTaskName string) string {
727 b.MustAddTask(name, &specs.TaskSpec{
728 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
729 Dependencies: []string{compileTaskName},
730 Dimensions: linuxGceDimensions(),
731 ExtraArgs: []string{
732 "--workdir", "../../..", "bookmaker",
733 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
734 fmt.Sprintf("buildername=%s", name),
735 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
736 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
737 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
738 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
739 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
740 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
741 },
742 Isolate: relpath("compile_skia.isolate"),
743 Priority: 0.8,
744 ExecutionTimeout: 2 * time.Hour,
745 IoTimeout: 2 * time.Hour,
746 })
747 return name
748}
749
borenet2dbbfa52016-10-14 06:32:09 -0700750// infra generates an infra_tests task. Returns the name of the last task in the
751// generated chain of tasks, which the Job should add as a dependency.
Eric Boren9d78afd2017-12-07 14:54:05 +0000752func infra(b *specs.TasksCfgBuilder, name string) string {
boreneted20a702016-10-20 11:04:31 -0700753 b.MustAddTask(name, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000754 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("go")},
755 Dimensions: linuxGceDimensions(),
756 ExtraArgs: []string{
757 "--workdir", "../../..", "infra",
skia.buildbots2478c732016-11-04 14:37:26 -0400758 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700759 fmt.Sprintf("buildername=%s", name),
borenet2dbbfa52016-10-14 06:32:09 -0700760 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
761 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400762 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet2dbbfa52016-10-14 06:32:09 -0700763 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400764 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
765 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenet2dbbfa52016-10-14 06:32:09 -0700766 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000767 Isolate: relpath("infra_skia.isolate"),
768 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700769 })
borenet2dbbfa52016-10-14 06:32:09 -0700770 return name
771}
772
Yuqian Li4a577af2018-01-05 11:13:43 -0500773func getParentRevisionName(compileTaskName string, parts map[string]string) string {
774 if parts["extra_config"] == "" {
775 return compileTaskName + "-ParentRevision"
776 } else {
777 return compileTaskName + "_ParentRevision"
778 }
779}
780
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400781// calmbench generates a calmbench task. Returns the name of the last task in the
782// generated chain of tasks, which the Job should add as a dependency.
Yuqian Li4a577af2018-01-05 11:13:43 -0500783func calmbench(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, compileParentName string) string {
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400784 s := &specs.TaskSpec{
Yuqian Li4a577af2018-01-05 11:13:43 -0500785 Dependencies: []string{compileTaskName, compileParentName},
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400786 CipdPackages: []*specs.CipdPackage{b.MustGetCipdPackageFromAsset("clang_linux")},
Eric Boren9d78afd2017-12-07 14:54:05 +0000787 Dimensions: swarmDimensions(parts),
788 ExtraArgs: []string{
789 "--workdir", "../../..", "calmbench",
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400790 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
791 fmt.Sprintf("buildername=%s", name),
792 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
793 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
794 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
795 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
796 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
797 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
798 },
Yuqian Li4a577af2018-01-05 11:13:43 -0500799 Isolate: relpath("calmbench.isolate"),
Eric Boren9d78afd2017-12-07 14:54:05 +0000800 Priority: 0.8,
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400801 }
802
803 s.Dependencies = append(s.Dependencies, ISOLATE_SKP_NAME, ISOLATE_SVG_NAME)
804
805 b.MustAddTask(name, s)
806
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400807 // Upload results if necessary.
808 if strings.Contains(name, "Release") && doUpload(name) {
809 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
810 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000811 Dependencies: []string{name},
812 Dimensions: linuxGceDimensions(),
813 ExtraArgs: []string{
814 "--workdir", "../../..", "upload_calmbench_results",
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400815 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
816 fmt.Sprintf("buildername=%s", name),
817 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
818 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
819 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
820 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
821 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
822 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
823 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketCalm),
824 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000825 // We're using the same isolate as upload_nano_results
826 Isolate: relpath("upload_nano_results.isolate"),
827 Priority: 0.8,
Yuqian Li2ebf3d12017-10-24 09:43:21 -0400828 })
829 return uploadName
830 }
831
Yuqian Lic81aaaa2017-10-16 12:24:43 -0400832 return name
833}
834
borenetdb182c72016-09-30 12:53:12 -0700835// doUpload indicates whether the given Job should upload its results.
836func doUpload(name string) bool {
Eric Boren27225492017-02-01 15:56:55 -0500837 for _, s := range CONFIG.NoUpload {
838 m, err := regexp.MatchString(s, name)
839 if err != nil {
840 glog.Fatal(err)
841 }
842 if m {
borenetdb182c72016-09-30 12:53:12 -0700843 return false
844 }
845 }
846 return true
847}
848
849// test generates a Test task. Returns the name of the last task in the
850// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -0700851func test(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500852 deps := []string{compileTaskName}
853 if strings.Contains(name, "Android_ASAN") {
854 deps = append(deps, isolateCIPDAsset(b, ISOLATE_NDK_LINUX_NAME))
855 }
856
Eric Boren4b254b92016-11-08 12:55:32 -0500857 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000858 CipdPackages: pkgs,
Kevin Lubick4f0f9332018-01-12 14:31:48 -0500859 Dependencies: deps,
Eric Boren9d78afd2017-12-07 14:54:05 +0000860 Dimensions: swarmDimensions(parts),
861 ExecutionTimeout: 4 * time.Hour,
862 Expiration: 20 * time.Hour,
863 ExtraArgs: []string{
864 "--workdir", "../../..", "test",
skia.buildbots2478c732016-11-04 14:37:26 -0400865 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
Eric Boren9a9e3872017-11-29 12:33:22 -0500866 fmt.Sprintf("buildbucket_build_id=%s", specs.PLACEHOLDER_BUILDBUCKET_BUILD_ID),
borenetdb182c72016-09-30 12:53:12 -0700867 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700868 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
869 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400870 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700871 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400872 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
873 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -0700874 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000875 IoTimeout: 40 * time.Minute,
876 Isolate: relpath("test_skia.isolate"),
877 MaxAttempts: 1,
878 Priority: 0.8,
879 }
880 if useBundledRecipes(parts) {
881 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
882 if strings.Contains(parts["os"], "Win") {
883 s.Isolate = relpath("test_skia_bundled_win.isolate")
884 } else {
885 s.Isolate = relpath("test_skia_bundled_unix.isolate")
886 }
Eric Boren8b3f9e62017-04-04 09:06:16 -0400887 }
Kevin Lubick90189522017-05-15 08:30:27 -0400888 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
889 s.Dependencies = append(s.Dependencies, deps...)
Kevin Lubick07072942017-05-11 13:35:23 -0400890 }
Eric Boren4b254b92016-11-08 12:55:32 -0500891 if strings.Contains(parts["extra_config"], "Valgrind") {
892 s.ExecutionTimeout = 9 * time.Hour
893 s.Expiration = 48 * time.Hour
894 s.IoTimeout = time.Hour
Eric Borend696df72017-05-31 15:09:10 -0400895 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Kevin Lubickea613822017-12-04 10:20:23 -0500896 s.Dimensions = append(s.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -0500897 } else if strings.Contains(parts["extra_config"], "MSAN") {
898 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -0400899 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
900 // skia:6737
901 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -0500902 }
Eric Borenfd4d60e2017-09-15 10:35:44 -0400903 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -0400904 if iid != nil {
Eric Boren4dc4aaf2017-09-15 14:09:07 -0400905 s.ExtraArgs = append(s.ExtraArgs, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -0400906 }
Eric Boren4b254b92016-11-08 12:55:32 -0500907 b.MustAddTask(name, s)
908
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400909 // Upload results if necessary. TODO(kjlubick): If we do coverage analysis at the same
910 // time as normal tests (which would be nice), cfg.json needs to have Coverage removed.
borenetdb182c72016-09-30 12:53:12 -0700911 if doUpload(name) {
912 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -0700913 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000914 Dependencies: []string{name},
915 Dimensions: linuxGceDimensions(),
916 ExtraArgs: []string{
917 "--workdir", "../../..", "upload_dm_results",
skia.buildbots2478c732016-11-04 14:37:26 -0400918 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -0700919 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -0700920 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
921 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -0400922 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -0700923 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -0400924 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
925 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -0500926 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketGm),
borenetdb182c72016-09-30 12:53:12 -0700927 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000928 Isolate: relpath("upload_dm_results.isolate"),
929 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -0700930 })
borenetdb182c72016-09-30 12:53:12 -0700931 return uploadName
Kevin Lubick32f318b2017-10-17 13:40:52 -0400932 }
933
934 return name
935}
936
937func coverage(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
938 shards := 1
939 deps := []string{}
940
941 tf := parts["test_filter"]
942 if strings.Contains(tf, "Shard") {
943 // Expected Shard_NN
944 shardstr := strings.Split(tf, "_")[1]
945 var err error
946 shards, err = strconv.Atoi(shardstr)
947 if err != nil {
948 glog.Fatalf("Expected int for number of shards %q in %s: %s", shardstr, name, err)
949 }
950 }
951 for i := 0; i < shards; i++ {
952 n := strings.Replace(name, tf, fmt.Sprintf("shard_%02d_%02d", i, shards), 1)
953 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +0000954 CipdPackages: pkgs,
955 Dependencies: []string{compileTaskName},
956 Dimensions: swarmDimensions(parts),
957 ExecutionTimeout: 4 * time.Hour,
958 Expiration: 20 * time.Hour,
959 ExtraArgs: []string{
960 "--workdir", "../../..", "test",
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400961 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
Kevin Lubick32f318b2017-10-17 13:40:52 -0400962 fmt.Sprintf("buildername=%s", n),
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400963 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
964 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
965 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
966 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
967 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
968 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400969 },
Eric Boren9d78afd2017-12-07 14:54:05 +0000970 IoTimeout: 40 * time.Minute,
971 Isolate: relpath("test_skia.isolate"),
972 MaxAttempts: 1,
973 Priority: 0.8,
974 }
975 if useBundledRecipes(parts) {
976 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
977 if strings.Contains(parts["os"], "Win") {
978 s.Isolate = relpath("test_skia_bundled_win.isolate")
979 } else {
980 s.Isolate = relpath("test_skia_bundled_unix.isolate")
981 }
Kevin Lubick32f318b2017-10-17 13:40:52 -0400982 }
983 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
984 s.Dependencies = append(s.Dependencies, deps...)
985 }
986 b.MustAddTask(n, s)
987 deps = append(deps, n)
borenetdb182c72016-09-30 12:53:12 -0700988 }
Kevin Lubickc795a4c2017-10-09 15:26:19 -0400989
Kevin Lubick32f318b2017-10-17 13:40:52 -0400990 uploadName := fmt.Sprintf("%s%s%s", "Upload", jobNameSchema.Sep, name)
991 // We need clang_linux to get access to the llvm-profdata and llvm-cov binaries
992 // which are used to deal with the raw coverage data output by the Test step.
993 pkgs = append([]*specs.CipdPackage{}, b.MustGetCipdPackageFromAsset("clang_linux"))
994 deps = append(deps, compileTaskName)
995
996 b.MustAddTask(uploadName, &specs.TaskSpec{
997 // A dependency on compileTaskName makes the TaskScheduler link the
998 // isolated output of the compile step to the input of the upload step,
999 // which gives us access to the instrumented binary. The binary is
1000 // needed to figure out symbol names and line numbers.
1001 Dependencies: deps,
1002 Dimensions: linuxGceDimensions(),
1003 CipdPackages: pkgs,
Eric Boren9d78afd2017-12-07 14:54:05 +00001004 ExtraArgs: []string{
1005 "--workdir", "../../..", "upload_coverage_results",
Kevin Lubick32f318b2017-10-17 13:40:52 -04001006 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
1007 fmt.Sprintf("buildername=%s", name),
1008 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1009 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
1010 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
1011 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
1012 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1013 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
1014 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketCoverage),
1015 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001016 Isolate: relpath("upload_coverage_results.isolate"),
Kevin Lubick32f318b2017-10-17 13:40:52 -04001017 Priority: 0.8,
1018 })
1019 return uploadName
borenetdb182c72016-09-30 12:53:12 -07001020}
1021
1022// perf generates a Perf task. Returns the name of the last task in the
1023// generated chain of tasks, which the Job should add as a dependency.
boreneted20a702016-10-20 11:04:31 -07001024func perf(b *specs.TasksCfgBuilder, name string, parts map[string]string, compileTaskName string, pkgs []*specs.CipdPackage) string {
Eric Boren768f52f2017-04-10 08:14:33 -04001025 recipe := "perf"
Eric Boren9d78afd2017-12-07 14:54:05 +00001026 isolate := relpath("perf_skia.isolate")
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001027 if strings.Contains(parts["extra_config"], "Skpbench") {
Eric Boren768f52f2017-04-10 08:14:33 -04001028 recipe = "skpbench"
Eric Boren9d78afd2017-12-07 14:54:05 +00001029 isolate = relpath("skpbench_skia.isolate")
1030 if useBundledRecipes(parts) {
1031 if strings.Contains(parts["os"], "Win") {
1032 isolate = relpath("skpbench_skia_bundled_win.isolate")
1033 } else {
1034 isolate = relpath("skpbench_skia_bundled_unix.isolate")
1035 }
1036 }
1037 } else if useBundledRecipes(parts) {
1038 if strings.Contains(parts["os"], "Win") {
1039 isolate = relpath("perf_skia_bundled_win.isolate")
1040 } else {
1041 isolate = relpath("perf_skia_bundled_unix.isolate")
1042 }
Kevin Lubickb03b5ac2016-11-14 13:42:27 -05001043 }
Eric Boren4b254b92016-11-08 12:55:32 -05001044 s := &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +00001045 CipdPackages: pkgs,
1046 Dependencies: []string{compileTaskName},
1047 Dimensions: swarmDimensions(parts),
1048 ExecutionTimeout: 4 * time.Hour,
1049 Expiration: 20 * time.Hour,
1050 ExtraArgs: []string{
1051 "--workdir", "../../..", recipe,
skia.buildbots2478c732016-11-04 14:37:26 -04001052 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -07001053 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -07001054 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1055 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -04001056 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -07001057 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -04001058 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1059 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
borenetdb182c72016-09-30 12:53:12 -07001060 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001061 IoTimeout: 40 * time.Minute,
1062 Isolate: isolate,
1063 MaxAttempts: 1,
1064 Priority: 0.8,
1065 }
1066 if useBundledRecipes(parts) {
1067 s.Dependencies = append(s.Dependencies, BUNDLE_RECIPES_NAME)
Eric Boren8b3f9e62017-04-04 09:06:16 -04001068 }
Kevin Lubick90189522017-05-15 08:30:27 -04001069 if deps := getIsolatedCIPDDeps(parts); len(deps) > 0 {
1070 s.Dependencies = append(s.Dependencies, deps...)
1071 }
1072
Eric Boren4b254b92016-11-08 12:55:32 -05001073 if strings.Contains(parts["extra_config"], "Valgrind") {
1074 s.ExecutionTimeout = 9 * time.Hour
1075 s.Expiration = 48 * time.Hour
1076 s.IoTimeout = time.Hour
Eric Borenc5a073d2017-06-01 07:13:33 -04001077 s.CipdPackages = append(s.CipdPackages, b.MustGetCipdPackageFromAsset("valgrind"))
Kevin Lubickea613822017-12-04 10:20:23 -05001078 s.Dimensions = append(s.Dimensions, "valgrind:1")
Eric Boren4b254b92016-11-08 12:55:32 -05001079 } else if strings.Contains(parts["extra_config"], "MSAN") {
1080 s.ExecutionTimeout = 9 * time.Hour
Ben Wagnera6b2ba22017-06-08 10:34:17 -04001081 } else if parts["arch"] == "x86" && parts["configuration"] == "Debug" {
1082 // skia:6737
1083 s.ExecutionTimeout = 6 * time.Hour
Eric Boren4b254b92016-11-08 12:55:32 -05001084 }
Eric Borenfd4d60e2017-09-15 10:35:44 -04001085 iid := internalHardwareLabel(parts)
Eric Boren053d7a42017-09-15 08:35:31 -04001086 if iid != nil {
Eric Boren4dc4aaf2017-09-15 14:09:07 -04001087 s.ExtraArgs = append(s.ExtraArgs, fmt.Sprintf("internal_hardware_label=%d", *iid))
Eric Boren053d7a42017-09-15 08:35:31 -04001088 }
Eric Boren4b254b92016-11-08 12:55:32 -05001089 b.MustAddTask(name, s)
1090
borenetdb182c72016-09-30 12:53:12 -07001091 // Upload results if necessary.
1092 if strings.Contains(name, "Release") && doUpload(name) {
1093 uploadName := fmt.Sprintf("%s%s%s", PREFIX_UPLOAD, jobNameSchema.Sep, name)
boreneted20a702016-10-20 11:04:31 -07001094 b.MustAddTask(uploadName, &specs.TaskSpec{
Eric Boren9d78afd2017-12-07 14:54:05 +00001095 Dependencies: []string{name},
1096 Dimensions: linuxGceDimensions(),
1097 ExtraArgs: []string{
1098 "--workdir", "../../..", "upload_nano_results",
skia.buildbots2478c732016-11-04 14:37:26 -04001099 fmt.Sprintf("repository=%s", specs.PLACEHOLDER_REPO),
borenetdb182c72016-09-30 12:53:12 -07001100 fmt.Sprintf("buildername=%s", name),
borenetdb182c72016-09-30 12:53:12 -07001101 fmt.Sprintf("swarm_out_dir=%s", specs.PLACEHOLDER_ISOLATED_OUTDIR),
1102 fmt.Sprintf("revision=%s", specs.PLACEHOLDER_REVISION),
Eric Boren09419502017-04-21 09:37:37 -04001103 fmt.Sprintf("patch_repo=%s", specs.PLACEHOLDER_PATCH_REPO),
borenet98b2e7a2016-10-13 06:23:45 -07001104 fmt.Sprintf("patch_storage=%s", specs.PLACEHOLDER_PATCH_STORAGE),
skia.buildbots2478c732016-11-04 14:37:26 -04001105 fmt.Sprintf("patch_issue=%s", specs.PLACEHOLDER_ISSUE),
1106 fmt.Sprintf("patch_set=%s", specs.PLACEHOLDER_PATCHSET),
Eric Boren965861b2017-02-06 15:38:41 -05001107 fmt.Sprintf("gs_bucket=%s", CONFIG.GsBucketNano),
borenetdb182c72016-09-30 12:53:12 -07001108 },
Eric Boren9d78afd2017-12-07 14:54:05 +00001109 Isolate: relpath("upload_nano_results.isolate"),
1110 Priority: 0.8,
boreneted20a702016-10-20 11:04:31 -07001111 })
borenetdb182c72016-09-30 12:53:12 -07001112 return uploadName
1113 }
1114 return name
1115}
1116
1117// process generates tasks and jobs for the given job name.
boreneted20a702016-10-20 11:04:31 -07001118func process(b *specs.TasksCfgBuilder, name string) {
borenetdb182c72016-09-30 12:53:12 -07001119 deps := []string{}
1120
Eric Boren8b3f9e62017-04-04 09:06:16 -04001121 // Bundle Recipes.
1122 if name == BUNDLE_RECIPES_NAME {
1123 deps = append(deps, bundleRecipes(b))
1124 }
1125
Kevin Lubick07072942017-05-11 13:35:23 -04001126 // Isolate CIPD assets.
Kevin Lubick07072942017-05-11 13:35:23 -04001127 if _, ok := ISOLATE_ASSET_MAPPING[name]; ok {
1128 deps = append(deps, isolateCIPDAsset(b, name))
1129 }
1130
borenetdb182c72016-09-30 12:53:12 -07001131 parts, err := jobNameSchema.ParseJobName(name)
1132 if err != nil {
1133 glog.Fatal(err)
1134 }
1135
1136 // RecreateSKPs.
1137 if strings.Contains(name, "RecreateSKPs") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001138 deps = append(deps, recreateSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001139 }
1140
Ravi Mistry01b48e72017-05-17 14:28:06 -04001141 // UpdateMetaConfig bot.
1142 if strings.Contains(name, "UpdateMetaConfig") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001143 deps = append(deps, updateMetaConfig(b, name))
Ravi Mistry01b48e72017-05-17 14:28:06 -04001144 }
1145
borenetdb182c72016-09-30 12:53:12 -07001146 // CT bots.
1147 if strings.Contains(name, "-CT_") {
Eric Boren9d78afd2017-12-07 14:54:05 +00001148 deps = append(deps, ctSKPs(b, name))
borenetdb182c72016-09-30 12:53:12 -07001149 }
1150
borenet2dbbfa52016-10-14 06:32:09 -07001151 // Infra tests.
1152 if name == "Housekeeper-PerCommit-InfraTests" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001153 deps = append(deps, infra(b, name))
borenet2dbbfa52016-10-14 06:32:09 -07001154 }
1155
borenetdb182c72016-09-30 12:53:12 -07001156 // Compile bots.
1157 if parts["role"] == "Build" {
boreneted20a702016-10-20 11:04:31 -07001158 deps = append(deps, compile(b, name, parts))
borenetdb182c72016-09-30 12:53:12 -07001159 }
1160
Eric Borenf5a90e82016-11-15 15:18:20 -05001161 // Most remaining bots need a compile task.
borenetdb182c72016-09-30 12:53:12 -07001162 compileTaskName := deriveCompileTaskName(name, parts)
borenet52383432016-10-17 10:17:53 -07001163 compileTaskParts, err := jobNameSchema.ParseJobName(compileTaskName)
1164 if err != nil {
1165 glog.Fatal(err)
1166 }
Yuqian Li4a577af2018-01-05 11:13:43 -05001167 compileParentName := getParentRevisionName(compileTaskName, compileTaskParts)
1168 compileParentParts, err := jobNameSchema.ParseJobName(compileParentName)
1169 if err != nil {
1170 glog.Fatal(err)
1171 }
1172
Eric Boren628e78b2016-11-17 11:33:27 -05001173 // These bots do not need a compile task.
Yuqian Li4a577af2018-01-05 11:13:43 -05001174 if parts["role"] != "Build" &&
Eric Borenb8ab7f72017-04-10 11:00:09 -04001175 name != "Housekeeper-PerCommit-BundleRecipes" &&
Eric Borenf5a90e82016-11-15 15:18:20 -05001176 name != "Housekeeper-PerCommit-InfraTests" &&
Eric Borenf7928b42017-07-28 07:35:28 -04001177 name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
Eric Boren71b762f2016-11-30 14:05:16 -05001178 !strings.Contains(name, "RecreateSKPs") &&
Ravi Mistry01b48e72017-05-17 14:28:06 -04001179 !strings.Contains(name, "UpdateMetaConfig") &&
Ben Wagner50b84682017-06-12 13:03:29 -04001180 !strings.Contains(name, "-CT_") &&
1181 !strings.Contains(name, "Housekeeper-PerCommit-Isolate") {
boreneted20a702016-10-20 11:04:31 -07001182 compile(b, compileTaskName, compileTaskParts)
Ben Wagner4c39c0d2018-01-10 11:14:52 -05001183 if parts["role"] == "Calmbench" {
Yuqian Li4a577af2018-01-05 11:13:43 -05001184 compile(b, compileParentName, compileParentParts)
1185 }
borenet52383432016-10-17 10:17:53 -07001186 }
borenetdb182c72016-09-30 12:53:12 -07001187
Eric Borenf7928b42017-07-28 07:35:28 -04001188 // Housekeepers.
Eric Boren22f5ef72016-12-02 11:01:33 -05001189 if name == "Housekeeper-PerCommit" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001190 deps = append(deps, housekeeper(b, name, compileTaskName))
borenetdb182c72016-09-30 12:53:12 -07001191 }
Eric Borenf7928b42017-07-28 07:35:28 -04001192 if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
Eric Boren9d78afd2017-12-07 14:54:05 +00001193 deps = append(deps, checkGeneratedFiles(b, name))
Eric Borenf7928b42017-07-28 07:35:28 -04001194 }
Ravi Mistryd4731e92018-01-02 14:54:43 -05001195 if strings.Contains(name, "Bookmaker") {
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001196 deps = append(deps, bookmaker(b, name, compileTaskName))
1197 }
borenetdb182c72016-09-30 12:53:12 -07001198
1199 // Common assets needed by the remaining bots.
Kevin Lubick07072942017-05-11 13:35:23 -04001200
1201 pkgs := []*specs.CipdPackage{}
1202
Kevin Lubick90189522017-05-15 08:30:27 -04001203 if deps := getIsolatedCIPDDeps(parts); len(deps) == 0 {
Kevin Lubick07072942017-05-11 13:35:23 -04001204 pkgs = []*specs.CipdPackage{
1205 b.MustGetCipdPackageFromAsset("skimage"),
1206 b.MustGetCipdPackageFromAsset("skp"),
1207 b.MustGetCipdPackageFromAsset("svg"),
1208 }
borenetdb182c72016-09-30 12:53:12 -07001209 }
Kevin Lubick90189522017-05-15 08:30:27 -04001210
Ben Wagner5655ba42017-10-02 10:48:32 -04001211 if strings.Contains(name, "Ubuntu") || strings.Contains(name, "Debian") {
1212 if strings.Contains(name, "SAN") {
1213 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("clang_linux"))
1214 }
Kevin Lubick35115eb2017-02-17 10:25:34 -05001215 if strings.Contains(name, "Vulkan") {
1216 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
1217 }
Ben Wagner5655ba42017-10-02 10:48:32 -04001218 if strings.Contains(name, "Intel") && strings.Contains(name, "GPU") {
1219 if strings.Contains(name, "Release") {
1220 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_release"))
1221 } else {
1222 pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_intel_driver_debug"))
1223 }
Kevin Lubick0a51b482017-02-06 12:45:29 -05001224 }
1225 }
borenetdb182c72016-09-30 12:53:12 -07001226
1227 // Test bots.
Kevin Lubick32f318b2017-10-17 13:40:52 -04001228
1229 if parts["role"] == "Test" {
1230 if strings.Contains(parts["extra_config"], "Coverage") {
1231 deps = append(deps, coverage(b, name, parts, compileTaskName, pkgs))
1232 } else if !strings.Contains(name, "-CT_") {
1233 deps = append(deps, test(b, name, parts, compileTaskName, pkgs))
1234 }
1235
borenetdb182c72016-09-30 12:53:12 -07001236 }
1237
1238 // Perf bots.
Eric Boren71b762f2016-11-30 14:05:16 -05001239 if parts["role"] == "Perf" && !strings.Contains(name, "-CT_") {
boreneted20a702016-10-20 11:04:31 -07001240 deps = append(deps, perf(b, name, parts, compileTaskName, pkgs))
borenetdb182c72016-09-30 12:53:12 -07001241 }
1242
Yuqian Li4a577af2018-01-05 11:13:43 -05001243 // Calmbench bots.
1244 if parts["role"] == "Calmbench" {
1245 deps = append(deps, calmbench(b, name, parts, compileTaskName, compileParentName))
1246 }
1247
borenetdb182c72016-09-30 12:53:12 -07001248 // Add the Job spec.
Eric Borenf5a90e82016-11-15 15:18:20 -05001249 j := &specs.JobSpec{
borenetdb182c72016-09-30 12:53:12 -07001250 Priority: 0.8,
1251 TaskSpecs: deps,
Eric Borenba937a42017-07-31 10:41:15 -04001252 Trigger: specs.TRIGGER_ANY_BRANCH,
Eric Borenf5a90e82016-11-15 15:18:20 -05001253 }
Eric Borenba937a42017-07-31 10:41:15 -04001254 if strings.Contains(name, "-Nightly-") {
1255 j.Trigger = specs.TRIGGER_NIGHTLY
Ravi Mistryf06dae82017-10-16 10:31:41 -04001256 } else if strings.Contains(name, "-Weekly-") || strings.Contains(name, "CT_DM_1m_SKPs") {
Eric Borenba937a42017-07-31 10:41:15 -04001257 j.Trigger = specs.TRIGGER_WEEKLY
1258 } else if strings.Contains(name, "Flutter") || strings.Contains(name, "PDFium") || strings.Contains(name, "CommandBuffer") {
1259 j.Trigger = specs.TRIGGER_MASTER_ONLY
Eric Boren71b762f2016-11-30 14:05:16 -05001260 }
Eric Boren8615fe52016-12-12 14:30:12 -05001261 b.MustAddJob(name, j)
borenetdb182c72016-09-30 12:53:12 -07001262}
1263
Eric Boren27225492017-02-01 15:56:55 -05001264func loadJson(flag *string, defaultFlag string, val interface{}) {
1265 if *flag == "" {
1266 *flag = defaultFlag
1267 }
1268 b, err := ioutil.ReadFile(*flag)
1269 if err != nil {
1270 glog.Fatal(err)
1271 }
1272 if err := json.Unmarshal(b, val); err != nil {
1273 glog.Fatal(err)
1274 }
1275}
1276
borenetdb182c72016-09-30 12:53:12 -07001277// Regenerate the tasks.json file.
1278func main() {
boreneted20a702016-10-20 11:04:31 -07001279 b := specs.MustNewTasksCfgBuilder()
Eric Boren27225492017-02-01 15:56:55 -05001280 b.SetAssetsDir(*assetsDir)
1281 infraBots := path.Join(b.CheckoutRoot(), "infra", "bots")
1282
1283 // Load the jobs from a JSON file.
1284 loadJson(jobsFile, path.Join(infraBots, "jobs.json"), &JOBS)
1285
Eric Boren27225492017-02-01 15:56:55 -05001286 // Load general config information from a JSON file.
1287 loadJson(cfgFile, path.Join(infraBots, "cfg.json"), &CONFIG)
1288
borenetdb182c72016-09-30 12:53:12 -07001289 // Create the JobNameSchema.
Eric Boren1f8be682017-02-07 09:16:30 -05001290 if *builderNameSchemaFile == "" {
1291 *builderNameSchemaFile = path.Join(b.CheckoutRoot(), "infra", "bots", "recipe_modules", "builder_name_schema", "builder_name_schema.json")
1292 }
1293 schema, err := NewJobNameSchema(*builderNameSchemaFile)
borenetdb182c72016-09-30 12:53:12 -07001294 if err != nil {
1295 glog.Fatal(err)
1296 }
1297 jobNameSchema = schema
1298
borenetdb182c72016-09-30 12:53:12 -07001299 // Create Tasks and Jobs.
boreneted20a702016-10-20 11:04:31 -07001300 for _, name := range JOBS {
1301 process(b, name)
borenetdb182c72016-09-30 12:53:12 -07001302 }
1303
boreneted20a702016-10-20 11:04:31 -07001304 b.MustFinish()
borenetdb182c72016-09-30 12:53:12 -07001305}
1306
1307// TODO(borenet): The below really belongs in its own file, probably next to the
1308// builder_name_schema.json file.
1309
1310// JobNameSchema is a struct used for (de)constructing Job names in a
1311// predictable format.
1312type JobNameSchema struct {
1313 Schema map[string][]string `json:"builder_name_schema"`
1314 Sep string `json:"builder_name_sep"`
1315}
1316
1317// NewJobNameSchema returns a JobNameSchema instance based on the given JSON
1318// file.
1319func NewJobNameSchema(jsonFile string) (*JobNameSchema, error) {
1320 var rv JobNameSchema
1321 f, err := os.Open(jsonFile)
1322 if err != nil {
1323 return nil, err
1324 }
1325 defer util.Close(f)
1326 if err := json.NewDecoder(f).Decode(&rv); err != nil {
1327 return nil, err
1328 }
1329 return &rv, nil
1330}
1331
1332// ParseJobName splits the given Job name into its component parts, according
1333// to the schema.
1334func (s *JobNameSchema) ParseJobName(n string) (map[string]string, error) {
1335 split := strings.Split(n, s.Sep)
1336 if len(split) < 2 {
1337 return nil, fmt.Errorf("Invalid job name: %q", n)
1338 }
1339 role := split[0]
1340 split = split[1:]
1341 keys, ok := s.Schema[role]
1342 if !ok {
1343 return nil, fmt.Errorf("Invalid job name; %q is not a valid role.", role)
1344 }
1345 extraConfig := ""
1346 if len(split) == len(keys)+1 {
1347 extraConfig = split[len(split)-1]
1348 split = split[:len(split)-1]
1349 }
1350 if len(split) != len(keys) {
1351 return nil, fmt.Errorf("Invalid job name; %q has incorrect number of parts.", n)
1352 }
1353 rv := make(map[string]string, len(keys)+2)
1354 rv["role"] = role
1355 if extraConfig != "" {
1356 rv["extra_config"] = extraConfig
1357 }
1358 for i, k := range keys {
1359 rv[k] = split[i]
1360 }
1361 return rv, nil
1362}
1363
1364// MakeJobName assembles the given parts of a Job name, according to the schema.
1365func (s *JobNameSchema) MakeJobName(parts map[string]string) (string, error) {
1366 role, ok := parts["role"]
1367 if !ok {
1368 return "", fmt.Errorf("Invalid job parts; jobs must have a role.")
1369 }
1370 keys, ok := s.Schema[role]
1371 if !ok {
1372 return "", fmt.Errorf("Invalid job parts; unknown role %q", role)
1373 }
1374 rvParts := make([]string, 0, len(parts))
1375 rvParts = append(rvParts, role)
1376 for _, k := range keys {
1377 v, ok := parts[k]
1378 if !ok {
1379 return "", fmt.Errorf("Invalid job parts; missing %q", k)
1380 }
1381 rvParts = append(rvParts, v)
1382 }
1383 if _, ok := parts["extra_config"]; ok {
1384 rvParts = append(rvParts, parts["extra_config"])
1385 }
1386 return strings.Join(rvParts, s.Sep), nil
1387}