-
Notifications
You must be signed in to change notification settings - Fork 298
/
build_reason.go
109 lines (89 loc) · 2.57 KB
/
build_reason.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package model
import "strings"
type BuildReason int
const BuildReasonNone = BuildReason(0)
const (
BuildReasonFlagChangedFiles BuildReason = 1 << iota
BuildReasonFlagConfig
// See comments on NeedsRebuildFromCrash
BuildReasonFlagCrash
BuildReasonFlagInit
BuildReasonFlagTriggerWeb
BuildReasonFlagTriggerCLI
BuildReasonFlagTriggerUnknown
// An external process called `tilt args`
BuildReasonFlagTiltfileArgs
// Suppose you have
// manifestA with imageA depending on imageCommon
// manifestB with imageB depending on imageCommon
//
// Building manifestA will mark imageB
// with changed dependencies.
BuildReasonFlagChangedDeps
)
func (r BuildReason) With(flag BuildReason) BuildReason {
return r | flag
}
func (r BuildReason) Has(flag BuildReason) bool {
return r&flag == flag
}
func (r BuildReason) HasTrigger() bool {
for _, v := range triggerBuildReasons {
if r.Has(v) {
return true
}
}
return false
}
func (r BuildReason) IsCrashOnly() bool {
return r == BuildReasonFlagCrash
}
var translations = map[BuildReason]string{
BuildReasonFlagChangedFiles: "Changed Files",
BuildReasonFlagConfig: "Config Changed",
BuildReasonFlagCrash: "Pod Crashed, Lost live_update Changes",
BuildReasonFlagInit: "Initial Build",
BuildReasonFlagTriggerWeb: "Web Trigger",
BuildReasonFlagTriggerCLI: "CLI Trigger",
BuildReasonFlagTriggerUnknown: "Unknown Trigger",
BuildReasonFlagTiltfileArgs: "Tilt Args",
BuildReasonFlagChangedDeps: "Dependency Updated",
}
var triggerBuildReasons = []BuildReason{
BuildReasonFlagTriggerWeb,
BuildReasonFlagTriggerCLI,
BuildReasonFlagTriggerUnknown,
}
var allBuildReasons = []BuildReason{
BuildReasonFlagInit,
BuildReasonFlagChangedFiles,
BuildReasonFlagConfig,
BuildReasonFlagCrash,
BuildReasonFlagTriggerWeb,
BuildReasonFlagTriggerCLI,
BuildReasonFlagChangedDeps,
BuildReasonFlagTriggerUnknown,
BuildReasonFlagTiltfileArgs,
}
func (r BuildReason) String() string {
rs := []string{}
// The trigger build reasons should never be used in conjunction with another
// build reason, because it was explicitly specified by the user rather than implicit.
for _, v := range triggerBuildReasons {
if r.Has(v) {
return translations[v]
}
}
// The Init build reason should be listed alone too.
if r.Has(BuildReasonFlagInit) {
return translations[BuildReasonFlagInit]
}
// Use an array to iterate over the translations to ensure the iteration order
// is consistent.
for _, v := range allBuildReasons {
if r.Has(v) {
rs = append(rs, translations[v])
}
}
return strings.Join(rs, " | ")
}