Skip to content

Commit

Permalink
fix: build --single-target when using specific targets (#3381)
Browse files Browse the repository at this point in the history
When using specific targets in the config, single target becomes
ineffective. This should fix it. This also removes other build options
like gomips, goarm, goamd64, etc, as go will infer them from the current
OS. In theory we should one day support all the GO* flags go build
supports.
  • Loading branch information
caarlos0 committed Sep 16, 2022
1 parent 69e9b2b commit 0ea3e0f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/build.go
Expand Up @@ -165,6 +165,10 @@ func setupBuildSingleTarget(ctx *context.Context) {
build := &ctx.Config.Builds[i]
build.Goos = []string{goos}
build.Goarch = []string{goarch}
build.Goarm = nil
build.Gomips = nil
build.Goamd64 = nil
build.Targets = nil
}
}

Expand Down
46 changes: 46 additions & 0 deletions cmd/build_test.go
Expand Up @@ -278,3 +278,49 @@ func TestBuildFlags(t *testing.T) {
})
})
}

func TestBuildSingleTargetWithSpecificTargets(t *testing.T) {
ctx := context.New(config.Project{
ProjectName: "test",
Builds: []config.Build{
{
Targets: []string{
"linux_amd64_v1",
"darwin_arm64",
"darwin_amd64_v1",
},
},
},
})

t.Setenv("GOOS", "linux")
t.Setenv("GOARCH", "amd64")
setupBuildSingleTarget(ctx)
require.Equal(t, config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
}, ctx.Config.Builds[0])
}

func TestBuildSingleTargetRemoveOtherOptions(t *testing.T) {
ctx := context.New(config.Project{
ProjectName: "test",
Builds: []config.Build{
{
Goos: []string{"linux", "darwin"},
Goarch: []string{"amd64", "arm64"},
Goamd64: []string{"v1", "v2"},
Goarm: []string{"6"},
Gomips: []string{"anything"},
},
},
})

t.Setenv("GOOS", "linux")
t.Setenv("GOARCH", "amd64")
setupBuildSingleTarget(ctx)
require.Equal(t, config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
}, ctx.Config.Builds[0])
}

0 comments on commit 0ea3e0f

Please sign in to comment.