Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
update to the new buildplan spec
Browse files Browse the repository at this point in the history
[#167920584]

Co-authored-by: Forest Eckhardt <[email protected]>
  • Loading branch information
dwillist and ForestEckhardt committed Aug 15, 2019
1 parent 9929fe7 commit 1516250
Show file tree
Hide file tree
Showing 44 changed files with 409 additions and 210 deletions.
9 changes: 4 additions & 5 deletions cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package main

import (
"fmt"
"github.com/cloudfoundry/libcfbuildpack/buildpackplan"
"os"

"github.com/cloudfoundry/dep-cnb/dep"
"github.com/cloudfoundry/dep-cnb/utils"

"github.com/buildpack/libbuildpack/buildplan"

"github.com/cloudfoundry/libcfbuildpack/build"
)

Expand All @@ -21,15 +20,15 @@ func main() {

code, err := runBuild(context)
if err != nil {
context.Logger.Error("failure running build: %s", err.Error())
context.Logger.BodyError("failure running build: %s", err.Error())
}

os.Exit(code)

}

func runBuild(context build.Build) (int, error) {
context.Logger.FirstLine(context.Logger.PrettyIdentity(context.Buildpack))
context.Logger.Title(context.Buildpack)

runner := &utils.Command{}

Expand All @@ -44,5 +43,5 @@ func runBuild(context build.Build) (int, error) {
}
}

return context.Success(buildplan.BuildPlan{})
return context.Success(buildpackplan.Plan{})
}
20 changes: 14 additions & 6 deletions cmd/detect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,24 @@ func runDetect(context detect.Detect) (int, error) {
metadata[dep.Targets] = buildpackYaml.Config.Targets
}

return context.Pass(buildplan.BuildPlan{
dep.Dependency: buildplan.Dependency{
return context.Pass(buildplan.Plan{
Provides: []buildplan.Provided{{
Name: dep.Dependency,
}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: metadata,
},
}},
})
}

return context.Pass(buildplan.BuildPlan{
dep.Dependency: buildplan.Dependency{
return context.Pass(buildplan.Plan{
Provides: []buildplan.Provided{{
Name: dep.Dependency,
}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: buildplan.Metadata{"build": true},
},
}},
})
}
145 changes: 79 additions & 66 deletions cmd/detect/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,101 +46,114 @@ func testDetect(t *testing.T, when spec.G, it spec.S) {
code, err := runDetect(factory.Detect)
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))
Expect(factory.Output[dep.Dependency].Metadata).NotTo(HaveKey(dep.ImportPath))
Expect(factory.Output[dep.Dependency].Metadata).NotTo(HaveKey(dep.Targets))
Expect(factory.Output[dep.Dependency].Metadata).To(HaveKey("build"))
Expect(factory.Plans.Plan).To(Equal(buildplan.Plan{
Provides: []buildplan.Provided{{Name: dep.Dependency}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: buildplan.Metadata{"build": true},
}},
}))
})
})

