Skip to content

Commit

Permalink
Merge pull request #323 from paketo-buildpacks/package-arches
Browse files Browse the repository at this point in the history
Modify carton package to work with targets
  • Loading branch information
anthonydahanne authored Apr 4, 2024
2 parents d46828f + 355f0b9 commit e0627f1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
30 changes: 29 additions & 1 deletion carton/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -97,10 +98,37 @@ func (p Package) Create(options ...Option) {
return
}

logger.Debugf("IncludeFiles: %+v", metadata.IncludeFiles)

supportedTargets := []string{}
for _, i := range metadata.IncludeFiles {
if strings.HasPrefix(i, "linux/") {
parts := strings.SplitN(i, "/", 3)
if len(parts) < 3 {
// this shouldn't happen, but if it does for some reason just ignore it
// this entry is not a properly formatted target
continue
}
supportedTargets = append(supportedTargets, fmt.Sprintf("%s/%s", parts[0], parts[1]))
}
}

if len(supportedTargets) == 0 {
logger.Info("No supported targets found, defaulting to old format")
}

logger.Debugf("Supported targets: %+v", supportedTargets)

entries := map[string]string{}

for _, i := range metadata.IncludeFiles {
entries[i] = filepath.Join(p.Source, i)
if len(supportedTargets) == 0 || strings.HasPrefix(i, "linux/") || i == "buildpack.toml" {
entries[i] = filepath.Join(p.Source, i)
} else {
for _, target := range supportedTargets {
entries[fmt.Sprintf("%s/%s", target, i)] = filepath.Join(p.Source, i)
}
}
}
logger.Debugf("Include files: %+v", entries)

Expand Down
63 changes: 62 additions & 1 deletion carton/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,68 @@ include-files = [
Expect(e.Dir).To(Equal(path))
})

it("includes include_files", func() {
context("has a buildpack.toml with target specific include files", func() {
it.Before(func() {
Expect(os.WriteFile(filepath.Join(path, "buildpack.toml"), []byte(`
api = "0.0.0"
[buildpack]
name = "test-name"
version = "{{.version}}"
[[metadata.dependencies]]
id = "test-id"
name = "test-name"
version = "1.1.1"
uri = "test-uri"
sha256 = "test-sha256"
stacks = [ "test-stack" ]
[[metadata.dependencies.licenses]]
type = "test-type"
uri = "test-uri"
[metadata]
pre-package = "test-pre-package"
include-files = [
"buildpack.toml",
"README",
"LICENSE",
"linux/amd64/bin/just-once",
"linux/arm64/bin/also-just-once"
]
`), 0644)).To(Succeed())
})

it("includes include_files using the original format", func() {
carton.Package{
Source: path,
Destination: "test-destination",
}.Create(
carton.WithEntryWriter(entryWriter),
carton.WithExecutor(executor),
carton.WithExitHandler(exitHandler))

Expect(entryWriter.Calls[0].Arguments[0]).To(Equal(filepath.Join(path, "buildpack.toml")))
Expect(entryWriter.Calls[0].Arguments[1]).To(Equal(filepath.Join("test-destination", "buildpack.toml")))

Expect(entryWriter.Calls[1].Arguments[0]).To(Equal(filepath.Join(path, "LICENSE")))
Expect(entryWriter.Calls[1].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/amd64/LICENSE")))
Expect(entryWriter.Calls[2].Arguments[0]).To(Equal(filepath.Join(path, "README")))
Expect(entryWriter.Calls[2].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/amd64/README")))
Expect(entryWriter.Calls[3].Arguments[0]).To(Equal(filepath.Join(path, "linux/amd64/bin/just-once")))
Expect(entryWriter.Calls[3].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/amd64/bin/just-once")))

Expect(entryWriter.Calls[4].Arguments[0]).To(Equal(filepath.Join(path, "LICENSE")))
Expect(entryWriter.Calls[4].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/arm64/LICENSE")))
Expect(entryWriter.Calls[5].Arguments[0]).To(Equal(filepath.Join(path, "README")))
Expect(entryWriter.Calls[5].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/arm64/README")))
Expect(entryWriter.Calls[6].Arguments[0]).To(Equal(filepath.Join(path, "linux/arm64/bin/also-just-once")))
Expect(entryWriter.Calls[6].Arguments[1]).To(Equal(filepath.Join("test-destination", "linux/arm64/bin/also-just-once")))
})
})

it("includes include_files using the target format", func() {
carton.Package{
Source: path,
Destination: "test-destination",
Expand Down

0 comments on commit e0627f1

Please sign in to comment.