]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: put user flags after code generation flag
authorIan Lance Taylor <iant@golang.org>
Tue, 9 May 2017 13:40:04 +0000 (06:40 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 9 May 2017 14:23:50 +0000 (14:23 +0000)
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>

src/cmd/go/go_test.go
src/cmd/go/internal/work/build.go

index bc6e1baab731ed132585121e787f179c94d6814c..2b118695c94e1c4032db4290b40ddca4612730cd 100644 (file)
@@ -4009,3 +4009,31 @@ func TestNeedVersion(t *testing.T) {
        tg.runFail("run", path)
        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")
+}
index 4e181933a75e8677f3a37bbc0e697bb2bc65b678..0b304f97fd2e085e212782b70b50162cbe649391 100644 (file)
@@ -379,10 +379,10 @@ func BuildModeInit() {
        }
        if codegenArg != "" {
                if gccgo {
-                       buildGccgoflags = append(buildGccgoflags, codegenArg)
+                       buildGccgoflags = append([]string{codegenArg}, buildGccgoflags...)
                } else {
-                       buildAsmflags = append(buildAsmflags, codegenArg)
-                       buildGcflags = append(buildGcflags, codegenArg)
+                       buildAsmflags = append([]string{codegenArg}, buildAsmflags...)
+                       buildGcflags = append([]string{codegenArg}, buildGcflags...)
                }
                // Don't alter InstallSuffix when modifying default codegen args.
                if cfg.BuildBuildmode != "default" || cfg.BuildLinkshared {