when("Gopkg.toml exists and buildpack.yml specifies an `import-path` and go targets", func() {
when("Gopkg.toml exists and buildpack.yml specifies an `import-path` and go targets", func() {

var bpYmlString string
var bpYmlString string

it.Before(func() {
bpYmlString = `---
it.Before(func() {
bpYmlString = `---
go:
import-path: some/app
targets: ["./path/to/first", "./path/to/second"]`
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "buildpack.yml"), bpYmlString)
goPkgString := fmt.Sprintf("This is a go pkg toml")
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "Gopkg.toml"), goPkgString)
})

it.After(func() {
Expect(os.Unsetenv("BP_GO_TARGETS")).To(Succeed())
})

it("adds the `import-path` and targets to the build plan", func() {

code, err := runDetect(factory.Detect)
Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "buildpack.yml"), bpYmlString)
goPkgString := fmt.Sprintf("This is a go pkg toml")
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "Gopkg.toml"), goPkgString)
})

plan := buildplan.BuildPlan{
dep.Dependency: buildplan.Dependency{
Metadata: buildplan.Metadata{
"build": true,
"import-path": "some/app",
"targets": []string{"./path/to/first", "./path/to/second"},
},
},
}

Expect(factory.Output).To(Equal(plan))
})
it.After(func() {
Expect(os.Unsetenv("BP_GO_TARGETS")).To(Succeed())
})

when("BP_GO_TARGETS environment variable is set", func() {
it("should use the BP_GO_TARGETS value in the build plan", func() {
err := os.Setenv("BP_GO_TARGETS", "./path/to/third:./path/to/fourth")
Expect(err).NotTo(HaveOccurred())
it("adds the `import-path` and targets to the build plan", func() {

code, err := runDetect(factory.Detect)
Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))
plan := buildplan.BuildPlan{
dep.Dependency: buildplan.Dependency{

plan := buildplan.Plan{
Provides: []buildplan.Provided{{Name: dep.Dependency}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: buildplan.Metadata{
"build": true,
"build": true,
"import-path": "some/app",
"targets": []string{"./path/to/third", "./path/to/fourth"},
"targets": []string{"./path/to/first", "./path/to/second"},
},
},
}},
}

Expect(factory.Output).To(Equal(plan))
Expect(factory.Plans.Plan).To(Equal(plan))
})
})

when("BP_GO_TARGETS environment variable is set but empty", func() {
it("should use fail the detect phase", func() {
err := os.Setenv("BP_GO_TARGETS", "")
Expect(err).NotTo(HaveOccurred())
when("BP_GO_TARGETS environment variable is set", func() {
it("should use the BP_GO_TARGETS value in the build plan", func() {
err := os.Setenv("BP_GO_TARGETS", "./path/to/third:./path/to/fourth")
Expect(err).NotTo(HaveOccurred())

code, err := runDetect(factory.Detect)
Expect(err).ToNot(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))

plan := buildplan.Plan{
Provides: []buildplan.Provided{{Name: dep.Dependency}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: buildplan.Metadata{
"build": true,
"import-path": "some/app",
"targets": []string{"./path/to/third", "./path/to/fourth"}},
}},
}

Expect(factory.Plans.Plan).To(Equal(plan))
})
})

code, err := runDetect(factory.Detect)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(EmptyTargetEnvVariableMsg))
Expect(code).To(Equal(detect.FailStatusCode))
when("BP_GO_TARGETS environment variable is set but empty", func() {
it("should use fail the detect phase", func() {
err := os.Setenv("BP_GO_TARGETS", "")
Expect(err).NotTo(HaveOccurred())

code, err := runDetect(factory.Detect)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal(EmptyTargetEnvVariableMsg))
Expect(code).To(Equal(detect.FailStatusCode))

})
})

})

})
when("Gopkg.toml exists and buildpack.yml empty", func() {
it("passes detect and does not add import-path to the buildplan", func() {
bpYmlString := ""
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "buildpack.yml"), bpYmlString)

when("Gopkg.toml exists and buildpack.yml empty", func() {
it("passes detect and does not add import-path to the buildplan", func() {
bpYmlString := ""
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "buildpack.yml"), bpYmlString)
goPkgString := fmt.Sprintf("This is a go pkg toml")
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "Gopkg.toml"), goPkgString)

goPkgString := fmt.Sprintf("This is a go pkg toml")
test.WriteFile(t, filepath.Join(factory.Detect.Application.Root, "Gopkg.toml"), goPkgString)
code, err := runDetect(factory.Detect)
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))

code, err := runDetect(factory.Detect)
Expect(err).NotTo(HaveOccurred())
Expect(code).To(Equal(detect.PassStatusCode))
Expect(factory.Output[dep.Dependency].Metadata).NotTo(HaveKey(dep.ImportPath))
Expect(factory.Output[dep.Dependency].Metadata).NotTo(HaveKey(dep.Targets))
Expect(factory.Output[dep.Dependency].Metadata).To(HaveKey("build"))
Expect(factory.Plans.Plan).To(Equal(buildplan.Plan{
Provides: []buildplan.Provided{{Name: dep.Dependency}},
Requires: []buildplan.Required{{
Name: dep.Dependency,
Metadata: buildplan.Metadata{"build": true},
}},
}))
})
})
})
}
9 changes: 7 additions & 2 deletions dep/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ type Runner interface {
}

func NewContributor(context build.Build, runner Runner) (Contributor, bool, error) {
dependency, wantDependency := context.BuildPlan[Dependency]
if !wantDependency {



dependency, wantDependency, err := context.Plans.GetShallowMerged(Dependency)
if err != nil {
return Contributor{}, false, nil
} else if !wantDependency {
return Contributor{}, false, nil
}

Expand Down
Loading

0 comments on commit 1516250

Please sign in to comment.