Skip to content

Commit 3e4bd22

Browse files
committed
dap: skip the load build context step when it doesn't have an associated source line
Skip the load build context step when it doesn't have an associated source line. This caused an extra branch to be created in an otherwise pretty straightforward dockerfile where stepping in on a copy instruction that used the context would stay on the same line because it "stepped into" the context loading rather than being treated the same as step next. This resulted in some bad and confusing ergonomics with the cursor position that were a bit confusing and unexpected. There might be more areas to try and prune but the most common one, a single branch instruction that doesn't have a location, now gets skipped which is the exact thing that was generated for loading the context. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
1 parent a5f49f0 commit 3e4bd22

2 files changed

Lines changed: 14 additions & 49 deletions

File tree

dap/thread.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ func (t *thread) createBranch(dgst digest.Digest, exitpoint *step) (entrypoint *
173173
parent: -1,
174174
}
175175

176+
// The entrypoint doesn't have a source entry. Just skip this
177+
// branch.
178+
if entrypoint.frame.Source == nil {
179+
return nil
180+
}
181+
176182
// Create a pseudo-frame and attach it to the return point.
177183
// This is mostly used for getting the correct inputs utilized
178184
// by this frame.
@@ -216,11 +222,18 @@ func (t *thread) createBranch(dgst digest.Digest, exitpoint *step) (entrypoint *
216222
inp := op.Inputs[i]
217223

218224
head := *entrypoint
219-
entrypoint.dgst = ""
220225

221226
// Create the routine associated with this input.
222227
// Associate it with the entrypoint in step.
223228
head.in = t.createBranch(digest.Digest(inp.Digest), entrypoint)
229+
230+
// If this branch is empty (signified by a nil return value) then
231+
// skip it.
232+
if head.in == nil {
233+
continue
234+
}
235+
236+
entrypoint.dgst = ""
224237
entrypoint = &head
225238
}
226239

tests/dap_build.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -299,54 +299,6 @@ func testDapBuildStepIn(t *testing.T, sb integration.Sandbox) {
299299
Name: `^\[stage-1 .*\] COPY .* /etc/bar`,
300300
},
301301
},
302-
// the following three steps are unintended and are the result
303-
// of a bug in the debug adapter.
304-
// see issue https://github.com/docker/buildx/issues/3565
305-
{
306-
{
307-
Name: `^\[internal\] load build context`,
308-
},
309-
{
310-
SourceName: "Dockerfile",
311-
Line: 3,
312-
Name: `^\[base .*\] COPY foo`,
313-
},
314-
{
315-
SourceName: "Dockerfile",
316-
Line: 7,
317-
Name: `^\[stage-1 .*\] COPY .* /etc/bar`,
318-
},
319-
},
320-
// todo: this shouldn't be a stop point.
321-
{
322-
{
323-
Name: `^\[internal\] load build context`,
324-
},
325-
{
326-
SourceName: "Dockerfile",
327-
Line: 3,
328-
Name: `^\[base .*\] COPY foo`,
329-
},
330-
{
331-
SourceName: "Dockerfile",
332-
Line: 7,
333-
Name: `^\[stage-1 .*\] COPY .* /etc/bar`,
334-
},
335-
},
336-
// duplicate of stop point 3 because of unintended branch
337-
// associated with the build context copy.
338-
{
339-
{
340-
SourceName: "Dockerfile",
341-
Line: 3,
342-
Name: `^\[base .*\] COPY foo`,
343-
},
344-
{
345-
SourceName: "Dockerfile",
346-
Line: 7,
347-
Name: `^\[stage-1 .*\] COPY .* /etc/bar`,
348-
},
349-
},
350302
// stop point 4
351303
{
352304
{

0 commit comments

Comments
 (0)