github.com/YousefHaggyHeroku/pack@v1.5.5/internal/dist/buildpack_descriptor.go (about) 1 package dist 2 3 import ( 4 "fmt" 5 "sort" 6 "strings" 7 8 "github.com/buildpacks/lifecycle/api" 9 10 "github.com/YousefHaggyHeroku/pack/internal/stringset" 11 "github.com/YousefHaggyHeroku/pack/internal/style" 12 ) 13 14 type BuildpackDescriptor struct { 15 API *api.Version `toml:"api"` 16 Info BuildpackInfo `toml:"buildpack"` 17 Stacks []Stack `toml:"stacks"` 18 Order Order `toml:"order"` 19 } 20 21 func (b *BuildpackDescriptor) EscapedID() string { 22 return strings.Replace(b.Info.ID, "/", "_", -1) 23 } 24 25 func (b *BuildpackDescriptor) EnsureStackSupport(stackID string, providedMixins []string, validateRunStageMixins bool) error { 26 if len(b.Stacks) == 0 { 27 return nil // Order buildpack, no validation required 28 } 29 30 bpMixins, err := b.findMixinsForStack(stackID) 31 if err != nil { 32 return err 33 } 34 35 if !validateRunStageMixins { 36 var filtered []string 37 for _, m := range bpMixins { 38 if !strings.HasPrefix(m, "run:") { 39 filtered = append(filtered, m) 40 } 41 } 42 bpMixins = filtered 43 } 44 45 _, missing, _ := stringset.Compare(providedMixins, bpMixins) 46 if len(missing) > 0 { 47 sort.Strings(missing) 48 return fmt.Errorf("buildpack %s requires missing mixin(s): %s", style.Symbol(b.Info.FullName()), strings.Join(missing, ", ")) 49 } 50 return nil 51 } 52 53 func (b *BuildpackDescriptor) findMixinsForStack(stackID string) ([]string, error) { 54 for _, s := range b.Stacks { 55 if s.ID == stackID { 56 return s.Mixins, nil 57 } 58 } 59 return nil, fmt.Errorf("buildpack %s does not support stack %s", style.Symbol(b.Info.FullName()), style.Symbol(stackID)) 60 }