From 63436392db6ac0557513535fc3ee4223a44810ed Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 20 Apr 2022 09:43:39 -0300 Subject: [PATCH] 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 * test: fix build tests Signed-off-by: Carlos A Becker --- internal/builders/golang/build.go | 15 +++++++ internal/builders/golang/build_test.go | 60 ++++++++++++++++++++++++++ internal/pipe/build/build_test.go | 33 +++++++------- 3 files changed, 93 insertions(+), 15 deletions(-) diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go index b8ad0298f..bd6fd40d9 100644 --- a/internal/builders/golang/build.go +++ b/internal/builders/golang/build.go @@ -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 } diff --git a/internal/builders/golang/build_test.go b/internal/builders/golang/build_test.go index 9f9e3ce4d..cf54b0d32 100644 --- a/internal/builders/golang/build_test.go +++ b/internal/builders/golang/build_test.go @@ -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", diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go index f9b8edaeb..21cda8c24 100644 --- a/internal/pipe/build/build_test.go +++ b/internal/pipe/build/build_test.go @@ -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", }, }, {