-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildcontext.go
37 lines (33 loc) · 1.06 KB
/
buildcontext.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
package ir
type (
// A Blueprint application can potentially have multiple IR node instances spread across the application
// that generate the same code.
//
// Visit tracker is a utility method used during artifact generation to prevent nodes from unnecessarily
// generating the same artifact repeatedly, when once will suffice.
VisitTracker interface {
// Returns false on the first invocation of name; true on subsequent invocations
Visited(name string) bool
}
// All artifact generation occurs in the context of some BuildContext.
//
// Plugins that control the artifact generation process should implement this interface.
BuildContext interface {
VisitTracker
ImplementsBuildContext()
}
)
// Basic implementation of the [VisitTracker] interface
type VisitTrackerImpl struct {
visited map[string]any
}
func (tracker *VisitTrackerImpl) Visited(name string) bool {
if tracker.visited == nil {
tracker.visited = make(map[string]any)
}
_, has_visited := tracker.visited[name]
if !has_visited {
tracker.visited[name] = nil
}
return has_visited
}