-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl_builtins.go
94 lines (84 loc) · 2.36 KB
/
repl_builtins.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
package main
import (
"fmt"
"github.com/pgavlin/dawn"
"github.com/pgavlin/dawn/label"
"github.com/pgavlin/dawn/util"
"go.starlark.net/starlark"
)
func getLabel(thread *starlark.Thread, fn *starlark.Builtin, labelOrTarget starlark.Value) (*label.Label, error) {
switch labelOrTarget := labelOrTarget.(type) {
case starlark.String:
l, err := label.Parse(string(labelOrTarget))
if err != nil {
return nil, err
}
m, ok := dawn.CurrentModule(thread)
if !ok && !l.IsAbs() {
return nil, fmt.Errorf("%v: no current module; label %v must be absolute", fn.Name(), l)
}
return l.RelativeTo(m.Package)
case dawn.Target:
return labelOrTarget.Label(), nil
default:
return nil, fmt.Errorf("%v: label_or_target must be a string or a target", fn.Name())
}
}
// def depends(label_or_target):
// """
// Returns the transitive closure of targets depended on by the given
// target.
//
// :param label_or_target: the label or target in question.
// :returns: the target's transitive dependency closure.
// :rtype: List[str]
// """
//
//starlark:builtin
func (w *workspace) builtin_depends(thread *starlark.Thread, fn *starlark.Builtin, labelOrTarget starlark.Value) (_ starlark.Value, err error) {
label, err := getLabel(thread, fn, labelOrTarget)
if err != nil {
return nil, err
}
list, err := w.depends(label)
if err != nil {
return nil, err
}
return util.StringList(list).List(), nil
}
// def what_depends(label_or_target):
// """
// Returns the transitive closure of target that depend on the given target.
//
// :param label_or_target: the label or target in question.
// :returns: the target's transitive dependent closure.
// :rtype: List[str]
// """
//
//starlark:builtin
func (w *workspace) builtin_whatDepends(thread *starlark.Thread, fn *starlark.Builtin, labelOrTarget starlark.Value) (_ starlark.Value, err error) {
label, err := getLabel(thread, fn, labelOrTarget)
if err != nil {
return nil, err
}
list, err := w.whatDepends(label)
if err != nil {
return nil, err
}
return util.StringList(list).List(), nil
}
// def cli():
// """
// CLI-only builtin functions.
// """
//
// @function("*workspace.builtin_depends")
// def depends():
// pass
//
// @function("*workspace.builtin_whatDepends")
// def what_depends():
// pass
//
//starlark:module
type cliModule int