| 1 |
// Copyright 2020 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 |
package gen_tasks_logic |
| 5 |
|
| 6 |
import ( |
| 7 |
"log" |
| 8 |
"strings" |
| 9 |
|
| 10 |
"go.skia.org/infra/task_scheduler/go/specs" |
| 11 |
) |
| 12 |
|
| 13 |
// jobBuilder provides helpers for creating a job. |
| 14 |
type jobBuilder struct { |
| 15 |
*builder |
| 16 |
Parts |
| 17 |
Name string |
| 18 |
Spec *specs.JobSpec |
| 19 |
} |
| 20 |
|
| 21 |
// newJobBuilder returns a jobBuilder for the given job name. |
| 22 |
func newJobBuilder(b *builder, name string) *jobBuilder { |
| 23 |
p, err := b.jobNameSchema.ParseJobName(name) |
| 24 |
if err != nil { |
| 25 |
log.Fatal(err) |
| 26 |
} |
| 27 |
return &jobBuilder{ |
| 28 |
builder: b, |
| 29 |
Parts: p, |
| 30 |
Name: name, |
| 31 |
Spec: &specs.JobSpec{}, |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// priority sets the priority of the job. |
| 36 |
func (b *jobBuilder) priority(p float64) { |
| 37 |
b.Spec.Priority = p |
| 38 |
} |
| 39 |
|
| 40 |
// trigger dictates when the job should be triggered. |
| 41 |
func (b *jobBuilder) trigger(trigger string) { |
| 42 |
b.Spec.Trigger = trigger |
| 43 |
} |
| 44 |
|
| 45 |
// Create a taskBuilder and run the given function for it. |
| 46 |
func (b *jobBuilder) addTask(name string, fn func(*TaskBuilder)) { |
| 47 |
tb := newTaskBuilder(b, name) |
| 48 |
fn(tb) |
| 49 |
if b.cfg.AddTaskCallback != nil { |
| 50 |
b.cfg.AddTaskCallback(tb) |
| 51 |
} |
| 52 |
b.MustAddTask(tb.Name, tb.Spec) |
| 53 |
// Add the task to the Job's dependency set, removing any which are |
| 54 |
// accounted for by the new task's dependencies. |
| 55 |
b.Spec.TaskSpecs = append(b.Spec.TaskSpecs, tb.Name) |
| 56 |
newSpecs := make([]string, 0, len(b.Spec.TaskSpecs)) |
| 57 |
for _, t := range b.Spec.TaskSpecs { |
| 58 |
if !In(t, tb.Spec.Dependencies) { |
| 59 |
newSpecs = append(newSpecs, t) |
| 60 |
} |
| 61 |
} |
| 62 |
b.Spec.TaskSpecs = newSpecs |
| 63 |
} |
| 64 |
|
| 65 |
// uploadCIPDAssetToCAS generates a task to isolate the given CIPD asset. Returns |
| 66 |
// the name of the task. |
| 67 |
func (b *jobBuilder) uploadCIPDAssetToCAS(asset string) string { |
| 68 |
cfg, ok := ISOLATE_ASSET_MAPPING[asset] |
| 69 |
if !ok { |
| 70 |
log.Fatalf("No isolate task for asset %q", asset) |
| 71 |
} |
| 72 |
b.addTask(cfg.uploadTaskName, func(b *TaskBuilder) { |
| 73 |
b.cipd(b.MustGetCipdPackageFromAsset(asset)) |
| 74 |
b.cmd("/bin/cp", "-rL", cfg.path, "${ISOLATED_OUTDIR}") |
| 75 |
b.linuxGceDimensions(MACHINE_TYPE_SMALL) |
| 76 |
b.idempotent() |
| 77 |
b.cas(CAS_EMPTY) |
| 78 |
}) |
| 79 |
return cfg.uploadTaskName |
| 80 |
} |
| 81 |
|
| 82 |
// genTasksForJob generates the tasks needed by this job. |
| 83 |
func (b *jobBuilder) genTasksForJob() { |
| 84 |
// Bundle Recipes. |
| 85 |
if b.Name == BUNDLE_RECIPES_NAME { |
| 86 |
b.bundleRecipes() |
| 87 |
return |
| 88 |
} |
| 89 |
if strings.HasPrefix(b.Name, BUILD_TASK_DRIVERS_PREFIX) { |
| 90 |
parts := strings.Split(b.Name, "_") |
| 91 |
b.buildTaskDrivers(parts[1], parts[2]) |
| 92 |
return |
| 93 |
} |
| 94 |
|
| 95 |
// Isolate CIPD assets. |
| 96 |
if b.MatchExtraConfig("Isolate") { |
| 97 |
for asset, cfg := range ISOLATE_ASSET_MAPPING { |
| 98 |
if cfg.uploadTaskName == b.Name { |
| 99 |
b.uploadCIPDAssetToCAS(asset) |
| 100 |
return |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
// RecreateSKPs. |
| 106 |
if b.ExtraConfig("RecreateSKPs") { |
| 107 |
b.recreateSKPs() |
| 108 |
return |
| 109 |
} |
| 110 |
|
| 111 |
// Infra tests. |
| 112 |
if b.ExtraConfig("InfraTests") { |
| 113 |
b.infra() |
| 114 |
return |
| 115 |
} |
| 116 |
|
| 117 |
// Housekeepers. |
| 118 |
if b.Name == "Housekeeper-PerCommit" { |
| 119 |
b.housekeeper() |
| 120 |
return |
| 121 |
} |
| 122 |
if b.Name == "Housekeeper-PerCommit-CheckGeneratedFiles" { |
| 123 |
b.checkGeneratedFiles() |
| 124 |
return |
| 125 |
} |
| 126 |
if b.Name == "Housekeeper-PerCommit-GoLinters" { |
| 127 |
b.goLinters() |
| 128 |
return |
| 129 |
} |
| 130 |
if b.Name == "Housekeeper-PerCommit-RunGnToBp" { |
| 131 |
b.checkGnToBp() |
| 132 |
return |
| 133 |
} |
| 134 |
if b.Name == "Housekeeper-OnDemand-Presubmit" { |
| 135 |
b.priority(1) |
| 136 |
b.presubmit() |
| 137 |
return |
| 138 |
} |
| 139 |
|
| 140 |
// Compile bots. |
| 141 |
if b.Role("Build") { |
| 142 |
b.compile() |
| 143 |
return |
| 144 |
} |
| 145 |
|
| 146 |
// BuildStats bots. This computes things like binary size. |
| 147 |
if b.Role("BuildStats") { |
| 148 |
b.buildstats() |
| 149 |
return |
| 150 |
} |
| 151 |
|
| 152 |
if b.Role("CodeSize") { |
| 153 |
b.codesize() |
| 154 |
return |
| 155 |
} |
| 156 |
|
| 157 |
// Test bots. |
| 158 |
if b.Role("Test") { |
| 159 |
if b.ExtraConfig("WasmGMTests") { |
| 160 |
b.runWasmGMTests() |
| 161 |
return |
| 162 |
} |
| 163 |
b.dm() |
| 164 |
return |
| 165 |
} |
| 166 |
|
| 167 |
// Canary bots. |
| 168 |
if b.Role("Canary") { |
| 169 |
if b.Project("G3") { |
| 170 |
b.g3FrameworkCanary() |
| 171 |
return |
| 172 |
} else if b.Project("Android") { |
| 173 |
b.canary("android-master-autoroll", "Canary-Android-Topic", "https://googleplex-android-review.googlesource.com/q/topic:") |
| 174 |
return |
| 175 |
} else if b.Project("Chromium") { |
| 176 |
b.canary("skia-autoroll", "Canary-Chromium-CL", "https://chromium-review.googlesource.com/c/") |
| 177 |
return |
| 178 |
} else if b.Project("Flutter") { |
| 179 |
b.canary("skia-flutter-autoroll", "Canary-Flutter-PR", "https://github.com/flutter/engine/pull/") |
| 180 |
return |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
if b.ExtraConfig("Puppeteer") { |
| 185 |
// TODO(kjlubick) make this a new role |
| 186 |
b.puppeteer() |
| 187 |
return |
| 188 |
} |
| 189 |
|
| 190 |
// Perf bots. |
| 191 |
if b.Role("Perf") { |
| 192 |
b.perf() |
| 193 |
return |
| 194 |
} |
| 195 |
|
| 196 |
if b.Role("BazelBuild") { |
| 197 |
b.bazelBuild() |
| 198 |
return |
| 199 |
} |
| 200 |
|
| 201 |
if b.Role("BazelTest") { |
| 202 |
b.bazelTest() |
| 203 |
return |
| 204 |
} |
| 205 |
|
| 206 |
log.Fatalf("Don't know how to handle job %q", b.Name) |
| 207 |
} |
| 208 |
|
| 209 |
func (b *jobBuilder) finish() { |
| 210 |
// Add the Job spec. |
| 211 |
if b.Frequency("Nightly") { |
| 212 |
b.trigger(specs.TRIGGER_NIGHTLY) |
| 213 |
} else if b.Frequency("Weekly") { |
| 214 |
b.trigger(specs.TRIGGER_WEEKLY) |
| 215 |
} else if b.ExtraConfig("Flutter", "PushBazelAppsFromWASMDockerImage") { |
| 216 |
b.trigger(specs.TRIGGER_MAIN_ONLY) |
| 217 |
} else if b.Frequency("OnDemand") || b.Role("Canary") { |
| 218 |
b.trigger(specs.TRIGGER_ON_DEMAND) |
| 219 |
} else { |
| 220 |
b.trigger(specs.TRIGGER_ANY_BRANCH) |
| 221 |
} |
| 222 |
b.MustAddJob(b.Name, b.Spec) |
| 223 |
} |