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
40 changes: 40 additions & 0 deletions build/result.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package build

import (
"cmp"
"context"
_ "crypto/sha256" // ensure digests can be computed
"encoding/json"
"io"
iofs "io/fs"
"path/filepath"
"slices"
"strings"
"sync"

"github.com/moby/buildkit/exporter/containerimage/exptypes"
Expand All @@ -14,6 +19,7 @@ import (
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/tonistiigi/fsutil/types"
)

// NewResultHandle stores a gateway client, gateway reference, and the error from
Expand Down Expand Up @@ -75,6 +81,40 @@ func (r *ResultHandle) NewContainer(ctx context.Context, cfg *InvokeConfig) (gat
return r.gwClient.NewContainer(ctx, req)
}

func (r *ResultHandle) StatFile(ctx context.Context, fpath string, cfg *InvokeConfig) (*types.Stat, error) {
containerCfg, err := r.getContainerConfig(cfg)
if err != nil {
return nil, err
}

candidateMounts := make([]gateway.Mount, 0, len(containerCfg.Mounts))
for _, m := range containerCfg.Mounts {
if strings.HasPrefix(fpath, m.Dest) {
candidateMounts = append(candidateMounts, m)
}
}
if len(candidateMounts) == 0 {
return nil, iofs.ErrNotExist
}

slices.SortFunc(candidateMounts, func(a, b gateway.Mount) int {
return cmp.Compare(len(a.Dest), len(b.Dest))
})

m := candidateMounts[len(candidateMounts)-1]
relpath, err := filepath.Rel(m.Dest, fpath)
if err != nil {
return nil, err
}

if m.Ref == nil {
return nil, iofs.ErrNotExist
}

req := gateway.StatRequest{Path: filepath.ToSlash(relpath)}
return m.Ref.StatFile(ctx, req)
}

func (r *ResultHandle) getContainerConfig(cfg *InvokeConfig) (containerCfg gateway.NewContainerRequest, _ error) {
if r.ref != nil && r.solveErr == nil {
logrus.Debugf("creating container from successful build")
Expand Down
39 changes: 16 additions & 23 deletions dap/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ type Adapter[C LaunchConfig] struct {
threadsMu sync.RWMutex
nextThreadID int

sharedState
}

type sharedState struct {
breakpointMap *breakpointMap
sourceMap sourceMap
sourceMap *sourceMap
idPool *idPool
sh *shell
}

func New[C LaunchConfig]() *Adapter[C] {
Expand All @@ -51,8 +56,12 @@ func New[C LaunchConfig]() *Adapter[C] {
evaluateReqCh: make(chan *evaluateRequest),
threads: make(map[int]*thread),
nextThreadID: 1,
breakpointMap: newBreakpointMap(),
idPool: new(idPool),
sharedState: sharedState{
breakpointMap: newBreakpointMap(),
sourceMap: new(sourceMap),
idPool: new(idPool),
sh: newShell(),
},
}
d.srv = NewServer(d.dapHandler())
return d
Expand Down Expand Up @@ -233,12 +242,10 @@ func (d *Adapter[C]) newThread(ctx Context, name string) (t *thread) {
d.threadsMu.Lock()
id := d.nextThreadID
t = &thread{
id: id,
name: name,
sourceMap: &d.sourceMap,
breakpointMap: d.breakpointMap,
idPool: d.idPool,
variables: newVariableReferences(),
id: id,
name: name,
sharedState: d.sharedState,
variables: newVariableReferences(),
}
d.threads[t.id] = t
d.nextThreadID++
Expand All @@ -261,20 +268,6 @@ func (d *Adapter[C]) getThread(id int) (t *thread) {
return t
}

func (d *Adapter[C]) getFirstThread() (t *thread) {
d.threadsMu.Lock()
defer d.threadsMu.Unlock()

for _, thread := range d.threads {
if thread.isPaused() {
if t == nil || thread.id < t.id {
t = thread
}
}
}
return t
}

func (d *Adapter[C]) deleteThread(ctx Context, t *thread) {
d.threadsMu.Lock()
if t := d.threads[t.id]; t != nil {
Expand Down
Loading