1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-06 03:13:48 +02:00

fix: custom targets if missing goamd64, goarm, gomips (#3056)

* fix: custom targets if missing goamd64, goarm, gomips

if the user provide custom targets without the goamd64, goarm or gomips bit, things may go awry at some point.

this prevents issues by suffixing them with the default when its missing.

closes https://github.com/goreleaser/goreleaser/issues/3055

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* test: fix build tests

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2022-04-20 09:43:39 -03:00 committed by GitHub
parent 922992ce76
commit 63436392db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 15 deletions

View File

@ -69,6 +69,21 @@ func (*Builder) WithDefaults(build config.Build) (config.Build, error) {
if err != nil {
return build, err
}
} else {
for i, target := range build.Targets {
if strings.HasSuffix(target, "_amd64") {
build.Targets[i] = target + "_v1"
}
if strings.HasSuffix(target, "_arm") {
build.Targets[i] = target + "_6"
}
if strings.HasSuffix(target, "_mips") ||
strings.HasSuffix(target, "_mips64") ||
strings.HasSuffix(target, "_mipsle") ||
strings.HasSuffix(target, "_mips64le") {
build.Targets[i] = target + "_hardfloat"
}
}
}
return build, nil
}

View File

@ -95,6 +95,66 @@ func TestWithDefaults(t *testing.T) {
},
goBinary: "go",
},
"custom targets no amd64": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{
"linux_386",
"darwin_amd64",
},
},
targets: []string{
"linux_386",
"darwin_amd64_v1",
},
goBinary: "go",
},
"custom targets no arm": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{"linux_arm"},
},
targets: []string{"linux_arm_6"},
goBinary: "go",
},
"custom targets no mips": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{"linux_mips"},
},
targets: []string{"linux_mips_hardfloat"},
goBinary: "go",
},
"custom targets no mipsle": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{"linux_mipsle"},
},
targets: []string{"linux_mipsle_hardfloat"},
goBinary: "go",
},
"custom targets no mips64": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{"linux_mips64"},
},
targets: []string{"linux_mips64_hardfloat"},
goBinary: "go",
},
"custom targets no mips64le": {
build: config.Build{
ID: "foo3",
Binary: "foo",
Targets: []string{"linux_mips64le"},
},
targets: []string{"linux_mips64le_hardfloat"},
goBinary: "go",
},
"empty with custom dir": {
build: config.Build{
ID: "foo2",

View File

@ -562,11 +562,12 @@ func TestBuildOptionsForTarget(t *testing.T) {
},
},
expectedOpts: &api.Options{
Name: "testbinary",
Path: filepath.Join(tmpDir, "testid_linux_amd64", "testbinary"),
Target: "linux_amd64",
Goos: "linux",
Goarch: "amd64",
Name: "testbinary",
Path: filepath.Join(tmpDir, "testid_linux_amd64_v1", "testbinary"),
Target: "linux_amd64_v1",
Goos: "linux",
Goarch: "amd64",
Goamd64: "v1",
},
},
{
@ -579,11 +580,12 @@ func TestBuildOptionsForTarget(t *testing.T) {
},
},
expectedOpts: &api.Options{
Name: "testbinary_linux_amd64",
Path: filepath.Join(tmpDir, "testid_linux_amd64", "testbinary_linux_amd64"),
Target: "linux_amd64",
Goos: "linux",
Goarch: "amd64",
Name: "testbinary_linux_amd64",
Path: filepath.Join(tmpDir, "testid_linux_amd64_v1", "testbinary_linux_amd64"),
Target: "linux_amd64_v1",
Goos: "linux",
Goarch: "amd64",
Goamd64: "v1",
},
},
{
@ -597,11 +599,12 @@ func TestBuildOptionsForTarget(t *testing.T) {
NoUniqueDistDir: true,
},
expectedOpts: &api.Options{
Name: "distpath/linux/amd64/testbinary_linux_amd64",
Path: filepath.Join(tmpDir, "distpath", "linux", "amd64", "testbinary_linux_amd64"),
Target: "linux_amd64",
Goos: "linux",
Goarch: "amd64",
Name: "distpath/linux/amd64/testbinary_linux_amd64",
Path: filepath.Join(tmpDir, "distpath", "linux", "amd64", "testbinary_linux_amd64"),
Target: "linux_amd64_v1",
Goos: "linux",
Goarch: "amd64",
Goamd64: "v1",
},
},
{