Skip to content

Commit 68d984b

Browse files
committed
Fix patching from dir with gomod generator
This is just a difference in how the states are stored when there is a subpath in a directory that is the patch source (as compared to a patch file). Signed-off-by: Brian Goff <[email protected]>
1 parent 20db3e7 commit 68d984b

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

source.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,14 @@ func patchSource(worker, sourceState llb.State, sourceToState map[string]llb.Sta
527527
patchState := sourceToState[p.Source]
528528
// on each iteration, mount source state to /src to run `patch`, and
529529
// set the state under /src to be the source state for the next iteration
530+
531+
subPath := p.Source
532+
if p.Path != "" {
533+
subPath = p.Path
534+
}
535+
530536
sourceState = worker.Run(
531-
llb.AddMount("/patch", patchState, llb.Readonly, llb.SourcePath(filepath.Join(p.Source, p.Path))),
537+
llb.AddMount("/patch", patchState, llb.Readonly, llb.SourcePath(subPath)),
532538
llb.Dir("src"),
533539
ShArgs(fmt.Sprintf("patch -p%d < /patch", *p.Strip)),
534540
WithConstraints(opts...),

test/source_test.go

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ index ea874f5..ba38f84 100644
260260

261261
// Note: module here should be moduyle+version because this is checking the go module path on disk
262262
checkModule := func(ctx context.Context, gwc gwclient.Client, module string, spec *dalec.Spec) {
263+
t.Helper()
263264
res, err := gwc.Solve(ctx, newSolveRequest(withBuildTarget("debug/gomods"), withSpec(ctx, t, spec)))
264265
if err != nil {
265266
t.Fatal(err)
@@ -314,24 +315,49 @@ index ea874f5..ba38f84 100644
314315
})
315316

316317
t.Run("with patch", func(t *testing.T) {
317-
t.Parallel()
318-
testEnv.RunTest(baseCtx, t, func(ctx context.Context, gwc gwclient.Client) {
319-
spec := baseSpec()
318+
t.Run("file", func(t *testing.T) {
319+
t.Parallel()
320+
testEnv.RunTest(baseCtx, t, func(ctx context.Context, gwc gwclient.Client) {
321+
spec := baseSpec()
320322

321-
patchName := "patch"
322-
spec.Sources[patchName] = dalec.Source{
323-
Inline: &dalec.SourceInline{
324-
File: &dalec.SourceInlineFile{
325-
Contents: downgradePatch,
323+
patchName := "patch"
324+
spec.Sources[patchName] = dalec.Source{
325+
Inline: &dalec.SourceInline{
326+
File: &dalec.SourceInlineFile{
327+
Contents: downgradePatch,
328+
},
326329
},
327-
},
328-
}
330+
}
329331

330-
spec.Patches = map[string][]dalec.PatchSpec{
331-
srcName: {{Source: patchName}},
332-
}
332+
spec.Patches = map[string][]dalec.PatchSpec{
333+
srcName: {{Source: patchName}},
334+
}
333335

334-
checkModule(ctx, gwc, "github.com/cpuguy83/[email protected]", spec)
336+
checkModule(ctx, gwc, "github.com/cpuguy83/[email protected]", spec)
337+
})
338+
})
339+
t.Run("dir", func(t *testing.T) {
340+
t.Parallel()
341+
testEnv.RunTest(baseCtx, t, func(ctx context.Context, gwc gwclient.Client) {
342+
spec := baseSpec()
343+
344+
patchName := "patch"
345+
spec.Sources[patchName] = dalec.Source{
346+
Inline: &dalec.SourceInline{
347+
Dir: &dalec.SourceInlineDir{
348+
Files: map[string]*dalec.SourceInlineFile{
349+
"patch-file": {Contents: downgradePatch},
350+
},
351+
},
352+
},
353+
}
354+
355+
spec.Patches = map[string][]dalec.PatchSpec{
356+
srcName: {{Source: patchName, Path: "patch-file"}},
357+
}
358+
359+
checkModule(ctx, gwc, "github.com/cpuguy83/[email protected]", spec)
360+
})
335361
})
336362
})
337363
}

0 commit comments

Comments
 (0)