Skip to content

Commit c7cb9a5

Browse files
authored
Merge pull request #186 from vito/remastered
remaster: a reckoning of weird ideas while adding gRPC runtimes
2 parents 16f74a0 + 95e7c26 commit c7cb9a5

135 files changed

Lines changed: 7849 additions & 1485 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pkg/runtimes/bin/exe.%: pkg/runtimes/shim/main.go
1414
cmd/bass/bass: shims
1515
env GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(VERSION)" -o ./cmd/bass/bass ./cmd/bass
1616

17+
pkg/proto/%.pb.go: proto/%.proto
18+
protoc -I=./proto --go_out=. --go-grpc_out=. proto/$*.proto
19+
1720
nix/vendorSha256.txt: go.mod go.sum
1821
./hack/get-nix-vendorsha > $@
1922

@@ -26,6 +29,9 @@ install: cmd/bass/bass
2629
mkdir -p $(DESTDIR)
2730
cp $< $(DESTDIR)
2831

32+
.PHONY: proto
33+
proto: pkg/proto/bass.pb.go pkg/proto/runtime.pb.go pkg/proto/progress.pb.go pkg/proto/memo.pb.go
34+
2935
.PHONY: clean
3036
clean:
3137
rm -f cmd/bass/bass $(shims)

bass/bass.bass

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
; load dependencies
66
(use (.git (linux/alpine/git))
7-
(git:github/vito/tabs/ref/main/nix))
7+
(git:github/vito/tabs/ref/main/nix.bass))
88

99
; clones the repo and checks out the given sha
1010
(defn checkout [sha]
@@ -152,7 +152,7 @@
152152
(undo-wordwrap src (src/notes/ notes)))))
153153

154154
(provide [release]
155-
(use (git:github/vito/tabs/ref/main/gh))
155+
(use (git:github/vito/tabs/ref/main/gh.bass))
156156

157157
; returns the github release module
158158
(defn release [token]

bass/bass.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ memos: {
332332
}
333333
output: {
334334
string: {
335-
value: "66938767c1fa545039225b4a06d7edc4a67a46cf"
335+
value: "d2b84a954119fa7506192aa5c0a9be7fa291500a"
336336
}
337337
}
338338
}

bass/checks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bass
22

33
(use (.git (linux/alpine/git))
4-
(*dir*/bass)
5-
(*dir*/github))
4+
(*dir*/bass.bass)
5+
(*dir*/github.bass))
66

