mirror of
https://github.com/moby/buildkit.git
synced 2026-11-06 05:16:45 +00:00
hack: update gopls to v0.38.0
Currently it is not possible to update to more recent version as modernize causes errors in generated code. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
19 files changed
+114
-55
No files matched your search
@@ -1,5 +1,4 @@
|
||||
//go:build nvidia
|
||||
// +build nvidia
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build venus
|
||||
// +build venus
|
||||
|
||||
package main
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ func MakeInTotoStatements(ctx context.Context, s session.Group, attestations []e
|
||||
statements := make([]intoto.Statement, len(attestations))
|
||||
|
||||
for i, att := range attestations {
|
||||
i, att := i, att
|
||||
eg.Go(func() error {
|
||||
content, err := ReadAll(ctx, s, att)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,7 +30,6 @@ func Unbundle(ctx context.Context, s session.Group, bundled []exporter.Attestati
|
||||
unbundled := make([][]exporter.Attestation, len(bundled))
|
||||
|
||||
for i, att := range bundled {
|
||||
i, att := i, att
|
||||
eg.Go(func() error {
|
||||
switch att.Kind {
|
||||
case gatewaypb.AttestationKind_InToto:
|
||||
|
||||
@@ -281,7 +281,6 @@ func (ic *ImageWriter) Commit(ctx context.Context, inp *exporter.Source, session
|
||||
|
||||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
for i, att := range attestations {
|
||||
i, att := i, att
|
||||
eg.Go(func() error {
|
||||
att, err := supplementSBOM(ctx2, session.NewGroup(sessionID), r, remote, att)
|
||||
if err != nil {
|
||||
@@ -420,7 +419,6 @@ func (ic *ImageWriter) rewriteRemoteWithEpoch(ctx context.Context, opts *ImageCo
|
||||
fmt.Sprintf("rewriting layers with source-date-epoch %d (%s)", opts.Epoch.Unix(), opts.Epoch.String()))
|
||||
var divergedFromBase bool
|
||||
for i, desc := range remoteDescriptors {
|
||||
i, desc := i, desc
|
||||
// Usually we get non-empty diffID here, but if the content was ingested via a third-party containerd client,
|
||||
// diffID here can be empty, and will be computed by the converter.
|
||||
diffID := digest.Digest(desc.Annotations[labels.LabelUncompressed])
|
||||
@@ -567,8 +565,6 @@ func (ic *ImageWriter) commitAttestationsManifest(ctx context.Context, opts *Ima
|
||||
|
||||
layers := make([]ocispecs.Descriptor, len(statements))
|
||||
for i, statement := range statements {
|
||||
i, statement := i, statement
|
||||
|
||||
data, err := json.Marshal(statement)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal attestation")
|
||||
|
||||
@@ -1279,11 +1279,14 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
|
||||
} else {
|
||||
// More complex heredoc, so reconstitute it, and pass it to the
|
||||
// shell to handle.
|
||||
full := args[0]
|
||||
var b strings.Builder
|
||||
b.WriteString(args[0])
|
||||
for _, file := range c.Files {
|
||||
full += "\n" + file.Data + file.Name
|
||||
b.WriteByte('\n')
|
||||
b.WriteString(file.Data)
|
||||
b.WriteString(file.Name)
|
||||
}
|
||||
args = []string{full}
|
||||
args = []string{b.String()}
|
||||
}
|
||||
}
|
||||
if c.PrependShell {
|
||||
|
||||
@@ -2,6 +2,7 @@ package dockerfile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
@@ -60,21 +61,57 @@ func testChmodNonOctal(t *testing.T, sb integration.Sandbox) {
|
||||
},
|
||||
}
|
||||
|
||||
expectedCommands := ""
|
||||
copyCommands := ""
|
||||
verifyCommands := ""
|
||||
var expectedCommands strings.Builder
|
||||
var copyCommands strings.Builder
|
||||
var verifyCommands strings.Builder
|
||||
|
||||
for _, tc := range tcases {
|
||||
if tc.isDir {
|
||||
// create nested input dir because COPY copies directory contents
|
||||
expectedCommands += "RUN mkdir -p /input/dirs/" + tc.dst + " && cp -a /input/" + tc.src + " /input/dirs/" + tc.dst + "/" + tc.dst + "\n"
|
||||
expectedCommands += "RUN cp -a /input/dirs/" + tc.dst + "/. /expected/ && chmod " + tc.mode + " /expected/" + tc.dst + "\n"
|
||||
copyCommands += "COPY --from=base --chmod=" + tc.mode + " /input/dirs/" + tc.dst + " /\n"
|
||||
expectedCommands.WriteString("RUN mkdir -p /input/dirs/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteString(" && cp -a /input/")
|
||||
expectedCommands.WriteString(tc.src)
|
||||
expectedCommands.WriteString(" /input/dirs/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteByte('/')
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteByte('\n')
|
||||
expectedCommands.WriteString("RUN cp -a /input/dirs/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteString("/. /expected/ && chmod ")
|
||||
expectedCommands.WriteString(tc.mode)
|
||||
expectedCommands.WriteString(" /expected/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteByte('\n')
|
||||
copyCommands.WriteString("COPY --from=base --chmod=")
|
||||
copyCommands.WriteString(tc.mode)
|
||||
copyCommands.WriteString(" /input/dirs/")
|
||||
copyCommands.WriteString(tc.dst)
|
||||
copyCommands.WriteString(" /\n")
|
||||
} else {
|
||||
expectedCommands += "RUN cp -a /input/" + tc.src + " /expected/" + tc.dst + " && chmod " + tc.mode + " /expected/" + tc.dst + "\n"
|
||||
copyCommands += "COPY --from=base --chmod=" + tc.mode + " /input/" + tc.src + " /" + tc.dst + "\n"
|
||||
expectedCommands.WriteString("RUN cp -a /input/")
|
||||
expectedCommands.WriteString(tc.src)
|
||||
expectedCommands.WriteString(" /expected/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteString(" && chmod ")
|
||||
expectedCommands.WriteString(tc.mode)
|
||||
expectedCommands.WriteString(" /expected/")
|
||||
expectedCommands.WriteString(tc.dst)
|
||||
expectedCommands.WriteByte('\n')
|
||||
copyCommands.WriteString("COPY --from=base --chmod=")
|
||||
copyCommands.WriteString(tc.mode)
|
||||
copyCommands.WriteString(" /input/")
|
||||
copyCommands.WriteString(tc.src)
|
||||
copyCommands.WriteString(" /")
|
||||
copyCommands.WriteString(tc.dst)
|
||||
copyCommands.WriteByte('\n')
|
||||
}
|
||||
verifyCommands += "RUN [ \"$(stat -c %A /actual/" + tc.dst + ")\" = \"$(stat -c %A /expected/" + tc.dst + ")\" ]\n"
|
||||
verifyCommands.WriteString("RUN [ \"$(stat -c %A /actual/")
|
||||
verifyCommands.WriteString(tc.dst)
|
||||
verifyCommands.WriteString(")\" = \"$(stat -c %A /expected/")
|
||||
verifyCommands.WriteString(tc.dst)
|
||||
verifyCommands.WriteString(")\" ]\n")
|
||||
}
|
||||
|
||||
dockerfile := fmt.Appendf(nil, `
|
||||
@@ -97,7 +134,7 @@ FROM base
|
||||
COPY --from=result / /actual/
|
||||
%s
|
||||
|
||||
`, expectedCommands, copyCommands, verifyCommands)
|
||||
`, expectedCommands.String(), copyCommands.String(), verifyCommands.String())
|
||||
|
||||
dir := integration.Tmpdir(
|
||||
t,
|
||||
|
||||
@@ -450,8 +450,15 @@ func parseOnBuild(req parseRequest) (*OnbuildCommand, error) {
|
||||
}
|
||||
|
||||
original := regexp.MustCompile(`(?i)^\s*ONBUILD\s*`).ReplaceAllString(req.original, "")
|
||||
for _, heredoc := range req.heredocs {
|
||||
original += "\n" + heredoc.Content + heredoc.Name
|
||||
if len(req.heredocs) > 0 {
|
||||
var b strings.Builder
|
||||
b.WriteString(original)
|
||||
for _, heredoc := range req.heredocs {
|
||||
b.WriteByte('\n')
|
||||
b.WriteString(heredoc.Content)
|
||||
b.WriteString(heredoc.Name)
|
||||
}
|
||||
original = b.String()
|
||||
}
|
||||
|
||||
return &OnbuildCommand{
|
||||
|
||||
@@ -49,25 +49,29 @@ func (node *Node) Location() []Range {
|
||||
// Dump dumps the AST defined by `node` as a list of sexps.
|
||||
// Returns a string suitable for printing.
|
||||
func (node *Node) Dump() string {
|
||||
str := strings.ToLower(node.Value)
|
||||
var str strings.Builder
|
||||
str.WriteString(strings.ToLower(node.Value))
|
||||
|
||||
if len(node.Flags) > 0 {
|
||||
str += fmt.Sprintf(" %q", node.Flags)
|
||||
fmt.Fprintf(&str, " %q", node.Flags)
|
||||
}
|
||||
|
||||
for _, n := range node.Children {
|
||||
str += "(" + n.Dump() + ")\n"
|
||||
str.WriteByte('(')
|
||||
str.WriteString(n.Dump())
|
||||
str.WriteString(")\n")
|
||||
}
|
||||
|
||||
for n := node.Next; n != nil; n = n.Next {
|
||||
str.WriteByte(' ')
|
||||
if len(n.Children) > 0 {
|
||||
str += " " + n.Dump()
|
||||
str.WriteString(n.Dump())
|
||||
} else {
|
||||
str += " " + strconv.Quote(n.Value)
|
||||
str.WriteString(strconv.Quote(n.Value))
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimSpace(str)
|
||||
return strings.TrimSpace(str.String())
|
||||
}
|
||||
|
||||
func (node *Node) lines(start, end int) {
|
||||
@@ -367,6 +371,8 @@ func Parse(rwc io.Reader) (*Result, error) {
|
||||
for _, heredoc := range heredocs {
|
||||
terminator := []byte(heredoc.Name)
|
||||
terminated := false
|
||||
var content strings.Builder
|
||||
content.WriteString(heredoc.Content)
|
||||
for scanner.Scan() {
|
||||
bytesRead := scanner.Bytes()
|
||||
currentLine++
|
||||
@@ -379,12 +385,13 @@ func Parse(rwc io.Reader) (*Result, error) {
|
||||
terminated = true
|
||||
break
|
||||
}
|
||||
heredoc.Content += string(bytesRead)
|
||||
content.Write(bytesRead)
|
||||
}
|
||||
if !terminated {
|
||||
return nil, withLocation(errors.New("unterminated heredoc"), startLine, currentLine)
|
||||
}
|
||||
|
||||
heredoc.Content = content.String()
|
||||
child.Heredocs = append(child.Heredocs, heredoc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ func (bc *Client) Build(ctx context.Context, fn BuildFunc) (*ResultBuilder, erro
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
for i, tp := range targets {
|
||||
i, tp := i, tp
|
||||
eg.Go(func() error {
|
||||
ref, img, baseImg, err := fn(ctx, tp, i)
|
||||
if err != nil {
|
||||
|
||||
@@ -250,7 +250,6 @@ func (c *BridgeClient) NewContainer(ctx context.Context, req client.NewContainer
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
for i, m := range req.Mounts {
|
||||
i, m := i, m
|
||||
eg.Go(func() error {
|
||||
var workerRef *worker.WorkerRef
|
||||
if m.Ref != nil {
|
||||
|
||||
@@ -1537,7 +1537,6 @@ func (lbf *llbBridgeForwarder) ExecProcess(srv pb.LLBBridge_ExecProcessServer) e
|
||||
// StartedMessage so that Fd output will not potentially arrive
|
||||
// to the client before "Started" as the container starts up.
|
||||
for fd, file := range pio.serverReaders {
|
||||
fd, file := fd, file
|
||||
eg.Go(func() error {
|
||||
defer func() {
|
||||
file.Close()
|
||||
|
||||
@@ -6,7 +6,7 @@ ARG XX_VERSION=1.6.1
|
||||
ARG PROTOLINT_VERSION=0.50.5
|
||||
ARG GOLANGCI_LINT_VERSION=v2.8.0
|
||||
ARG GOLANGCI_FROM_SOURCE=false
|
||||
ARG GOPLS_VERSION=v0.33.0
|
||||
ARG GOPLS_VERSION=v0.38.0
|
||||
# GOPLS_ANALYZERS defines gopls analyzers to be run. disabled by default: deprecated simplifyrange unusedfunc unusedvariable
|
||||
ARG GOPLS_ANALYZERS="embeddirective fillreturns infertypeargs maprange modernize nonewvars noresultvalues simplifycompositelit simplifyslice unusedparams yield"
|
||||
|
||||
@@ -84,16 +84,30 @@ RUN <<'EOF'
|
||||
mkdir -p /out
|
||||
for analyzer in ${GOPLS_ANALYZERS}; do
|
||||
mkdir -p internal/cmd/$analyzer
|
||||
cat <<eot > internal/cmd/$analyzer/main.go
|
||||
if [ "$analyzer" = "modernize" ]; then
|
||||
cat <<'eot' > internal/cmd/$analyzer/main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis/multichecker"
|
||||
"golang.org/x/tools/go/analysis/passes/modernize"
|
||||
)
|
||||
|
||||
func main() { multichecker.Main(modernize.Suite...) }
|
||||
eot
|
||||
else
|
||||
pkg="golang.org/x/tools/gopls/internal/analysis/$analyzer"
|
||||
cat <<eot > internal/cmd/$analyzer/main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis/singlechecker"
|
||||
analyzer "golang.org/x/tools/gopls/internal/analysis/$analyzer"
|
||||
analyzer "${pkg}"
|
||||
)
|
||||
|
||||
func main() { singlechecker.Main(analyzer.Analyzer) }
|
||||
eot
|
||||
fi
|
||||
echo "Analyzing with ${analyzer}..."
|
||||
go build -o /out/$analyzer ./internal/cmd/$analyzer
|
||||
done
|
||||
|
||||
@@ -1238,8 +1238,8 @@ func adaptHistoryRecord(rec *controlapi.BuildHistoryRecord) filters.Adaptor {
|
||||
|
||||
func cutAny(in string, opt []string) (before string, sep string, after string, found bool) {
|
||||
for _, s := range opt {
|
||||
if i := strings.Index(in, s); i >= 0 {
|
||||
return in[:i], s, in[i+len(s):], true
|
||||
if before, after, ok := strings.Cut(in, s); ok {
|
||||
return before, s, after, true
|
||||
}
|
||||
}
|
||||
return "", "", "", false
|
||||
|
||||
@@ -44,7 +44,6 @@ func NewContentHashFunc(selectors []Selector) solver.ResultBasedCacheFunc {
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
for i, sel := range selectors {
|
||||
i, sel := i, sel
|
||||
eg.Go(func() error {
|
||||
dgst, err := contenthash.Checksum(
|
||||
ctx, ref.ImmutableRef, path.Join("/", sel.Path),
|
||||
|
||||
@@ -319,7 +319,6 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
|
||||
if r == nil {
|
||||
continue
|
||||
}
|
||||
k, r := k, r
|
||||
cp := res.Provenance.Refs[k]
|
||||
eg.Go(func() error {
|
||||
desc, release, err := makeProvenance(k, r, cp)
|
||||
@@ -367,7 +366,6 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
|
||||
|
||||
setDeprecated := true
|
||||
for i, descref := range descrefs {
|
||||
i, descref := i, descref
|
||||
if descref == nil {
|
||||
continue
|
||||
}
|
||||
@@ -777,7 +775,6 @@ func runCacheExporters(ctx context.Context, exporters []RemoteCacheExporter, j *
|
||||
var cacheExporterResponse map[string]string
|
||||
resps := make([]map[string]string, len(exporters))
|
||||
for i, exp := range exporters {
|
||||
i, exp := i, exp
|
||||
eg.Go(func() (err error) {
|
||||
id := fmt.Sprint(j.SessionID, "-cache-", i)
|
||||
err = inBuilderContext(ctx, j, exp.Name(), id, func(ctx context.Context, _ solver.JobContext) error {
|
||||
@@ -853,7 +850,6 @@ func (s *Solver) runExporters(ctx context.Context, ref string, exporters []expor
|
||||
descs := make([]exporter.DescriptorReference, len(exporters))
|
||||
var inlineCacheMu sync.Mutex
|
||||
for i, exp := range exporters {
|
||||
i, exp := i, exp
|
||||
eg.Go(func() error {
|
||||
id := fmt.Sprint(job.SessionID, "-export-", i)
|
||||
return inBuilderContext(ctx, job, exp.Name(), id, func(ctx context.Context, _ solver.JobContext) error {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/v2/core/remotes/docker"
|
||||
remoteserrors "github.com/containerd/containerd/v2/core/remotes/errors"
|
||||
@@ -81,11 +82,13 @@ func (e *formattedDockerError) Error() string {
|
||||
case 1:
|
||||
return format(e.dErr[0])
|
||||
default:
|
||||
msg := "errors:\n"
|
||||
var msg strings.Builder
|
||||
msg.WriteString("errors:\n")
|
||||
for _, err := range e.dErr {
|
||||
msg += format(err) + "\n"
|
||||
msg.WriteString(format(err))
|
||||
msg.WriteByte('\n')
|
||||
}
|
||||
return msg
|
||||
return msg.String()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,20 +156,25 @@ options ndots:0 attempts:3
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc := tc
|
||||
var input string
|
||||
var input strings.Builder
|
||||
if len(tc.inputNS) != 0 {
|
||||
for _, ns := range tc.inputNS {
|
||||
input += "nameserver " + ns + "\n"
|
||||
input.WriteString("nameserver ")
|
||||
input.WriteString(ns)
|
||||
input.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
if len(tc.inputSearch) != 0 {
|
||||
input += "search " + strings.Join(tc.inputSearch, " ") + "\n"
|
||||
input.WriteString("search ")
|
||||
input.WriteString(strings.Join(tc.inputSearch, " "))
|
||||
input.WriteByte('\n')
|
||||
}
|
||||
if len(tc.inputOptions) != 0 {
|
||||
input += "options " + strings.Join(tc.inputOptions, " ") + "\n"
|
||||
input.WriteString("options ")
|
||||
input.WriteString(strings.Join(tc.inputOptions, " "))
|
||||
input.WriteByte('\n')
|
||||
}
|
||||
rc, err := Parse(bytes.NewBufferString(input), "")
|
||||
rc, err := Parse(bytes.NewBufferString(input.String()), "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.inputNS, a2s(rc.NameServers()))
|
||||
assert.Equal(t, tc.inputSearch, rc.Search())
|
||||
@@ -327,7 +332,6 @@ nameserver ::1
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc := tc
|
||||
rc, err := Parse(bytes.NewBufferString(tc.input), "/etc/resolv.conf")
|
||||
require.NoError(t, err)
|
||||
if tc.overrideNS != nil {
|
||||
@@ -508,7 +512,6 @@ options trust-ad ndots:0 attempts:3 edns0
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc := tc
|
||||
rc, err := Parse(bytes.NewBufferString(tc.input), "/etc/resolv.conf")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -81,9 +81,10 @@ func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
|
||||
c.RootCAs = append(c.RootCAs, filepath.Join(d, f.Name()))
|
||||
}
|
||||
if strings.HasSuffix(f.Name(), ".cert") {
|
||||
base, _ := strings.CutSuffix(f.Name(), ".cert")
|
||||
c.KeyPairs = append(c.KeyPairs, config.TLSKeyPair{
|
||||
Certificate: filepath.Join(d, f.Name()),
|
||||
Key: filepath.Join(d, strings.TrimSuffix(f.Name(), ".cert")+".key"),
|
||||
Key: filepath.Join(d, base+".key"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user