-
Notifications
You must be signed in to change notification settings - Fork 288
/
local_resource.go
83 lines (71 loc) · 2.04 KB
/
local_resource.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
package tiltfile
import (
"fmt"
"path/filepath"
"github.com/pkg/errors"
"go.starlark.net/starlark"
"github.com/windmilleng/tilt/internal/tiltfile/starkit"
"github.com/windmilleng/tilt/internal/tiltfile/value"
"github.com/windmilleng/tilt/pkg/model"
)
type localResource struct {
name string
cmd model.Cmd
workdir string
deps []string
triggerMode triggerMode
autoInit bool
repos []model.LocalGitRepo
resourceDeps []string
ignores []string
}
func (s *tiltfileState) localResource(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var name, cmd string
var triggerMode triggerMode
var deps starlark.Value
var resourceDepsVal starlark.Sequence
var ignoresVal starlark.Value
autoInit := true
if err := s.unpackArgs(fn.Name(), args, kwargs,
"name", &name,
"cmd", &cmd,
"deps?", &deps,
"trigger_mode?", &triggerMode,
"resource_deps?", &resourceDepsVal,
"ignore?", &ignoresVal,
"auto_init?", &autoInit,
); err != nil {
return nil, err
}
depsVals := starlarkValueOrSequenceToSlice(deps)
var depsStrings []string
for _, v := range depsVals {
path, err := value.ValueToAbsPath(thread, v)
if err != nil {
return nil, fmt.Errorf("deps must be a string or a sequence of strings; found a %T", v)
}
depsStrings = append(depsStrings, path)
}
repos := reposForPaths(depsStrings)
resourceDeps, err := value.SequenceToStringSlice(resourceDepsVal)
if err != nil {
return nil, errors.Wrapf(err, "%s: resource_deps", fn.Name())
}
ignores, err := parseValuesToStrings(ignoresVal, "ignore")
if err != nil {
return nil, err
}
res := localResource{
name: name,
cmd: model.ToShellCmd(cmd),
workdir: filepath.Dir(starkit.CurrentExecPath(thread)),
deps: depsStrings,
triggerMode: triggerMode,
autoInit: autoInit,
repos: repos,
resourceDeps: resourceDeps,
ignores: ignores,
}
s.localResources = append(s.localResources, res)
return starlark.None, nil
}