@@ -2,9 +2,9 @@ package dap
22
33import (
44 "context"
5- "path"
65 "path/filepath"
76 "slices"
7+ "strings"
88 "sync"
99
1010 "github.com/docker/buildx/build"
@@ -31,10 +31,10 @@ type thread struct {
3131 variables * variableReferences
3232
3333 // Inputs to the evaluate call.
34- c gateway.Client
35- ref gateway.Reference
36- meta map [string ][]byte
37- sourcePath string
34+ c gateway.Client
35+ ref gateway.Reference
36+ meta map [string ][]byte
37+ sourceInfoMap func ( * pb. Source ) * pb. Source
3838
3939 // LLB state for the evaluate call.
4040 def * llb.Definition
@@ -107,14 +107,21 @@ func (t *thread) init(ctx Context, c gateway.Client, ref gateway.Reference, meta
107107 t .c = c
108108 t .ref = ref
109109 t .meta = meta
110-
111- // Combine the dockerfile directory with the context path to find the
112- // real base path. The frontend will report the base path as the filename.
113- dir := path .Dir (inputs .DockerfilePath )
114- if ! path .IsAbs (dir ) {
115- dir = path .Join (inputs .ContextPath , dir )
110+ t .sourceInfoMap = func (s * pb.Source ) * pb.Source {
111+ s = s .CloneVT ()
112+ for _ , sinfo := range s .Infos {
113+ // Map the filename from the source info from the frontend location to the
114+ // client location.
115+ fname := strings .Replace (sinfo .Filename , inputs .DockerfileMappingDst , inputs .DockerfileMappingSrc , 1 )
116+
117+ // Convert to an absolute path.
118+ if abspath , err := filepath .Abs (fname ); err == nil {
119+ fname = abspath
120+ }
121+ sinfo .Filename = fname
122+ }
123+ return s
116124 }
117- t .sourcePath = dir
118125
119126 if err := t .getLLBState (ctx ); err != nil {
120127 return err
@@ -252,7 +259,7 @@ func (t *thread) getStackFrame(dgst digest.Digest, next *step) *frame {
252259 f .setNameFromMeta (meta )
253260 }
254261 if loc , ok := t .def .Source .Locations [string (dgst )]; ok {
255- f .fillLocation (t .def , loc , t . sourcePath , next )
262+ f .fillLocation (t .def , loc , next )
256263 }
257264 t .frames [int32 (f .Id )] = f
258265 return f
@@ -296,7 +303,6 @@ func (t *thread) reset() {
296303 t .c = nil
297304 t .ref = nil
298305 t .meta = nil
299- t .sourcePath = ""
300306 t .ops = nil
301307}
302308
@@ -462,9 +468,12 @@ func (t *thread) getLLBState(ctx Context) error {
462468 return err
463469 }
464470
471+ if t .sourceInfoMap != nil {
472+ t .def .Source = t .sourceInfoMap (t .def .Source )
473+ }
474+
465475 for _ , src := range t .def .Source .Infos {
466- fname := filepath .Join (t .sourcePath , src .Filename )
467- t .sourceMap .Put (ctx , fname , src .Data )
476+ t .sourceMap .Put (ctx , src .Filename , src .Data )
468477 }
469478
470479 t .ops = make (map [digest.Digest ]* pb.Op , len (t .def .Def ))
@@ -483,7 +492,7 @@ func (t *thread) getLLBState(ctx Context) error {
483492}
484493
485494func (t * thread ) setBreakpoints (ctx Context ) {
486- t .bps = t .breakpointMap .Intersect (ctx , t .def .Source , t . sourcePath )
495+ t .bps = t .breakpointMap .Intersect (ctx , t .def .Source )
487496}
488497
489498func (t * thread ) seekNext (ctx Context , from * step , action stepType ) (string , * step , map [string ]gateway.Reference , error ) {
0 commit comments