-
Notifications
You must be signed in to change notification settings - Fork 298
/
include.go
67 lines (56 loc) · 1.75 KB
/
include.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
package tiltfile
import (
"fmt"
"path/filepath"
"go.starlark.net/starlark"
)
type loadCacheEntry struct {
status loadStatus
exports starlark.StringDict
err error
}
type loadStatus int
const (
loadStatusNone loadStatus = iota
loadStatusExecuting
loadStatusDone
)
// Tiltfiles support both load() and include().
//
// The main difference is that include() doesn't bind any arguments into the
// global scope, whereas load() forces you to bind at least one argument into the global
// scope (i.e., you can't load() a Tilfile for its side-effects).
func (s *tiltfileState) include(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var p string
err := s.unpackArgs(fn.Name(), args, kwargs, "path", &p)
if err != nil {
return nil, err
}
_, err = s.exec(s.absPath(thread, p))
return starlark.None, err
}
func (s *tiltfileState) exec(tiltfilePath string) (starlark.StringDict, error) {
if !filepath.IsAbs(tiltfilePath) {
return starlark.StringDict{}, fmt.Errorf("internal error: tiltfilePath must be absolute")
}
entry := s.loadCache[tiltfilePath]
status := entry.status
if status == loadStatusExecuting {
return starlark.StringDict{}, fmt.Errorf("Circular tiltfile load: %s", tiltfilePath)
} else if status == loadStatusDone {
return entry.exports, entry.err
}
s.loadCache[tiltfilePath] = loadCacheEntry{
status: loadStatusExecuting,
}
s.configFiles = append(s.configFiles, tiltfilePath, tiltIgnorePath(tiltfilePath))
newT := s.starlarkThread()
newT.Name = tiltfilePath
exports, err := starlark.ExecFile(newT, tiltfilePath, nil, s.predeclared())
s.loadCache[tiltfilePath] = loadCacheEntry{
status: loadStatusDone,
exports: exports,
err: err,
}
return exports, err
}