77
; a github client that uses commit statuses for checks
88
(defn status-client [repo]

bass/github.bass

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bass
22

33
(provide [start-status]
4-
(def *memos* *dir*/memos.json)
4+
(def *memos* *dir*/bass.lock)
55

66
; starts the thunk and reflects its status as a Commit Status
77
(defn start-status [thunk name sha repo auth]

bass/shipit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
; load libraries
44
(use (.strings)
5-
(*dir*/bass))
5+
(*dir*/bass.bass))
66

77
; builds and publishes a GitHub release
88
;

bass/test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env bass
22

3+
(use (*dir*/bass.bass))
4+
35
; runs tests against src passed on *stdin*
46
;
57
; Emits code coverage to *stdout*.
68
(defn main testflags
79
(for [{:src src} *stdin*]
8-
(use (src/project))
9-
(let [tests (project:tests src ["./..." & testflags])]
10+
(let [tests (bass:tests src ["./..." & testflags])]
1011
(log "running tests")
1112
(run tests)
1213
(emit {:coverage tests/cover.html} *stdout*))))

cmd/bass/bump.go

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package main
22

33
import (
44
"context"
5-
"fmt"
65
"os"
7-
"strings"
86

97
"github.com/vito/bass/pkg/bass"
8+
"github.com/vito/bass/pkg/proto"
109
"github.com/vito/progrock"
10+
"google.golang.org/protobuf/encoding/prototext"
1111
)
1212

1313
func bump(ctx context.Context) error {
@@ -17,63 +17,59 @@ func bump(ctx context.Context) error {
1717
return err
1818
}
1919

20-
var lf bass.LockfileContent
21-
err = bass.UnmarshalJSON(lockContent, &lf)
20+
content := &proto.Memosphere{}
21+
err = prototext.Unmarshal(lockContent, content)
2222
if err != nil {
2323
return err
2424
}
2525

26-
for thunkFn, pairs := range lf.Data {
27-
segs := strings.SplitN(thunkFn, ":", 2)
28-
if len(segs) != 2 {
29-
return fmt.Errorf("malformed bass.lock key: %q", thunkFn)
30-
}
31-
32-
thunkID := segs[0]
33-
fn := bass.Symbol(segs[1])
34-
thunk := lf.Thunks[thunkID]
35-
36-
runtime, err := bass.RuntimeFromContext(ctx, nil)
26+
for _, memo := range content.Memos {
27+
thunk := bass.Thunk{}
28+
err := thunk.UnmarshalProto(memo.Module)
3729
if err != nil {
3830
return err
3931
}
4032

41-
scope, err := runtime.Load(ctx, thunk)
33+
scope, err := bass.Bass.Load(ctx, thunk)
4234
if err != nil {
4335
return err
4436
}
4537

46-
var comb bass.Combiner
47-
err = scope.GetDecode(fn, &comb)
48-
if err != nil {
49-
return err
50-
}
38+
for _, call := range memo.Calls {
39+
binding := bass.Symbol(call.Binding)
5140

52-
for i, pair := range pairs {
53-
res, err := bass.Trampoline(ctx, comb.Call(ctx, pair.Input.Value, bass.NewEmptyScope(), bass.Identity))
41+
var comb bass.Combiner
42+
err = scope.GetDecode(binding, &comb)
5443
if err != nil {
5544
return err
5645
}
5746

58-
// update reference inline
59-
pairs[i].Output.Value = res
60-
}
61-
}
47+
for _, res := range call.Results {
48+
input, err := bass.FromProto(res.Input)
49+
if err != nil {
50+
return err
51+
}
6252

63-
lockFile, err := os.Create(bumpLock)
64-
if err != nil {
65-
return err
66-
}
53+
out, err := bass.Trampoline(ctx, comb.Call(ctx, input, bass.NewEmptyScope(), bass.Identity))
54+
if err != nil {
55+
return err
56+
}
57+
58+
output, err := bass.MarshalProto(out)
59+
if err != nil {
60+
return err
61+
}
6762

68-
defer lockFile.Close()
63+
res.Output = output
64+
}
65+
}
66+
}
6967

70-
enc := bass.NewEncoder(lockFile)
71-
enc.SetIndent("", " ")
72-
err = enc.Encode(lf)
68+
payload, err := prototext.MarshalOptions{Multiline: true}.Marshal(content)
7369
if err != nil {
7470
return err
7571
}
7672

77-
return nil
73+
return os.WriteFile(bumpLock, payload, 0644)
7874
})
7975
}

cmd/bass/export.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"archive/tar"
55
"context"
6+
"encoding/json"
67
"fmt"
78
"io"
89
"os"
@@ -17,20 +18,25 @@ import (
1718

1819
func export(ctx context.Context) error {
1920
return withProgress(ctx, "export", func(ctx context.Context, vertex *progrock.VertexRecorder) error {
20-
dec := bass.NewDecoder(os.Stdin)
21+
dec := bass.NewRawDecoder(os.Stdin)
2122

22-
var val bass.Value
23-
err := dec.Decode(&val)
23+
var msg json.RawMessage
24+
err := dec.Decode(&msg)
2425
if err != nil {
2526
return err
2627
}
2728

2829
var errs error
2930

3031
var path bass.ThunkPath
31-
err = val.Decode(&path)
32+
err = json.Unmarshal([]byte(msg), &path)
3233
if err == nil {
33-
runtime, err := bass.RuntimeFromContext(ctx, path.Thunk.Platform())
34+
platform := path.Thunk.Platform()
35+
if platform == nil {
36+
return fmt.Errorf("cannot export bass thunk path: %s", path)
37+
}
38+
39+
runtime, err := bass.RuntimeFromContext(ctx, *platform)
3440
if err != nil {
3541
return err
3642
}
@@ -43,9 +49,14 @@ func export(ctx context.Context) error {
4349
}
4450

4551
var thunk bass.Thunk
46-
err = val.Decode(&thunk)
52+
err = json.Unmarshal([]byte(msg), &path)
4753
if err == nil {
48-
runtime, err := bass.RuntimeFromContext(ctx, thunk.Platform())
54+
platform := path.Thunk.Platform()
55+
if platform == nil {
56+
return fmt.Errorf("cannot export bass thunk: %s", thunk)
57+
}
58+
59+
runtime, err := bass.RuntimeFromContext(ctx, *platform)
4960
if err != nil {
5061
return err
5162
}

cmd/bass/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func root(ctx context.Context) error {
140140
ctx = bass.WithRuntimePool(ctx, pool)
141141

142142
if runnerAddr != "" {
143-
return runnerLoop(ctx, runnerAddr, config.Runtimes)
143+
return runnerLoop(ctx, runnerAddr, pool.Runtimes)
144144
}
145145

146146
if runExport {

0 commit comments

Comments
 (0)