-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
will not be added to when is defined and not defined
Signed-off-by: WYGIN <[email protected]>
- Loading branch information
Showing
6 changed files
with
90 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,12 +70,16 @@ func BuildpackNew(logger logging.Logger, creator BuildpackCreator) *cobra.Comman | |
}) | ||
} | ||
|
||
targets, warn, err := target.ParseTargets(flags.Targets) | ||
for _, w := range warn.Messages { | ||
logger.Warn(w) | ||
} | ||
if err != nil { | ||
return err | ||
var targets []dist.Target | ||
if len(flags.Targets) == 0 && len(flags.Stacks) == 0 { | ||
targets = []dist.Target{{ | ||
OS: runtime.GOOS, | ||
Arch: runtime.GOARCH, | ||
}} | ||
} else { | ||
if targets, err = target.ParseTargets(flags.Targets, logger); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := creator.NewBuildpack(cmd.Context(), client.NewBuildpackOptions{ | ||
|
@@ -97,9 +101,9 @@ func BuildpackNew(logger logging.Logger, creator BuildpackCreator) *cobra.Comman | |
cmd.Flags().StringVarP(&flags.API, "api", "a", "0.8", "Buildpack API compatibility of the generated buildpack") | ||
cmd.Flags().StringVarP(&flags.Path, "path", "p", "", "Path to generate the buildpack") | ||
cmd.Flags().StringVarP(&flags.Version, "version", "V", "1.0.0", "Version of the generated buildpack") | ||
cmd.Flags().StringSliceVarP(&flags.Stacks, "stacks", "s", []string{}, "Stack(s) this buildpack will be compatible with"+stringSliceHelp("stack")) | ||
cmd.Flags().StringSliceVarP(&flags.Stacks, "stacks", "s", nil, "Stack(s) this buildpack will be compatible with"+stringSliceHelp("stack")) | ||
cmd.Flags().MarkDeprecated("stacks", "prefer `--targets` instead: https://github.com/buildpacks/rfcs/blob/main/text/0096-remove-stacks-mixins.md") | ||
cmd.Flags().StringSliceVarP(&flags.Targets, "targets", "t", []string{runtime.GOOS + "/" + runtime.GOARCH}, | ||
cmd.Flags().StringSliceVarP(&flags.Targets, "targets", "t", nil, | ||
`Targets are the list platforms that one targeting, these are generated as part of scaffolding inside buildpack.toml file. one can provide target platforms in format [os][/arch][/variant]:[distroname@osversion@anotherversion];[distroname@osversion] | ||
- Base case for two different architectures : '--targets "linux/amd64" --targets "linux/arm64"' | ||
- case for distribution version: '--targets "windows/amd64:[email protected]"' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package target_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/heroku/color" | ||
|
@@ -9,6 +10,7 @@ import ( | |
|
||
"github.com/buildpacks/pack/internal/target" | ||
"github.com/buildpacks/pack/pkg/dist" | ||
"github.com/buildpacks/pack/pkg/logging" | ||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
|
@@ -19,33 +21,53 @@ func TestParseTargets(t *testing.T) { | |
} | ||
|
||
func testParseTargets(t *testing.T, when spec.G, it spec.S) { | ||
outBuf := bytes.Buffer{} | ||
it.Before(func() { | ||
outBuf = bytes.Buffer{} | ||
h.AssertEq(t, outBuf.String(), "") | ||
var err error | ||
h.AssertNil(t, err) | ||
}) | ||
|
||
when("target#ParseTarget", func() { | ||
it("should show a warn when [os][/arch][/variant] is nil", func() { | ||
_, warn, _ := target.ParseTarget(":distro@version") | ||
h.AssertNotNil(t, warn.Messages) | ||
target.ParseTarget(":distro@version", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotEq(t, outBuf.String(), "") | ||
}) | ||
it("should parse target as expected", func() { | ||
output, _, err := target.ParseTarget("linux/arm/v6") | ||
output, err := target.ParseTarget("linux/arm/v6", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertEq(t, outBuf.String(), "") | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, output, dist.Target{ | ||
OS: "linux", | ||
Arch: "arm", | ||
ArchVariant: "v6", | ||
}) | ||
}) | ||
it("should return an error", func() { | ||
_, err := target.ParseTarget("", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotNil(t, err) | ||
}) | ||
it("should log a warning when only [os] has typo or is unknown", func() { | ||
target.ParseTarget("os/arm/v6", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotEq(t, outBuf.String(), "") | ||
}) | ||
it("should log a warning when only [arch] has typo or is unknown", func() { | ||
target.ParseTarget("darwin/arm/v6", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotEq(t, outBuf.String(), "") | ||
}) | ||
it("should log a warning when only [variant] has typo or is unknown", func() { | ||
target.ParseTarget("linux/arm/unknown", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotEq(t, outBuf.String(), "") | ||
}) | ||
}) | ||
when("target#ParseTargets", func() { | ||
it("should throw an error when atleast one target throws error", func() { | ||
_, _, err := target.ParseTargets([]string{"linux/arm/v6", ":distro@version"}) | ||
_, err := target.ParseTargets([]string{"linux/arm/v6", ":distro@version"}, logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotNil(t, err) | ||
}) | ||
it("should parse targets as expected", func() { | ||
output, _, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:[email protected];[email protected]@10.06"}) | ||
output, err := target.ParseTargets([]string{"linux/arm/v6", "linux/amd64:[email protected];[email protected]@10.06"}, logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, output, []dist.Target{ | ||
{ | ||
|
@@ -72,17 +94,25 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) { | |
}) | ||
when("target#ParseDistro", func() { | ||
it("should parse distro as expected", func() { | ||
output, _, err := target.ParseDistro("[email protected]@20.08") | ||
output, err := target.ParseDistro("[email protected]@20.08", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertEq(t, output, dist.Distribution{ | ||
Name: "ubuntu", | ||
Versions: []string{"22.04", "20.08"}, | ||
}) | ||
h.AssertNil(t, err) | ||
}) | ||
it("should return an error", func() { | ||
_, err := target.ParseDistro("@[email protected]", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotNil(t, err) | ||
}) | ||
it("should warn when distro version is not specified", func() { | ||
target.ParseDistro("ubuntu", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotEq(t, outBuf.String(), "") | ||
}) | ||
}) | ||
when("target#ParseDistros", func() { | ||
it("should parse distros as expected", func() { | ||
output, _, err := target.ParseDistros("[email protected]@20.08;[email protected]@10.06") | ||
output, err := target.ParseDistros("[email protected]@20.08;[email protected]@10.06", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertEq(t, output, []dist.Distribution{ | ||
{ | ||
Name: "ubuntu", | ||
|
@@ -96,9 +126,13 @@ func testParseTargets(t *testing.T, when spec.G, it spec.S) { | |
h.AssertNil(t, err) | ||
}) | ||
it("result should be nil", func() { | ||
output, _, err := target.ParseDistros("") | ||
output, err := target.ParseDistros("", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertEq(t, output, []dist.Distribution(nil)) | ||
h.AssertNil(t, err) | ||
}) | ||
it("should return an error", func() { | ||
_, err := target.ParseDistros(";", logging.NewLogWithWriters(&outBuf, &outBuf)) | ||
h.AssertNotNil(t, err) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.