Skip to content

Commit 6737deb

Browse files
committed
vendor: add go-csvvalue for more efficient CSV parsing
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent c5413de commit 6737deb

File tree

21 files changed

+421
-34
lines changed

21 files changed

+421
-34
lines changed

cmd/buildctl/build/exportcache.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package build
22

33
import (
4-
"encoding/csv"
54
"strings"
65

76
"github.com/moby/buildkit/client"
87
"github.com/moby/buildkit/util/bklog"
98
"github.com/pkg/errors"
9+
"github.com/tonistiigi/go-csvvalue"
1010
)
1111

1212
func parseExportCacheCSV(s string) (client.CacheOptionsEntry, error) {
1313
ex := client.CacheOptionsEntry{
1414
Type: "",
1515
Attrs: map[string]string{},
1616
}
17-
csvReader := csv.NewReader(strings.NewReader(s))
18-
fields, err := csvReader.Read()
17+
fields, err := csvvalue.Fields(s, nil)
1918
if err != nil {
2019
return ex, err
2120
}

cmd/buildctl/build/importcache.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package build
22

33
import (
4-
"encoding/csv"
54
"strings"
65

76
"github.com/moby/buildkit/client"
87
"github.com/moby/buildkit/util/bklog"
98
"github.com/pkg/errors"
9+
"github.com/tonistiigi/go-csvvalue"
1010
)
1111

1212
func parseImportCacheCSV(s string) (client.CacheOptionsEntry, error) {
1313
im := client.CacheOptionsEntry{
1414
Type: "",
1515
Attrs: map[string]string{},
1616
}
17-
csvReader := csv.NewReader(strings.NewReader(s))
18-
fields, err := csvReader.Read()
17+
fields, err := csvvalue.Fields(s, nil)
1918
if err != nil {
2019
return im, err
2120
}

cmd/buildctl/build/output.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package build
22

33
import (
4-
"encoding/csv"
54
"io"
65
"os"
76
"strconv"
@@ -11,6 +10,7 @@ import (
1110
"github.com/moby/buildkit/client"
1211
"github.com/moby/buildkit/session/filesync"
1312
"github.com/pkg/errors"
13+
"github.com/tonistiigi/go-csvvalue"
1414
)
1515

1616
// parseOutputCSV parses a single --output CSV string
@@ -19,8 +19,7 @@ func parseOutputCSV(s string) (client.ExportEntry, error) {
1919
Type: "",
2020
Attrs: map[string]string{},
2121
}
22-
csvReader := csv.NewReader(strings.NewReader(s))
23-
fields, err := csvReader.Read()
22+
fields, err := csvvalue.Fields(s, nil)
2423
if err != nil {
2524
return ex, err
2625
}

cmd/buildctl/build/registryauthtlscontext.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package build
22

33
import (
4-
"encoding/csv"
54
"strconv"
65
"strings"
76

87
"github.com/moby/buildkit/session/auth/authprovider"
98
"github.com/pkg/errors"
9+
"github.com/tonistiigi/go-csvvalue"
1010
)
1111

1212
type authTLSContextEntry struct {
@@ -19,8 +19,7 @@ type authTLSContextEntry struct {
1919

2020
func parseRegistryAuthTLSContextCSV(s string) (authTLSContextEntry, error) {
2121
authTLSContext := authTLSContextEntry{}
22-
csvReader := csv.NewReader(strings.NewReader(s))
23-
fields, err := csvReader.Read()
22+
fields, err := csvvalue.Fields(s, nil)
2423
if err != nil {
2524
return authTLSContext, err
2625
}

cmd/buildctl/build/secret.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package build
22

33
import (
4-
"encoding/csv"
54
"strings"
65

76
"github.com/moby/buildkit/session"
87
"github.com/moby/buildkit/session/secrets/secretsprovider"
98
"github.com/pkg/errors"
9+
"github.com/tonistiigi/go-csvvalue"
1010
)
1111

1212
// ParseSecret parses --secret
@@ -27,8 +27,7 @@ func ParseSecret(sl []string) (session.Attachable, error) {
2727
}
2828

2929
func parseSecret(val string) (*secretsprovider.Source, error) {
30-
csvReader := csv.NewReader(strings.NewReader(val))
31-
fields, err := csvReader.Read()
30+
fields, err := csvvalue.Fields(val, nil)
3231
if err != nil {
3332
return nil, errors.Wrap(err, "failed to parse csv secret")
3433
}

frontend/attestations/parse.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package attestations
22

33
import (
4-
"encoding/csv"
54
"strings"
65

76
"github.com/pkg/errors"
7+
"github.com/tonistiigi/go-csvvalue"
88
)
99

1010
const (
@@ -63,8 +63,7 @@ func Parse(values map[string]string) (map[string]map[string]string, error) {
6363
if v == "" {
6464
continue
6565
}
66-
csvReader := csv.NewReader(strings.NewReader(v))
67-
fields, err := csvReader.Read()
66+
fields, err := csvvalue.Fields(v, nil)
6867
if err != nil {
6968
return nil, errors.Wrapf(err, "failed to parse %s", k)
7069
}

frontend/dockerfile/instructions/commands_runmount.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package instructions
22

33
import (
4-
"encoding/csv"
54
"strconv"
65
"strings"
76

87
"github.com/docker/go-units"
98
"github.com/moby/buildkit/util/suggest"
109
"github.com/pkg/errors"
10+
"github.com/tonistiigi/go-csvvalue"
1111
)
1212

1313
type MountType string
@@ -128,8 +128,7 @@ type Mount struct {
128128
}
129129

130130
func parseMount(val string, expander SingleWordExpander) (*Mount, error) {
131-
csvReader := csv.NewReader(strings.NewReader(val))
132-
fields, err := csvReader.Read()
131+
fields, err := csvvalue.Fields(val, nil)
133132
if err != nil {
134133
return nil, errors.Wrap(err, "failed to parse csv mounts")
135134
}

frontend/dockerui/attr.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dockerui
22

33
import (
4-
"encoding/csv"
54
"net"
65
"strconv"
76
"strings"
@@ -13,6 +12,7 @@ import (
1312
"github.com/moby/buildkit/solver/pb"
1413
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1514
"github.com/pkg/errors"
15+
"github.com/tonistiigi/go-csvvalue"
1616
)
1717

1818
func parsePlatforms(v string) ([]ocispecs.Platform, error) {
@@ -45,8 +45,7 @@ func parseExtraHosts(v string) ([]llb.HostIP, error) {
4545
return nil, nil
4646
}
4747
out := make([]llb.HostIP, 0)
48-
csvReader := csv.NewReader(strings.NewReader(v))
49-
fields, err := csvReader.Read()
48+
fields, err := csvvalue.Fields(v, nil)
5049
if err != nil {
5150
return nil, err
5251
}
@@ -80,8 +79,7 @@ func parseUlimits(v string) ([]pb.Ulimit, error) {
8079
return nil, nil
8180
}
8281
out := make([]pb.Ulimit, 0)
83-
csvReader := csv.NewReader(strings.NewReader(v))
84-
fields, err := csvReader.Read()
82+
fields, err := csvvalue.Fields(v, nil)
8583
if err != nil {
8684
return nil, err
8785
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ require (
7070
github.com/tonistiigi/fsutil v0.0.0-20240424095704-91a3fc46842c
7171
github.com/tonistiigi/go-actions-cache v0.0.0-20240320205438-9794bdbb2fb4
7272
github.com/tonistiigi/go-archvariant v1.0.0
73+
github.com/tonistiigi/go-csvvalue v0.0.0-20240619222358-bb8dd5cba3c2
7374
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
7475
github.com/tonistiigi/vt100 v0.0.0-20240514184818-90bafcd6abab
7576
github.com/urfave/cli v1.22.14

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ github.com/tonistiigi/go-actions-cache v0.0.0-20240320205438-9794bdbb2fb4 h1:R0l
403403
github.com/tonistiigi/go-actions-cache v0.0.0-20240320205438-9794bdbb2fb4/go.mod h1:anhKd3mnC1shAbQj1Q4IJ+w6xqezxnyDYlx/yKa7IXM=
404404
github.com/tonistiigi/go-archvariant v1.0.0 h1:5LC1eDWiBNflnTF1prCiX09yfNHIxDC/aukdhCdTyb0=
405405
github.com/tonistiigi/go-archvariant v1.0.0/go.mod h1:TxFmO5VS6vMq2kvs3ht04iPXtu2rUT/erOnGFYfk5Ho=
406+
github.com/tonistiigi/go-csvvalue v0.0.0-20240619222358-bb8dd5cba3c2 h1:4dXTcm/McJMoXXFhqr+4rNL4WkLqMoHkdMhT4nU0Z28=
407+
github.com/tonistiigi/go-csvvalue v0.0.0-20240619222358-bb8dd5cba3c2/go.mod h1:278M4p8WsNh3n4a1eqiFcV2FGk7wE5fwUpUom9mK9lE=
406408
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/v/cCndK0AMpt1wiVFb/YYmqB3/QG0=
407409
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6cRcDZSUvVmezrxJPkiO87ThFYsoUiMwWNDJk=
408410
github.com/tonistiigi/vt100 v0.0.0-20240514184818-90bafcd6abab h1:H6aJ0yKQ0gF49Qb2z5hI1UHxSQt4JMyxebFR15KnApw=

0 commit comments

Comments
 (0)