Skip to content

Commit 0e321ad

Browse files
committed
Adjust types to use Google's protobuf code generator
The code generator is less customizable and doesn't allow custom types. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 19a108d commit 0e321ad

31 files changed

+242
-139
lines changed

cache/contenthash/checksum_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ func parseChange(str string) *change {
12691269
st.Linkname = f[3][1:]
12701270
} else {
12711271
c.data = f[3]
1272-
st.Size_ = int64(len(f[3]))
1272+
st.Size = int64(len(f[3]))
12731273
}
12741274
}
12751275
st.Mode |= 0644

cache/contenthash/filehash.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) {
2424

2525
stat := &fstypes.Stat{
2626
Mode: uint32(fi.Mode()),
27-
Size_: fi.Size(),
27+
Size: fi.Size(),
2828
ModTime: fi.ModTime().UnixNano(),
2929
Linkname: link,
3030
}
@@ -86,7 +86,7 @@ func (s *statInfo) Name() string {
8686
return filepath.Base(s.Stat.Path)
8787
}
8888
func (s *statInfo) Size() int64 {
89-
return s.Stat.Size_
89+
return s.Stat.Size
9090
}
9191
func (s *statInfo) Mode() os.FileMode {
9292
return os.FileMode(s.Stat.Mode)

client/diskusage.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,21 @@ func (c *Client) DiskUsage(ctx context.Context, opts ...DiskUsageOption) ([]*Usa
3939
var du []*UsageInfo
4040

4141
for _, d := range resp.Record {
42+
var lastUsedAt *time.Time
43+
if d.LastUsedAt != nil {
44+
t := d.LastUsedAt.AsTime()
45+
lastUsedAt = &t
46+
}
4247
du = append(du, &UsageInfo{
4348
ID: d.ID,
4449
Mutable: d.Mutable,
4550
InUse: d.InUse,
46-
Size: d.Size_,
51+
Size: d.Size,
4752
Parents: d.Parents,
48-
CreatedAt: d.CreatedAt,
53+
CreatedAt: d.CreatedAt.AsTime(),
4954
Description: d.Description,
5055
UsageCount: int(d.UsageCount),
51-
LastUsedAt: d.LastUsedAt,
56+
LastUsedAt: lastUsedAt,
5257
RecordType: UsageRecordType(d.RecordType),
5358
Shared: d.Shared,
5459
})

client/llb/definition.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"sync"
66

77
"github.com/moby/buildkit/solver/pb"
8+
"github.com/moby/buildkit/util"
89
digest "github.com/opencontainers/go-digest"
910
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1011
"github.com/pkg/errors"
12+
"google.golang.org/protobuf/proto"
1113
)
1214

1315
// DefinitionOp implements llb.Vertex using a marshalled definition.
@@ -40,7 +42,7 @@ func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
4042
var dgst digest.Digest
4143
for _, dt := range def.Def {
4244
var op pb.Op
43-
if err := (&op).Unmarshal(dt); err != nil {
45+
if err := proto.Unmarshal(dt, &op); err != nil {
4446
return nil, errors.Wrap(err, "failed to parse llb proto op")
4547
}
4648
dgst = digest.FromBytes(dt)
@@ -89,14 +91,14 @@ func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
8991

9092
var index pb.OutputIndex
9193
if dgst != "" {
92-
index = ops[dgst].Inputs[0].Index
93-
dgst = ops[dgst].Inputs[0].Digest
94+
index = pb.OutputIndex(ops[dgst].Inputs[0].Index)
95+
dgst = digest.Digest(ops[dgst].Inputs[0].Digest)
9496
}
9597

9698
return &DefinitionOp{
9799
ops: ops,
98100
defs: defs,
99-
metas: def.Metadata,
101+
metas: util.FromPointerMap[digest.Digest](def.Metadata),
100102
sources: srcs,
101103
platforms: platforms,
102104
dgst: dgst,
@@ -207,7 +209,10 @@ func (d *DefinitionOp) Inputs() []Output {
207209
for _, input := range op.Inputs {
208210
var vtx *DefinitionOp
209211
d.mu.Lock()
210-
if existingIndexes, ok := d.loadInputCache(input.Digest); ok {
212+
213+
dgst := digest.Digest(input.Digest)
214+
215+
if existingIndexes, ok := d.loadInputCache(dgst); ok {
211216
if int(input.Index) < len(existingIndexes) && existingIndexes[input.Index] != nil {
212217
vtx = existingIndexes[input.Index]
213218
}
@@ -218,19 +223,19 @@ func (d *DefinitionOp) Inputs() []Output {
218223
defs: d.defs,
219224
metas: d.metas,
220225
platforms: d.platforms,
221-
dgst: input.Digest,
222-
index: input.Index,
226+
dgst: dgst,
227+
index: pb.OutputIndex(input.Index),
223228
inputCache: d.inputCache,
224229
sources: d.sources,
225230
}
226-
existingIndexes, _ := d.loadInputCache(input.Digest)
231+
existingIndexes, _ := d.loadInputCache(dgst)
227232
indexDiff := int(input.Index) - len(existingIndexes)
228233
if indexDiff >= 0 {
229234
// make room in the slice for the new index being set
230235
existingIndexes = append(existingIndexes, make([]*DefinitionOp, indexDiff+1)...)
231236
}
232237
existingIndexes[input.Index] = vtx
233-
d.storeInputCache(input.Digest, existingIndexes)
238+
d.storeInputCache(dgst, existingIndexes)
234239
}
235240
d.mu.Unlock()
236241

client/prune.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
controlapi "github.com/moby/buildkit/api/services/control"
9+
"github.com/moby/buildkit/util"
910
"github.com/pkg/errors"
1011
)
1112

@@ -41,12 +42,12 @@ func (c *Client) Prune(ctx context.Context, ch chan UsageInfo, opts ...PruneOpti
4142
ID: d.ID,
4243
Mutable: d.Mutable,
4344
InUse: d.InUse,
44-
Size: d.Size_,
45+
Size: d.Size,
4546
Parents: d.Parents,
46-
CreatedAt: d.CreatedAt,
47+
CreatedAt: d.CreatedAt.AsTime(),
4748
Description: d.Description,
4849
UsageCount: int(d.UsageCount),
49-
LastUsedAt: d.LastUsedAt,
50+
LastUsedAt: util.ToTimeOrNil(d.LastUsedAt),
5051
RecordType: UsageRecordType(d.RecordType),
5152
Shared: d.Shared,
5253
}

client/solve.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/moby/buildkit/session/grpchijack"
2424
"github.com/moby/buildkit/solver/pb"
2525
spb "github.com/moby/buildkit/sourcepolicy/pb"
26+
"github.com/moby/buildkit/util"
2627
"github.com/moby/buildkit/util/bklog"
2728
"github.com/moby/buildkit/util/entitlements"
2829
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
@@ -269,8 +270,8 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG
269270
Frontend: opt.Frontend,
270271
FrontendAttrs: frontendAttrs,
271272
FrontendInputs: frontendInputs,
272-
Cache: cacheOpt.options,
273-
Entitlements: opt.AllowedEntitlements,
273+
Cache: &cacheOpt.options,
274+
Entitlements: util.ToStringSlice(opt.AllowedEntitlements),
274275
Internal: opt.Internal,
275276
SourcePolicy: opt.SourcePolicy,
276277
})

client/status.go

+27-23
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@ package client
22

33
import (
44
controlapi "github.com/moby/buildkit/api/services/control"
5+
"github.com/moby/buildkit/util"
6+
digest "github.com/opencontainers/go-digest"
7+
"google.golang.org/protobuf/proto"
8+
"google.golang.org/protobuf/types/known/timestamppb"
59
)
610

711
var emptyLogVertexSize int
812

913
func init() {
1014
emptyLogVertex := controlapi.VertexLog{}
11-
emptyLogVertexSize = emptyLogVertex.Size()
15+
emptyLogVertexSize = proto.Size(&emptyLogVertex)
1216
}
1317

1418
func NewSolveStatus(resp *controlapi.StatusResponse) *SolveStatus {
1519
s := &SolveStatus{}
1620
for _, v := range resp.Vertexes {
1721
s.Vertexes = append(s.Vertexes, &Vertex{
18-
Digest: v.Digest,
19-
Inputs: v.Inputs,
22+
Digest: digest.Digest(v.Digest),
23+
Inputs: util.FromStringSlice[digest.Digest](v.Inputs),
2024
Name: v.Name,
21-
Started: v.Started,
22-
Completed: v.Completed,
25+
Started: util.ToTimeOrNil(v.Started),
26+
Completed: util.ToTimeOrNil(v.Completed),
2327
Error: v.Error,
2428
Cached: v.Cached,
2529
ProgressGroup: v.ProgressGroup,
@@ -28,26 +32,26 @@ func NewSolveStatus(resp *controlapi.StatusResponse) *SolveStatus {
2832
for _, v := range resp.Statuses {
2933
s.Statuses = append(s.Statuses, &VertexStatus{
3034
ID: v.ID,
31-
Vertex: v.Vertex,
35+
Vertex: digest.Digest(v.Vertex),
3236
Name: v.Name,
3337
Total: v.Total,
3438
Current: v.Current,
35-
Timestamp: v.Timestamp,
36-
Started: v.Started,
37-
Completed: v.Completed,
39+
Timestamp: v.Timestamp.AsTime(),
40+
Started: util.ToTimeOrNil(v.Started),
41+
Completed: util.ToTimeOrNil(v.Completed),
3842
})
3943
}
4044
for _, v := range resp.Logs {
4145
s.Logs = append(s.Logs, &VertexLog{
42-
Vertex: v.Vertex,
46+
Vertex: digest.Digest(v.Vertex),
4347
Stream: int(v.Stream),
4448
Data: v.Msg,
45-
Timestamp: v.Timestamp,
49+
Timestamp: v.Timestamp.AsTime(),
4650
})
4751
}
4852
for _, v := range resp.Warnings {
4953
s.Warnings = append(s.Warnings, &VertexWarning{
50-
Vertex: v.Vertex,
54+
Vertex: digest.Digest(v.Vertex),
5155
Level: int(v.Level),
5256
Short: v.Short,
5357
Detail: v.Detail,
@@ -66,11 +70,11 @@ func (ss *SolveStatus) Marshal() (out []*controlapi.StatusResponse) {
6670
sr := controlapi.StatusResponse{}
6771
for _, v := range ss.Vertexes {
6872
sr.Vertexes = append(sr.Vertexes, &controlapi.Vertex{
69-
Digest: v.Digest,
70-
Inputs: v.Inputs,
73+
Digest: v.Digest.String(),
74+
Inputs: util.ToStringSlice(v.Inputs),
7175
Name: v.Name,
72-
Started: v.Started,
73-
Completed: v.Completed,
76+
Started: util.ToTimestampOrNil(v.Started),
77+
Completed: util.ToTimestampOrNil(v.Completed),
7478
Error: v.Error,
7579
Cached: v.Cached,
7680
ProgressGroup: v.ProgressGroup,
@@ -79,21 +83,21 @@ func (ss *SolveStatus) Marshal() (out []*controlapi.StatusResponse) {
7983
for _, v := range ss.Statuses {
8084
sr.Statuses = append(sr.Statuses, &controlapi.VertexStatus{
8185
ID: v.ID,
82-
Vertex: v.Vertex,
86+
Vertex: v.Vertex.String(),
8387
Name: v.Name,
8488
Current: v.Current,
8589
Total: v.Total,
86-
Timestamp: v.Timestamp,
87-
Started: v.Started,
88-
Completed: v.Completed,
90+
Timestamp: timestamppb.New(v.Timestamp),
91+
Started: util.ToTimestampOrNil(v.Started),
92+
Completed: util.ToTimestampOrNil(v.Completed),
8993
})
9094
}
9195
for i, v := range ss.Logs {
9296
sr.Logs = append(sr.Logs, &controlapi.VertexLog{
93-
Vertex: v.Vertex,
97+
Vertex: v.Vertex.String(),
9498
Stream: int64(v.Stream),
9599
Msg: v.Data,
96-
Timestamp: v.Timestamp,
100+
Timestamp: timestamppb.New(v.Timestamp),
97101
})
98102
logSize += len(v.Data) + emptyLogVertexSize
99103
// avoid logs growing big and split apart if they do
@@ -107,7 +111,7 @@ func (ss *SolveStatus) Marshal() (out []*controlapi.StatusResponse) {
107111
}
108112
for _, v := range ss.Warnings {
109113
sr.Warnings = append(sr.Warnings, &controlapi.VertexWarning{
110-
Vertex: v.Vertex,
114+
Vertex: v.Vertex.String(),
111115
Level: int64(v.Level),
112116
Short: v.Short,
113117
Detail: v.Detail,

cmd/buildctl/debug/histories.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func printRecordsTable(w io.Writer, eventReceiver controlapi.Control_ListenBuild
8383
if r := ev.Record; r != nil {
8484
ref = r.Ref
8585
if r.CreatedAt != nil {
86-
createdAt = r.CreatedAt.Local().Format(time.RFC3339)
86+
createdAt = r.CreatedAt.AsTime().Local().Format(time.RFC3339)
8787
}
8888
if r.CompletedAt != nil {
89-
completedAt = r.CompletedAt.Local().Format(time.RFC3339)
89+
completedAt = r.CompletedAt.AsTime().Local().Format(time.RFC3339)
9090
}
9191
generation = r.Generation
9292
if r.Pinned {

cmd/buildctl/debug/logs.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
1212
"github.com/moby/buildkit/util/appcontext"
1313
"github.com/moby/buildkit/util/progress/progresswriter"
14+
digest "github.com/opencontainers/go-digest"
1415
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1516
"github.com/pkg/errors"
1617
"github.com/urfave/cli"
@@ -66,8 +67,8 @@ func logs(clicontext *cli.Context) error {
6667
}
6768
store := proxy.NewContentStore(c.ContentClient())
6869
ra, err := store.ReaderAt(ctx, ocispecs.Descriptor{
69-
Digest: he.Record.Trace.Digest,
70-
Size: he.Record.Trace.Size_,
70+
Digest: digest.Digest(he.Record.Trace.Digest),
71+
Size: he.Record.Trace.Size,
7172
MediaType: he.Record.Trace.MediaType,
7273
})
7374
if err != nil {

cmd/buildctl/prunehistories.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ func pruneHistoriesWithTableOutput(ctx context.Context, w io.Writer, controlClie
105105
completedAt string
106106
)
107107
if r.CreatedAt != nil {
108-
createdAt = r.CreatedAt.Local().Format(time.RFC3339)
108+
createdAt = r.CreatedAt.AsTime().Local().Format(time.RFC3339)
109109
}
110110
if r.CompletedAt != nil {
111-
completedAt = r.CompletedAt.Local().Format(time.RFC3339)
111+
completedAt = r.CompletedAt.AsTime().Local().Format(time.RFC3339)
112112
}
113113
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%d\n", ev.Type, r.Ref, createdAt, completedAt, r.Generation)
114114
tw.Flush()

0 commit comments

Comments
 (0)