From 85e968209124e339515f0616da0c014233db9b3b Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Mon, 26 Feb 2024 13:06:10 -0600 Subject: [PATCH 1/3] Add a test for non-meta buildpack with empty stacks Signed-off-by: Josh W Lewis --- pkg/buildpack/builder_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/buildpack/builder_test.go b/pkg/buildpack/builder_test.go index 5138fcad81..3abdeecb24 100644 --- a/pkg/buildpack/builder_test.go +++ b/pkg/buildpack/builder_test.go @@ -244,6 +244,25 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) { }) when("validate stacks", func() { + when("buildpack does not define stacks", func() { + it("should succeed", func() { + bp, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ + WithAPI: api.MustParse("0.10"), + WithInfo: dist.ModuleInfo{ + ID: "bp.1.id", + Version: "bp.1.version", + }, + WithStacks: nil, + WithOrder: nil, + }, 0644) + h.AssertNil(t, err) + builder := buildpack.NewBuilder(mockImageFactory(expectedImageOS)) + builder.SetBuildpack(bp) + err = testFn(builder) + h.AssertNil(t, err) + }) + }) + when("buildpack is meta-buildpack", func() { it("should succeed", func() { bp, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{ From 03cfdef3d0ef50fad91dfc2c46248a61d15253bf Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Mon, 26 Feb 2024 13:24:26 -0600 Subject: [PATCH 2/3] Assume non-meta buildpacks without stacks use any stack Signed-off-by: Josh W Lewis --- pkg/buildpack/builder.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/buildpack/builder.go b/pkg/buildpack/builder.go index 443f0de322..b76dccc74f 100644 --- a/pkg/buildpack/builder.go +++ b/pkg/buildpack/builder.go @@ -330,13 +330,22 @@ func (b *PackageBuilder) validate() error { func (b *PackageBuilder) resolvedStacks() []dist.Stack { stacks := b.buildpack.Descriptor().Stacks() + if len(stacks) == 0 && len(b.buildpack.Descriptor().Order()) == 0 { + // For non-meta-buildpacks using targets, not stacks: assume any stack + stacks = append(stacks, dist.Stack{ID: "*"}) + } for _, bp := range b.AllModules() { bpd := bp.Descriptor() + bpdStacks := bp.Descriptor().Stacks() + if len(bpdStacks) == 0 && len(bpd.Order()) == 0 { + // For non-meta-buildpacks using targets, not stacks: assume any stack + bpdStacks = append(stacks, dist.Stack{ID: "*"}) + } if len(stacks) == 0 { - stacks = bpd.Stacks() - } else if len(bpd.Stacks()) > 0 { // skip over "meta-buildpacks" - stacks = stack.MergeCompatible(stacks, bpd.Stacks()) + stacks = bpdStacks + } else if len(bpdStacks) > 0 { // skip over "meta-buildpacks" + stacks = stack.MergeCompatible(stacks, bpdStacks) } } From 7a5d93b2c76e8ed4fd9f632bc3cfb9855a087f73 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Mon, 26 Feb 2024 14:18:19 -0600 Subject: [PATCH 3/3] Fix incorrect append argument Signed-off-by: Josh W Lewis --- pkg/buildpack/builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/buildpack/builder.go b/pkg/buildpack/builder.go index b76dccc74f..14006b6b67 100644 --- a/pkg/buildpack/builder.go +++ b/pkg/buildpack/builder.go @@ -339,7 +339,7 @@ func (b *PackageBuilder) resolvedStacks() []dist.Stack { bpdStacks := bp.Descriptor().Stacks() if len(bpdStacks) == 0 && len(bpd.Order()) == 0 { // For non-meta-buildpacks using targets, not stacks: assume any stack - bpdStacks = append(stacks, dist.Stack{ID: "*"}) + bpdStacks = append(bpdStacks, dist.Stack{ID: "*"}) } if len(stacks) == 0 {