Skip to content

Commit e801e0e

Browse files
committed
Fix lint issues
google.golang.org/protobuf made all proto structs with a mutex to prevent copies. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 3cc72fd commit e801e0e

File tree

43 files changed

+194
-163
lines changed

Some content is hidden

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

43 files changed

+194
-163
lines changed

cache/contenthash/checksum.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,12 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
372372
ln := path.Join("/", filepath.ToSlash(stat.Linkname))
373373
v, ok := cc.txn.Get(convertPathToKey([]byte(ln)))
374374
if ok {
375-
cp := *v.(*CacheRecord)
376-
cr = &cp
375+
cp := v.(*CacheRecord)
376+
cr = &CacheRecord{
377+
Digest: cp.Digest,
378+
Type: cp.Type,
379+
Linkname: cp.Linkname,
380+
}
377381
}
378382
cc.linkMap[ln] = append(cc.linkMap[ln], k)
379383
}

client/llb/definition.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type DefinitionOp struct {
2121
mu sync.Mutex
2222
ops map[digest.Digest]*pb.Op
2323
defs map[digest.Digest][]byte
24-
metas map[digest.Digest]pb.OpMetadata
24+
metas map[digest.Digest]*pb.OpMetadata
2525
sources map[digest.Digest][]*SourceLocation
2626
platforms map[digest.Digest]*ocispecs.Platform
2727
dgst digest.Digest
@@ -101,7 +101,7 @@ func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
101101
return &DefinitionOp{
102102
ops: ops,
103103
defs: defs,
104-
metas: util.FromPointerMap[digest.Digest](def.Metadata),
104+
metas: util.FromStringMap[digest.Digest](def.Metadata),
105105
sources: srcs,
106106
platforms: platforms,
107107
dgst: dgst,
@@ -168,7 +168,7 @@ func (d *DefinitionOp) Marshal(ctx context.Context, c *Constraints) (digest.Dige
168168
defer d.mu.Unlock()
169169

170170
meta := d.metas[d.dgst]
171-
return d.dgst, d.defs[d.dgst], &meta, d.sources[d.dgst], nil
171+
return d.dgst, d.defs[d.dgst], meta, d.sources[d.dgst], nil
172172
}
173173

174174
func (d *DefinitionOp) Output() Output {

client/llb/fileop_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,24 +693,24 @@ func TestFileCreatedTime(t *testing.T) {
693693
require.Equal(t, dt3.UnixNano(), copy.Timestamp)
694694
}
695695

696-
func parseDef(t *testing.T, def [][]byte) (map[digest.Digest]pb.Op, []pb.Op) {
697-
m := map[digest.Digest]pb.Op{}
698-
arr := make([]pb.Op, 0, len(def))
696+
func parseDef(t *testing.T, def [][]byte) (map[digest.Digest]*pb.Op, []*pb.Op) {
697+
m := map[digest.Digest]*pb.Op{}
698+
arr := make([]*pb.Op, 0, len(def))
699699

700700
for _, dt := range def {
701701
var op pb.Op
702702
err := proto.Unmarshal(dt, &op)
703703
require.NoError(t, err)
704704
dgst := digest.FromBytes(dt)
705-
m[dgst] = op
706-
arr = append(arr, op)
705+
m[dgst] = &op
706+
arr = append(arr, &op)
707707
// fmt.Printf(":: %T %+v\n", op.Op, op)
708708
}
709709

710710
return m, arr
711711
}
712712

713-
func last(t *testing.T, arr []pb.Op) (digest.Digest, int) {
713+
func last(t *testing.T, arr []*pb.Op) (digest.Digest, int) {
714714
require.True(t, len(arr) > 1)
715715

716716
op := arr[len(arr)-1]

client/llb/llbbuild/llbbuild.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (b *build) Marshal(ctx context.Context, c *llb.Constraints) (digest.Digest,
6262
pbo.Attrs[pb.AttrLLBDefinitionFilename] = b.info.DefinitionFilename
6363
}
6464

65+
if b.constraints.Metadata == nil {
66+
b.constraints.Metadata = &pb.OpMetadata{}
67+
}
6568
if b.constraints.Metadata.Caps == nil {
6669
b.constraints.Metadata.Caps = make(map[string]bool)
6770
}

client/llb/llbtest/platform_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func toOp(e solver.Edge) *pb.Op {
186186

187187
func platform(e solver.Edge) ocispecs.Platform {
188188
op := toOp(e)
189-
p := *op.Platform
189+
p := op.Platform
190190
return ocispecs.Platform{
191191
OS: p.OS,
192192
Architecture: p.Architecture,

client/llb/marshal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
8989
}
9090

9191
c.WorkerConstraints = append(c.WorkerConstraints, override.WorkerConstraints...)
92-
md := mergeMetadata(&c.Metadata, &override.Metadata)
93-
c.Metadata = *md
92+
md := mergeMetadata(c.Metadata, override.Metadata)
93+
c.Metadata = md
9494

9595
if c.Platform == nil {
9696
defaultPlatform := platforms.Normalize(platforms.DefaultSpec())
@@ -112,7 +112,7 @@ func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
112112
Constraints: &pb.WorkerConstraints{
113113
Filter: c.WorkerConstraints,
114114
},
115-
}, &c.Metadata
115+
}, c.Metadata
116116
}
117117

118118
type MarshalCache struct {

client/llb/meta.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func ulimit(name UlimitName, soft int64, hard int64) StateOption {
261261
if err != nil {
262262
return nil, err
263263
}
264-
return append(v, pb.Ulimit{
264+
return append(v, &pb.Ulimit{
265265
Name: string(name),
266266
Soft: soft,
267267
Hard: hard,
@@ -270,14 +270,14 @@ func ulimit(name UlimitName, soft int64, hard int64) StateOption {
270270
}
271271
}
272272

273-
func getUlimit(s State) func(context.Context, *Constraints) ([]pb.Ulimit, error) {
274-
return func(ctx context.Context, c *Constraints) ([]pb.Ulimit, error) {
273+
func getUlimit(s State) func(context.Context, *Constraints) ([]*pb.Ulimit, error) {
274+
return func(ctx context.Context, c *Constraints) ([]*pb.Ulimit, error) {
275275
v, err := s.getValue(keyUlimit)(ctx, c)
276276
if err != nil {
277277
return nil, err
278278
}
279279
if v != nil {
280-
return v.([]pb.Ulimit), nil
280+
return v.([]*pb.Ulimit), nil
281281
}
282282
return nil, nil
283283
}

client/llb/source.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ func platformSpecificSource(id string) bool {
640640
}
641641

642642
func addCap(c *Constraints, id apicaps.CapID) {
643+
if c.Metadata == nil {
644+
c.Metadata = &pb.OpMetadata{}
645+
}
643646
if c.Metadata.Caps == nil {
644647
c.Metadata.Caps = make(map[string]bool)
645648
}

client/llb/state.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,12 @@ func (fn constraintsOptFunc) SetGitOption(gi *GitInfo) {
567567
}
568568

569569
func mergeMetadata(m1, m2 *pb.OpMetadata) *pb.OpMetadata {
570+
if m1 == nil {
571+
m1 = &pb.OpMetadata{}
572+
}
573+
if m2 == nil {
574+
m2 = &pb.OpMetadata{}
575+
}
570576
if m2.IgnoreCache {
571577
m1.IgnoreCache = true
572578
}
@@ -597,11 +603,17 @@ func mergeMetadata(m1, m2 *pb.OpMetadata) *pb.OpMetadata {
597603
}
598604

599605
var IgnoreCache = constraintsOptFunc(func(c *Constraints) {
606+
if c.Metadata == nil {
607+
c.Metadata = &pb.OpMetadata{}
608+
}
600609
c.Metadata.IgnoreCache = true
601610
})
602611

603612
func WithDescription(m map[string]string) ConstraintsOpt {
604613
return constraintsOptFunc(func(c *Constraints) {
614+
if c.Metadata == nil {
615+
c.Metadata = &pb.OpMetadata{}
616+
}
605617
if c.Metadata.Description == nil {
606618
c.Metadata.Description = map[string]string{}
607619
}
@@ -624,6 +636,9 @@ func WithCustomNamef(name string, a ...interface{}) ConstraintsOpt {
624636
// WithExportCache forces results for this vertex to be exported with the cache
625637
func WithExportCache() ConstraintsOpt {
626638
return constraintsOptFunc(func(c *Constraints) {
639+
if c.Metadata == nil {
640+
c.Metadata = &pb.OpMetadata{}
641+
}
627642
c.Metadata.ExportCache = &pb.ExportCache{Value: true}
628643
})
629644
}
@@ -632,6 +647,9 @@ func WithExportCache() ConstraintsOpt {
632647
// the cache
633648
func WithoutExportCache() ConstraintsOpt {
634649
return constraintsOptFunc(func(c *Constraints) {
650+
if c.Metadata == nil {
651+
c.Metadata = &pb.OpMetadata{}
652+
}
635653
// ExportCache with value false means to disable exporting
636654
c.Metadata.ExportCache = &pb.ExportCache{Value: false}
637655
})
@@ -641,6 +659,9 @@ func WithoutExportCache() ConstraintsOpt {
641659
// the default defined by the build configuration.
642660
func WithoutDefaultExportCache() ConstraintsOpt {
643661
return constraintsOptFunc(func(c *Constraints) {
662+
if c.Metadata == nil {
663+
c.Metadata = &pb.OpMetadata{}
664+
}
644665
// nil means no vertex based config has been set
645666
c.Metadata.ExportCache = nil
646667
})
@@ -664,7 +685,7 @@ func (cw *constraintsWrapper) applyConstraints(f func(c *Constraints)) {
664685
type Constraints struct {
665686
Platform *ocispecs.Platform
666687
WorkerConstraints []string
667-
Metadata pb.OpMetadata
688+
Metadata *pb.OpMetadata
668689
LocalUniqueID string
669690
Caps *apicaps.CapSet
670691
SourceLocations []*SourceLocation
@@ -684,6 +705,9 @@ func LocalUniqueID(v string) ConstraintsOpt {
684705

685706
func ProgressGroup(id, name string, weak bool) ConstraintsOpt {
686707
return constraintsOptFunc(func(c *Constraints) {
708+
if c.Metadata == nil {
709+
c.Metadata = &pb.OpMetadata{}
710+
}
687711
c.Metadata.ProgressGroup = &pb.ProgressGroup{Id: id, Name: name, Weak: weak}
688712
})
689713
}

client/workers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
controlapi "github.com/moby/buildkit/api/services/control"
88
apitypes "github.com/moby/buildkit/api/types"
99
"github.com/moby/buildkit/solver/pb"
10-
"github.com/moby/buildkit/util"
1110
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1211
"github.com/pkg/errors"
1312
)
@@ -40,7 +39,7 @@ func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]
4039
wi = append(wi, &WorkerInfo{
4140
ID: w.ID,
4241
Labels: w.Labels,
43-
Platforms: pb.ToSpecPlatforms(util.FromPointerSlice(w.Platforms)),
42+
Platforms: pb.ToSpecPlatforms(w.Platforms),
4443
GCPolicy: fromAPIGCPolicy(w.GCPolicy),
4544
BuildkitVersion: fromAPIBuildkitVersion(w.BuildkitVersion),
4645
})

cmd/buildctl/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ func read(r io.Reader, clicontext *cli.Context) (*llb.Definition, error) {
134134
if !ok {
135135
opMetadata = &pb.OpMetadata{}
136136
}
137-
c := llb.Constraints{Metadata: *opMetadata}
137+
c := llb.Constraints{Metadata: opMetadata}
138138
llb.IgnoreCache(&c)
139-
def.Metadata[dgst] = &c.Metadata
139+
def.Metadata[dgst] = c.Metadata
140140
}
141141
}
142142
return def, nil

cmd/buildctl/debug/dumpllb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func dumpLLB(clicontext *cli.Context) error {
5858
}
5959

6060
type llbOp struct {
61-
Op pb.Op
61+
Op *pb.Op
6262
Digest digest.Digest
63-
OpMetadata pb.OpMetadata
63+
OpMetadata *pb.OpMetadata
6464
}
6565

6666
func loadLLB(r io.Reader) ([]llbOp, error) {
@@ -75,7 +75,7 @@ func loadLLB(r io.Reader) ([]llbOp, error) {
7575
return nil, errors.Wrap(err, "failed to parse op")
7676
}
7777
dgst := digest.FromBytes(dt)
78-
ent := llbOp{Op: op, Digest: dgst, OpMetadata: *def.Metadata[dgst]}
78+
ent := llbOp{Op: &op, Digest: dgst, OpMetadata: def.Metadata[dgst]}
7979
ops = append(ops, ent)
8080
}
8181
return ops, nil
@@ -104,7 +104,7 @@ func writeDot(ops []llbOp, w io.Writer) {
104104
}
105105
}
106106

107-
func attr(dgst digest.Digest, op pb.Op) (string, string) {
107+
func attr(dgst digest.Digest, op *pb.Op) (string, string) {
108108
switch op := op.Op.(type) {
109109
case *pb.Op_Source:
110110
return op.Source.Identifier, "ellipse"

control/control.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (c *Controller) ListWorkers(ctx context.Context, r *controlapi.ListWorkersR
542542
resp.Record = append(resp.Record, &apitypes.WorkerRecord{
543543
ID: w.ID(),
544544
Labels: w.Labels(),
545-
Platforms: util.PointerSlice(pb.PlatformsFromSpec(w.Platforms(true))),
545+
Platforms: pb.PlatformsFromSpec(w.Platforms(true)),
546546
GCPolicy: toPBGCPolicy(w.GCPolicy()),
547547
BuildkitVersion: toPBBuildkitVersion(w.BuildkitVersion()),
548548
})
@@ -646,7 +646,7 @@ func findDuplicateCacheOptions(cacheOpts []*controlapi.CacheOptionsEntry) ([]*co
646646
seen := map[string]*controlapi.CacheOptionsEntry{}
647647
duplicate := map[string]struct{}{}
648648
for _, opt := range cacheOpts {
649-
k, err := cacheOptKey(*opt)
649+
k, err := cacheOptKey(opt)
650650
if err != nil {
651651
return nil, err
652652
}
@@ -663,7 +663,7 @@ func findDuplicateCacheOptions(cacheOpts []*controlapi.CacheOptionsEntry) ([]*co
663663
return duplicates, nil
664664
}
665665

666-
func cacheOptKey(opt controlapi.CacheOptionsEntry) (string, error) {
666+
func cacheOptKey(opt *controlapi.CacheOptionsEntry) (string, error) {
667667
if opt.Type == "registry" && opt.Attrs["ref"] != "" {
668668
return opt.Attrs["ref"], nil
669669
}

exporter/local/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func CreateFS(ctx context.Context, sessionID string, k string, ref cache.Immutab
196196
}
197197
names[name] = struct{}{}
198198

199-
st := fstypes.Stat{
199+
st := &fstypes.Stat{
200200
Mode: 0600,
201201
Path: name,
202202
ModTime: defaultTime.UnixNano(),

frontend/dockerfile/builder/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,5 @@ func wrapSource(err error, sm *llb.SourceMap, ranges []parser.Range) error {
275275
},
276276
})
277277
}
278-
return errdefs.WithSource(err, s)
278+
return errdefs.WithSource(err, &s)
279279
}

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ type dispatchOpt struct {
682682
buildPlatforms []ocispecs.Platform
683683
extraHosts []llb.HostIP
684684
shmSize int64
685-
ulimit []pb.Ulimit
685+
ulimit []*pb.Ulimit
686686
cgroupParent string
687687
llbCaps *apicaps.CapSet
688688
sourceMap *llb.SourceMap

frontend/dockerui/attr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ func parseShmSize(v string) (int64, error) {
7575
return kb, nil
7676
}
7777

78-
func parseUlimits(v string) ([]pb.Ulimit, error) {
78+
func parseUlimits(v string) ([]*pb.Ulimit, error) {
7979
if v == "" {
8080
return nil, nil
8181
}
82-
out := make([]pb.Ulimit, 0)
82+
out := make([]*pb.Ulimit, 0)
8383
csvReader := csv.NewReader(strings.NewReader(v))
8484
fields, err := csvReader.Read()
8585
if err != nil {
@@ -90,7 +90,7 @@ func parseUlimits(v string) ([]pb.Ulimit, error) {
9090
if err != nil {
9191
return nil, err
9292
}
93-
out = append(out, pb.Ulimit{
93+
out = append(out, &pb.Ulimit{
9494
Name: ulimit.Name,
9595
Soft: ulimit.Soft,
9696
Hard: ulimit.Hard,

frontend/dockerui/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Config struct {
6363
NetworkMode pb.NetMode
6464
ShmSize int64
6565
Target string
66-
Ulimits []pb.Ulimit
66+
Ulimits []*pb.Ulimit
6767

6868
CacheImports []client.CacheOptionsEntry
6969
TargetPlatforms []ocispecs.Platform // nil means default
@@ -218,7 +218,7 @@ func (bc *Client) init() error {
218218
var cacheImports []client.CacheOptionsEntry
219219
// new API
220220
if cacheImportsStr := opts[keyCacheImports]; cacheImportsStr != "" {
221-
var cacheImportsUM []controlapi.CacheOptionsEntry
221+
var cacheImportsUM []*controlapi.CacheOptionsEntry
222222
if err := json.Unmarshal([]byte(cacheImportsStr), &cacheImportsUM); err != nil {
223223
return errors.Wrapf(err, "failed to unmarshal %s (%q)", keyCacheImports, cacheImportsStr)
224224
}

0 commit comments

Comments
 (0)