Skip to content

Commit

Permalink
Merge pull request #1437 from imnitishng/05-05-bp-order-missing
Browse files Browse the repository at this point in the history
Update error when bp order group is malformed for meta-buildpacks
  • Loading branch information
jromero authored Jun 7, 2022
2 parents 1e6ba9c + d9b834e commit 1c191ac
Show file tree
Hide file tree
Showing 3 changed files with 60 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 @@ -269,15 +269,24 @@ func validateBuildpacks(mainBP Buildpack, depBPs []Buildpack) error {
bpd := bp.Descriptor()
for _, orderEntry := range bpd.Order {
for _, groupEntry := range orderEntry.Group {
if _, ok := depsWithRefs[groupEntry.BuildpackInfo.FullName()]; !ok {
bpFullName, err := groupEntry.BuildpackInfo.FullNameWithVersion()
if err != nil {
return errors.Wrapf(
err,
"buildpack %s must specify a version when referencing buildpack %s",
style.Symbol(bpd.Info.FullName()),
style.Symbol(bpFullName),
)
}
if _, ok := depsWithRefs[bpFullName]; !ok {
return errors.Errorf(
"buildpack %s references buildpack %s which is not present",
style.Symbol(bpd.Info.FullName()),
style.Symbol(groupEntry.FullName()),
style.Symbol(bpFullName),
)
}

depsWithRefs[groupEntry.BuildpackInfo.FullName()] = append(depsWithRefs[groupEntry.BuildpackInfo.FullName()], bpd.Info)
depsWithRefs[bpFullName] = append(depsWithRefs[bpFullName], bpd.Info)
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/buildpack/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,41 @@ func testPackageBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertError(t, err, "buildpack '[email protected]' references buildpack '[email protected]' which is not present")
})
})

when("there is a referenced buildpack from dependency buildpack that does not have proper version defined", func() {
it("should error", func() {
mainBP, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
API: api.MustParse("0.2"),
Info: dist.BuildpackInfo{
ID: "bp.1.id",
Version: "bp.1.version",
},
Order: dist.Order{{
Group: []dist.BuildpackRef{
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.present.id", Version: "bp.present.version"}},
},
}},
}, 0644)
h.AssertNil(t, err)
builder := buildpack.NewBuilder(mockImageFactory(expectedImageOS))
builder.SetBuildpack(mainBP)

presentBP, err := ifakes.NewFakeBuildpack(dist.BuildpackDescriptor{
API: api.MustParse("0.2"),
Info: dist.BuildpackInfo{ID: "bp.present.id", Version: "bp.present.version"},
Order: dist.Order{{
Group: []dist.BuildpackRef{
{BuildpackInfo: dist.BuildpackInfo{ID: "bp.missing.id"}},
},
}},
}, 0644)
h.AssertNil(t, err)
builder.AddDependency(presentBP)

err = testFn(builder)
h.AssertError(t, err, "buildpack '[email protected]' must specify a version when referencing buildpack 'bp.missing.id'")
})
})
})

when("validate stacks", func() {
Expand Down
13 changes: 13 additions & 0 deletions pkg/dist/buildpack.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package dist

import (
"github.com/pkg/errors"

"github.com/buildpacks/pack/internal/style"
)

const AssumedBuildpackAPIVersion = "0.1"
const BuildpacksDir = "/cnb/buildpacks"

Expand All @@ -20,6 +26,13 @@ func (b BuildpackInfo) FullName() string {
return b.ID
}

func (b BuildpackInfo) FullNameWithVersion() (string, error) {
if b.Version == "" {
return b.ID, errors.Errorf("buildpack %s does not have a version defined", style.Symbol(b.ID))
}
return b.ID + "@" + b.Version, nil
}

// Satisfy stringer
func (b BuildpackInfo) String() string { return b.FullName() }

Expand Down

0 comments on commit 1c191ac

Please sign in to comment.