Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Nov 9, 2024
1 parent 7adfa13 commit ab88dd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
24 changes: 20 additions & 4 deletions carton/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/paketo-buildpacks/libpak/v2/utils"
)

const DefaultTargetArch = "all"

// Package is an object that contains the configuration for building a package.
type Package struct {

Expand All @@ -58,6 +60,9 @@ type Package struct {

// Version is a version to substitute into an existing buildpack.toml.
Version string

// TargetArch is the target architecture to package. Default is "all".
TargetArch string
}

// Create creates a package.
Expand Down Expand Up @@ -149,7 +154,8 @@ func (p Package) Create(options ...Option) {
}
}

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

Expand All @@ -158,7 +164,7 @@ func (p Package) Create(options ...Option) {
entries := map[string]string{}

for _, i := range metadata.IncludeFiles {
if len(supportedTargets) == 0 || strings.HasPrefix(i, "linux/") || i == "buildpack.toml" {
if oldOutputFormat || strings.HasPrefix(i, "linux/") || i == "buildpack.toml" {
entries[i] = filepath.Join(p.Source, i)
} else {
for _, target := range supportedTargets {
Expand Down Expand Up @@ -276,8 +282,18 @@ func (p Package) Create(options ...Option) {
}
sort.Strings(files)
for _, d := range files {
logger.Bodyf("Adding %s", d)
file = filepath.Join(p.Destination, d)
if p.TargetArch != DefaultTargetArch && !oldOutputFormat && strings.HasPrefix(d, "linux/") && !strings.HasPrefix(d, fmt.Sprintf("linux/%s", p.TargetArch)) {
logger.Debugf("Skipping %s because target arch is %s", d, p.TargetArch)
continue
}

targetLocation := d
if p.TargetArch != DefaultTargetArch {
targetLocation = strings.Replace(d, fmt.Sprintf("linux/%s/", p.TargetArch), "", 1)
}

logger.Bodyf("Adding %s", targetLocation)
file = filepath.Join(p.Destination, targetLocation)
if err = config.entryWriter.Write(entries[d], file); err != nil {
config.exitHandler.Error(fmt.Errorf("unable to write file %s to %s\n%w", entries[d], file, err))
return
Expand Down
1 change: 1 addition & 0 deletions commands/package_create.go → commands/package_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func PackageCompileCommand() *cobra.Command {
packageCreateCommand.Flags().BoolVar(&p.StrictDependencyFilters, "strict-filters", false, "require filter to match all data or just some data (default: false)")
packageCreateCommand.Flags().StringVar(&p.Source, "source", defaultSource(), "path to build package source directory (default: $PWD)")
packageCreateCommand.Flags().StringVar(&p.Version, "version", "", "version to substitute into buildpack.toml/extension.toml")
packageCreateCommand.Flags().StringVar(&p.TargetArch, "target-arch", carton.DefaultTargetArch, "target architecture for the package (default: all)")

return packageCreateCommand
}
Expand Down

0 comments on commit ab88dd7

Please sign in to comment.