forked from buildpacks/lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildpack.go
55 lines (45 loc) · 1.27 KB
/
buildpack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package lifecycle
import (
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/buildpacks/lifecycle/launch"
)
type Buildpack struct {
ID string `toml:"id" json:"id"`
Version string `toml:"version" json:"version"`
Optional bool `toml:"optional,omitempty" json:"optional,omitempty"`
}
func (bp Buildpack) String() string {
return bp.ID + "@" + bp.Version
}
func (bp Buildpack) noOpt() Buildpack {
bp.Optional = false
return bp
}
func (bp Buildpack) lookup(buildpacksDir string) (*buildpackTOML, error) {
bpTOML := buildpackTOML{}
bpPath, err := filepath.Abs(filepath.Join(buildpacksDir, launch.EscapeID(bp.ID), bp.Version))
if err != nil {
return nil, err
}
tomlPath := filepath.Join(bpPath, "buildpack.toml")
if _, err := toml.DecodeFile(tomlPath, &bpTOML); err != nil {
return nil, err
}
bpTOML.Path = bpPath
return &bpTOML, nil
}
type buildpackTOML struct {
Buildpack buildpackInfo `toml:"buildpack"`
Order BuildpackOrder `toml:"order"`
Path string `toml:"-"`
}
type buildpackInfo struct {
ID string `toml:"id"`
Version string `toml:"version"`
Name string `toml:"name"`
ClearEnv bool `toml:"clear-env,omitempty"`
}
func (bp buildpackTOML) String() string {
return bp.Buildpack.Name + " " + bp.Buildpack.Version
}