github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/dist/buildmodule.go (about)

     1  package dist
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  
     6  	"github.com/buildpacks/pack/internal/style"
     7  )
     8  
     9  const AssumedBuildpackAPIVersion = "0.1"
    10  const BuildpacksDir = "/cnb/buildpacks"
    11  const ExtensionsDir = "/cnb/extensions"
    12  
    13  type ModuleInfo struct {
    14  	ID          string    `toml:"id,omitempty" json:"id,omitempty" yaml:"id,omitempty"`
    15  	Name        string    `toml:"name,omitempty" json:"name,omitempty" yaml:"name,omitempty"`
    16  	Version     string    `toml:"version,omitempty" json:"version,omitempty" yaml:"version,omitempty"`
    17  	Description string    `toml:"description,omitempty" json:"description,omitempty" yaml:"description,omitempty"`
    18  	Homepage    string    `toml:"homepage,omitempty" json:"homepage,omitempty" yaml:"homepage,omitempty"`
    19  	Keywords    []string  `toml:"keywords,omitempty" json:"keywords,omitempty" yaml:"keywords,omitempty"`
    20  	Licenses    []License `toml:"licenses,omitempty" json:"licenses,omitempty" yaml:"licenses,omitempty"`
    21  }
    22  
    23  func (b ModuleInfo) FullName() string {
    24  	if b.Version != "" {
    25  		return b.ID + "@" + b.Version
    26  	}
    27  	return b.ID
    28  }
    29  
    30  func (b ModuleInfo) FullNameWithVersion() (string, error) {
    31  	if b.Version == "" {
    32  		return b.ID, errors.Errorf("buildpack %s does not have a version defined", style.Symbol(b.ID))
    33  	}
    34  	return b.ID + "@" + b.Version, nil
    35  }
    36  
    37  // Satisfy stringer
    38  func (b ModuleInfo) String() string { return b.FullName() }
    39  
    40  // Match compares two buildpacks by ID and Version
    41  func (b ModuleInfo) Match(o ModuleInfo) bool {
    42  	return b.ID == o.ID && b.Version == o.Version
    43  }
    44  
    45  type License struct {
    46  	Type string `toml:"type"`
    47  	URI  string `toml:"uri"`
    48  }
    49  
    50  type Stack struct {
    51  	ID     string   `json:"id" toml:"id"`
    52  	Mixins []string `json:"mixins,omitempty" toml:"mixins,omitempty"`
    53  }
    54  
    55  type Target struct {
    56  	OS            string         `json:"os" toml:"os"`
    57  	Arch          string         `json:"arch" toml:"arch"`
    58  	ArchVariant   string         `json:"variant,omitempty" toml:"variant,omitempty"`
    59  	Distributions []Distribution `json:"distros,omitempty" toml:"distros,omitempty"`
    60  }
    61  
    62  type Distribution struct {
    63  	Name    string `json:"name,omitempty" toml:"name,omitempty"`
    64  	Version string `json:"version,omitempty" toml:"version,omitempty"`
    65  }