Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ linters:
- linters:
- revive
text: stutters
- linters:
- revive
text: var-naming
- linters:
- revive
text: empty-block
Expand Down
8 changes: 4 additions & 4 deletions bake/hclparser/gohcl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func getFieldTags(ty reflect.Type) *fieldTags {
continue
}

comma := strings.Index(tag, ",")
before, after, ok := strings.Cut(tag, ",")
var name, kind string
if comma != -1 {
name = tag[:comma]
kind = tag[comma+1:]
if ok {
name = before
kind = after
} else {
name = tag
kind = "attr"
Expand Down
13 changes: 5 additions & 8 deletions bake/hclparser/gohcl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (
"github.com/hashicorp/hcl/v2"
)

var victimExpr hcl.Expression
var victimBody hcl.Body

var exprType = reflect.TypeOf(&victimExpr).Elem()
var bodyType = reflect.TypeOf(&victimBody).Elem()
var blockType = reflect.TypeOf((*hcl.Block)(nil)) //nolint:unused
var attrType = reflect.TypeOf((*hcl.Attribute)(nil))
var attrsType = reflect.TypeOf(hcl.Attributes(nil))
var exprType = reflect.TypeFor[hcl.Expression]()
var bodyType = reflect.TypeFor[hcl.Body]()
var blockType = reflect.TypeFor[*hcl.Block]() //nolint:unused
var attrType = reflect.TypeFor[*hcl.Attribute]()
var attrsType = reflect.TypeFor[hcl.Attributes]()
5 changes: 0 additions & 5 deletions bake/hclparser/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestIndexOf(t *testing.T) {
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
got, err := indexOfFunc().Call([]cty.Value{test.input, test.key})
if test.wantErr {
Expand Down Expand Up @@ -85,7 +84,6 @@ func TestBasename(t *testing.T) {
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
got, err := basenameFunc().Call([]cty.Value{test.input})
if test.wantErr {
Expand Down Expand Up @@ -136,7 +134,6 @@ func TestDirname(t *testing.T) {
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
got, err := dirnameFunc().Call([]cty.Value{test.input})
if test.wantErr {
Expand Down Expand Up @@ -190,7 +187,6 @@ func TestSanitize(t *testing.T) {
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
got, err := sanitizeFunc().Call([]cty.Value{test.input})
require.NoError(t, err)
Expand Down Expand Up @@ -251,7 +247,6 @@ func TestSemverCmp(t *testing.T) {
},
}
for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
got, err := semvercmpFunc().Call([]cty.Value{test.version, test.constraint})
if test.wantErr {
Expand Down
4 changes: 2 additions & 2 deletions bake/hclparser/type_implied.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func impliedStructType(rt reflect.Type, path cty.Path) (cty.Type, error) {
}

var (
valueType = reflect.TypeOf(cty.Value{})
stringType = reflect.TypeOf("")
valueType = reflect.TypeFor[cty.Value]()
stringType = reflect.TypeFor[string]()
)

// structTagIndices interrogates the fields of the given type (which must
Expand Down
1 change: 0 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
var insecurePush bool

for i, dp := range dps {
i, dp := i, dp
node := dp.Node()
so := reqForNodes[k][i].so
if multiDriver {
Expand Down
2 changes: 0 additions & 2 deletions build/resolver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (r *nodeResolver) Resolve(ctx context.Context, optPlatforms map[string][]oc
eg, egCtx := errgroup.WithContext(ctx)
workers := make([][]ocispecs.Platform, len(clients))
for i, c := range clients {
i, c := i, c
if c == nil {
continue
}
Expand Down Expand Up @@ -269,7 +268,6 @@ func (r *nodeResolver) boot(ctx context.Context, idxs []int, pw progress.Writer)
eg, ctx := errgroup.WithContext(ctx)

for i, idx := range idxs {
i, idx := i, idx
eg.Go(func() error {
c, err := r.clients.g.Do(ctx, fmt.Sprint(idx), func(ctx context.Context) (*client.Client, error) {
if r.nodes[idx].Driver == nil {
Expand Down
3 changes: 2 additions & 1 deletion commands/dap.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func dapAttachCmd() *cobra.Command {
return err
}

conn, err := net.Dial("unix", args[0])
dialer := net.Dialer{}
conn, err := dialer.DialContext(cmd.Context(), "unix", args[0])
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion commands/history/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ func runTrace(ctx context.Context, dockerCli command.Cli, opts traceOptions) err
return nil
}

ln, err := net.Listen("tcp", opts.addr)
lc := net.ListenConfig{}
ln, err := lc.Listen(ctx, "tcp", opts.addr)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions commands/history/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ func timeBasedFilter(key, value, sep string) (matchFunc, error) {

func cutAny(s string, seps ...string) (before, after, sep string, found bool) {
for _, sep := range seps {
if idx := strings.Index(s, sep); idx != -1 {
return s[:idx], s[idx+len(sep):], sep, true
if before0, after0, ok := strings.Cut(s, sep); ok {
return before0, after0, sep, true
}
}
return s, "", "", false
Expand Down
3 changes: 2 additions & 1 deletion dap/debug_shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (s *shell) listen() error {
}()
s.SocketPath = filepath.Join(dir, "s.sock")

s.l, s.err = net.Listen("unix", s.SocketPath)
lc := net.ListenConfig{}
s.l, s.err = lc.Listen(context.Background(), "unix", s.SocketPath)
if s.err != nil {
return
}
Expand Down
3 changes: 2 additions & 1 deletion dap/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (t *thread) Exec(ctx Context, args []string) (message string, retErr error)
}()

socketPath := filepath.Join(dir, "s.sock")
l, err := net.Listen("unix", socketPath)
lc := net.ListenConfig{}
l, err := lc.Listen(ctx, "unix", socketPath)
if err != nil {
return "", err
}
Expand Down
6 changes: 2 additions & 4 deletions dap/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,9 @@ func (t *thread) prepareResultHandle(c Context, ref gateway.Reference, err error

// Start the attach. Use the context we created and perform it in
// a goroutine. We aren't necessarily assuming this will actually work.
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
t.sh.Attach(ctx, t)
}()
})
}

func (t *thread) Continue() {
Expand Down
6 changes: 3 additions & 3 deletions docs/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func generateBakeStdlibDocs(filename string) error {
}
currentContent := string(dt)

start := strings.Index(currentContent, "<!---MARKER_STDLIB_START-->")
before, _, ok := strings.Cut(currentContent, "<!---MARKER_STDLIB_START-->")
end := strings.Index(currentContent, "<!---MARKER_STDLIB_END-->")
if start == -1 {
if !ok {
return errors.Errorf("no start marker in %s", filename)
}
if end == -1 {
Expand All @@ -164,7 +164,7 @@ func generateBakeStdlibDocs(filename string) error {
table.AddRow(fname, fdesc)
}

newContent := currentContent[:start] + "<!---MARKER_STDLIB_START-->\n\n" + table.String() + "\n" + currentContent[end:]
newContent := before + "<!---MARKER_STDLIB_START-->\n\n" + table.String() + "\n" + currentContent[end:]
return os.WriteFile(filename, []byte(newContent), 0644)
}

Expand Down
1 change: 0 additions & 1 deletion driver/remote/util/dialer_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package remoteutil

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/docker/buildx

go 1.24.3
go 1.25.0

require (
github.com/Masterminds/semver/v3 v3.4.0
Expand Down
22 changes: 18 additions & 4 deletions hack/dockerfiles/lint.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ ARG GO_VERSION=1.25
ARG ALPINE_VERSION=3.22
ARG XX_VERSION=1.7.0

ARG GOLANGCI_LINT_VERSION=v2.1.5
ARG GOLANGCI_LINT_VERSION=v2.8.0
ARG GOLANGCI_FROM_SOURCE=false
ARG GOPLS_VERSION=v0.33.0
ARG GOPLS_VERSION=v0.40.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"

Expand Down Expand Up @@ -60,16 +60,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
Expand Down
11 changes: 6 additions & 5 deletions tests/integration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"context"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -49,7 +50,7 @@ func withDir(dir string) cmdOpt {
}

func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
cmd := exec.Command("buildx")
cmd := exec.CommandContext(context.TODO(), "buildx")
cmd.Env = os.Environ()
for _, opt := range opts {
opt(cmd)
Expand All @@ -76,7 +77,7 @@ func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
}

func composeCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
cmd := exec.Command("compose")
cmd := exec.CommandContext(context.TODO(), "compose")
cmd.Env = os.Environ()
for _, opt := range opts {
opt(cmd)
Expand All @@ -100,7 +101,7 @@ func composeCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
}

func dockerCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
cmd := exec.Command("docker")
cmd := exec.CommandContext(context.TODO(), "docker")
cmd.Env = os.Environ()
for _, opt := range opts {
opt(cmd)
Expand Down Expand Up @@ -200,10 +201,10 @@ func buildkitVersion(t *testing.T, sb integration.Sandbox) string {
os.RemoveAll(destDir)
})

cmd := exec.Command(undockBin, "--cachedir", "/root/.cache/undock", "--include", "/usr/bin/buildkitd", "--rm-dist", buildkitImage, destDir)
cmd := exec.CommandContext(context.TODO(), undockBin, "--cachedir", "/root/.cache/undock", "--include", "/usr/bin/buildkitd", "--rm-dist", buildkitImage, destDir)
require.NoErrorf(t, cmd.Run(), "failed to extract buildkitd binary from %q", buildkitImage)

cmd = exec.Command(filepath.Join(destDir, "usr", "bin", "buildkitd"), "--version")
cmd = exec.CommandContext(context.TODO(), filepath.Join(destDir, "usr", "bin", "buildkitd"), "--version")
out, err := cmd.CombinedOutput()
require.NoErrorf(t, err, "failed to get BuildKit version from %q: %s", buildkitImage, string(out))

Expand Down
4 changes: 2 additions & 2 deletions tests/workers/docker-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (w *containerWorker) New(ctx context.Context, cfg *integration.BackendConfi
}
defer os.RemoveAll(filepath.Dir(cfgfile))
name := "integration-container-" + identity.NewID()
cmd := exec.Command("buildx", "create",
cmd := exec.CommandContext(ctx, "buildx", "create",
"--bootstrap",
"--name="+name,
"--buildkitd-config="+cfgfile,
Expand All @@ -75,7 +75,7 @@ func (w *containerWorker) New(ctx context.Context, cfg *integration.BackendConfi
}

cl := func() error {
cmd := exec.Command("buildx", "rm", "-f", name)
cmd := exec.CommandContext(context.Background(), "buildx", "rm", "-f", name)
cmd.Env = append(
os.Environ(),
"BUILDX_CONFIG=/tmp/buildx-"+name,
Expand Down
4 changes: 2 additions & 2 deletions tests/workers/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (
}

name := "integration-" + identity.NewID()
cmd := exec.Command("docker", "context", "create",
cmd := exec.CommandContext(ctx, "docker", "context", "create",
name,
"--docker", "host="+bk.DockerAddress(),
)
Expand All @@ -109,7 +109,7 @@ func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (

cl = func() error {
err := bkclose()
cmd := exec.Command("docker", "context", "rm", "-f", name)
cmd := exec.CommandContext(context.Background(), "docker", "context", "rm", "-f", name)
if err1 := cmd.Run(); err == nil {
err = errors.Wrapf(err1, "failed to remove buildx instance %s", name)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/workers/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (w remoteWorker) New(ctx context.Context, cfg *integration.BackendConfig) (
}

name := "integration-remote-" + identity.NewID()
cmd := exec.Command("buildx", "create",
cmd := exec.CommandContext(ctx, "buildx", "create",
"--bootstrap",
"--name="+name,
"--driver=remote",
Expand All @@ -55,7 +55,7 @@ func (w remoteWorker) New(ctx context.Context, cfg *integration.BackendConfig) (

cl = func() error {
err := bkclose()
cmd := exec.Command("buildx", "rm", "-f", name)
cmd := exec.CommandContext(context.Background(), "buildx", "rm", "-f", name)
cmd.Env = append(os.Environ(), "BUILDX_CONFIG=/tmp/buildx-"+name)
if err1 := cmd.Run(); err == nil {
err = err1
Expand Down
1 change: 0 additions & 1 deletion util/confutil/config_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package confutil

Expand Down
1 change: 0 additions & 1 deletion util/confutil/config_unix_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package confutil

Expand Down
Loading