Skip to content

Commit

Permalink
Merge pull request #2081 from joshwlewis/support-empty-stacks
Browse files Browse the repository at this point in the history
Add validation support for empty/nil `[[stacks]]`
  • Loading branch information
jjbustamante authored Feb 28, 2024
2 parents 3356686 + a0bb25e commit ea5a48a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/buildpack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(bpdStacks, 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)
}
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/buildpack/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit ea5a48a

Please sign in to comment.