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
4 changes: 2 additions & 2 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, debugOpts debuggerOpti
desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term)
}
if options.imageIDFile != "" {
if err := os.WriteFile(options.imageIDFile, []byte(getImageID(resp.ExporterResponse)), 0644); err != nil {
if err := os.WriteFile(options.imageIDFile, []byte(getImageID(resp.ExporterResponse)), 0o644); err != nil {
return errors.Wrap(err, "writing image ID file")
}
}
Expand Down Expand Up @@ -655,7 +655,7 @@ func writeMetadataFile(filename string, dt any) error {
if err != nil {
return err
}
return atomicwriter.WriteFile(filename, b, 0644)
return atomicwriter.WriteFile(filename, b, 0o644)
}

func decodeExporterResponse(exporterResponse map[string]string) map[string]any {
Expand Down
5 changes: 3 additions & 2 deletions dap/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,9 @@ func newBreakpointMap() *breakpointMap {
func (b *breakpointMap) Set(fname string, sbps []dap.SourceBreakpoint) (breakpoints []dap.Breakpoint) {
b.mu.Lock()
defer b.mu.Unlock()
// explicitly initialize breakpoints so that
// we do not send a null back in the JSON if there are no breakpoints

// Explicitly initialize breakpoints so that we do not send a
// null back in the JSON if there are no breakpoints
breakpoints = []dap.Breakpoint{}

prev := b.byPath[fname]
Expand Down
59 changes: 11 additions & 48 deletions dap/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package dap

import (
"context"
"encoding/json"
"fmt"
"io"
"path/filepath"
"testing"
"time"

"github.com/docker/buildx/dap/common"
"github.com/docker/buildx/util/daptest"
"github.com/google/go-dap"
"github.com/moby/buildkit/solver/pb"
"github.com/stretchr/testify/assert"
Expand All @@ -36,20 +36,20 @@ func TestLaunch(t *testing.T) {

client.RegisterEvent("initialized", func(em dap.EventMessage) {
// Send configuration done since we don't do any configuration.
configurationDone = DoRequest[*dap.ConfigurationDoneResponse](t, client, &dap.ConfigurationDoneRequest{
configurationDone = daptest.DoRequest[*dap.ConfigurationDoneResponse](t, client, &dap.ConfigurationDoneRequest{
Request: dap.Request{Command: "configurationDone"},
})
close(initialized)
})

eg.Go(func() error {
initializeResp := <-DoRequest[*dap.InitializeResponse](t, client, &dap.InitializeRequest{
initializeResp := <-daptest.DoRequest[*dap.InitializeResponse](t, client, &dap.InitializeRequest{
Request: dap.Request{Command: "initialize"},
})
assert.True(t, initializeResp.Success)
assert.True(t, initializeResp.Body.SupportsConfigurationDoneRequest)

launchResp := <-DoRequest[*dap.LaunchResponse](t, client, &dap.LaunchRequest{
launchResp := <-daptest.DoRequest[*dap.LaunchResponse](t, client, &dap.LaunchRequest{
Request: dap.Request{Command: "launch"},
})
assert.True(t, launchResp.Success)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestSetBreakpoints(t *testing.T) {
)

client.RegisterEvent("initialized", func(em dap.EventMessage) {
setBreakpoints = DoRequest[*dap.SetBreakpointsResponse](t, client, &dap.SetBreakpointsRequest{
setBreakpoints = daptest.DoRequest[*dap.SetBreakpointsResponse](t, client, &dap.SetBreakpointsRequest{
Request: dap.Request{Command: "setBreakpoints"},
Arguments: dap.SetBreakpointsArguments{
Source: dap.Source{Name: "Dockerfile", Path: filepath.Join(t.TempDir(), "Dockerfile")},
Expand All @@ -104,13 +104,13 @@ func TestSetBreakpoints(t *testing.T) {
})

eg.Go(func() error {
initializeResp := <-DoRequest[*dap.InitializeResponse](t, client, &dap.InitializeRequest{
initializeResp := <-daptest.DoRequest[*dap.InitializeResponse](t, client, &dap.InitializeRequest{
Request: dap.Request{Command: "initialize"},
})
assert.True(t, initializeResp.Success)
assert.True(t, initializeResp.Body.SupportsConfigurationDoneRequest)

launchResp := <-DoRequest[*dap.LaunchResponse](t, client, &dap.LaunchRequest{
launchResp := <-daptest.DoRequest[*dap.LaunchResponse](t, client, &dap.LaunchRequest{
Request: dap.Request{Command: "launch"},
})
assert.True(t, launchResp.Success)
Expand Down Expand Up @@ -234,66 +234,29 @@ func TestBreakpointMapIntersectVerified(t *testing.T) {
}
}

func NewTestAdapter[C LaunchConfig](t *testing.T) (*Adapter[C], Conn, *Client) {
func NewTestAdapter[C LaunchConfig](t *testing.T) (*Adapter[C], Conn, *daptest.Client) {
t.Helper()

rd1, wr1 := io.Pipe()
rd2, wr2 := io.Pipe()

srvConn := logConn(t, "server", NewConn(rd1, wr2))
srvConn := daptest.LogConn(t, "server", NewConn(rd1, wr2))
t.Cleanup(func() {
srvConn.Close()
})

clientConn := logConn(t, "client", NewConn(rd2, wr1))
clientConn := daptest.LogConn(t, "client", NewConn(rd2, wr1))
t.Cleanup(func() { clientConn.Close() })

adapter := New[C]()
t.Cleanup(func() { adapter.Stop() })

client := NewClient(clientConn)
client := daptest.NewClient(clientConn)
t.Cleanup(func() { client.Close() })

return adapter, srvConn, client
}

func logConn(t *testing.T, prefix string, conn Conn) Conn {
return &loggingConn{
Conn: conn,
t: t,
prefix: prefix,
}
}

type loggingConn struct {
Conn
t *testing.T
prefix string
}

func (c *loggingConn) SendMsg(m dap.Message) error {
b, _ := json.Marshal(m)
c.t.Logf("[%s] send: %v", c.prefix, string(b))

err := c.Conn.SendMsg(m)
if err != nil {
c.t.Logf("[%s] send error: %v", c.prefix, err)
}
return err
}

func (c *loggingConn) RecvMsg(ctx context.Context) (dap.Message, error) {
m, err := c.Conn.RecvMsg(ctx)
if err != nil {
c.t.Logf("[%s] recv error: %v", c.prefix, err)
return nil, err
}

b, _ := json.Marshal(m)
c.t.Logf("[%s] recv: %v", c.prefix, string(b))
return m, nil
}

type breakpointTestContext struct {
context.Context
messages chan dap.Message
Expand Down
1 change: 1 addition & 0 deletions dap/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package dap
14 changes: 14 additions & 0 deletions dap/common/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package common

import (
"context"
"io"

"github.com/google/go-dap"
)

type Conn interface {
SendMsg(m dap.Message) error
RecvMsg(ctx context.Context) (dap.Message, error)
io.Closer
}
7 changes: 2 additions & 5 deletions dap/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import (
"io"
"sync"

"github.com/docker/buildx/dap/common"
"github.com/google/go-dap"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)

type Conn interface {
SendMsg(m dap.Message) error
RecvMsg(ctx context.Context) (dap.Message, error)
io.Closer
}
type Conn = common.Conn

type conn struct {
recvCh <-chan dap.Message
Expand Down
Loading