mirror of
https://github.com/golang/go
synced 2024-11-18 15:54:42 -07:00
cmd/go: put user flags after code generation flag
This permits the user to override the code generation flag when they know better. This is always a good policy for all flags automatically inserted by the build system. Doing this now so that I can write a test for #20290. Update #20290 Change-Id: I5c6708a277238d571b8d037993a5a59e2a442e98 Reviewed-on: https://go-review.googlesource.com/42952 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
1e732ca388
commit
9eacd977a0
@ -4009,3 +4009,31 @@ func TestNeedVersion(t *testing.T) {
|
|||||||
tg.runFail("run", path)
|
tg.runFail("run", path)
|
||||||
tg.grepStderr("compile", "does not match go tool version")
|
tg.grepStderr("compile", "does not match go tool version")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that user can override default code generation flags.
|
||||||
|
func TestUserOverrideFlags(t *testing.T) {
|
||||||
|
if !canCgo {
|
||||||
|
t.Skip("skipping because cgo not enabled")
|
||||||
|
}
|
||||||
|
if runtime.GOOS != "linux" {
|
||||||
|
// We are testing platform-independent code, so it's
|
||||||
|
// OK to skip cases that work differently.
|
||||||
|
t.Skipf("skipping on %s because test only works if c-archive implies -shared", runtime.GOOS)
|
||||||
|
}
|
||||||
|
|
||||||
|
tg := testgo(t)
|
||||||
|
defer tg.cleanup()
|
||||||
|
tg.parallel()
|
||||||
|
tg.tempFile("override.go", `package main
|
||||||
|
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
//export GoFunc
|
||||||
|
func GoFunc() {}
|
||||||
|
|
||||||
|
func main() {}`)
|
||||||
|
tg.creatingTemp("override.a")
|
||||||
|
tg.creatingTemp("override.h")
|
||||||
|
tg.run("build", "-x", "-buildmode=c-archive", "-gcflags=-shared=false", tg.path("override.go"))
|
||||||
|
tg.grepStderr("compile .*-shared .*-shared=false", "user can not override code generation flag")
|
||||||
|
}
|
||||||
|
@ -379,10 +379,10 @@ func BuildModeInit() {
|
|||||||
}
|
}
|
||||||
if codegenArg != "" {
|
if codegenArg != "" {
|
||||||
if gccgo {
|
if gccgo {
|
||||||
buildGccgoflags = append(buildGccgoflags, codegenArg)
|
buildGccgoflags = append([]string{codegenArg}, buildGccgoflags...)
|
||||||
} else {
|
} else {
|
||||||
buildAsmflags = append(buildAsmflags, codegenArg)
|
buildAsmflags = append([]string{codegenArg}, buildAsmflags...)
|
||||||
buildGcflags = append(buildGcflags, codegenArg)
|
buildGcflags = append([]string{codegenArg}, buildGcflags...)
|
||||||
}
|
}
|
||||||
// Don't alter InstallSuffix when modifying default codegen args.
|
// Don't alter InstallSuffix when modifying default codegen args.
|
||||||
if cfg.BuildBuildmode != "default" || cfg.BuildLinkshared {
|
if cfg.BuildBuildmode != "default" || cfg.BuildLinkshared {
|
||||||
|
Loading…
Reference in New Issue
Block a user