Commit 2c296dc8 authored by Russ Cox's avatar Russ Cox

cmd/go: apply same per-package flags to compile and link of test

If package strings has a particular set of gcflags, then the strings_test
pseudo-package built as part of the test binary started inheriting the
same flags in CL 81496, to fix #22831.

Now the package main and final test binary link built as part of the
strings test binary also inherit the same flags, to fix #22994.

I am slightly uneasy about reusing package strings's flags for
package main, but the alternative would be to introduce some
kind of special case, which I'd be even more uneasy about.

This interpretation preserves the Go 1.9 behavior of existing
commands like:

	go test -c -ldflags=-X=mypkg.debugString=foo mypkg

Fixes #22994.

Change-Id: I9ab83bf1a9a6adae530a7715b907e709fd6c1b5d
Reviewed-on: https://go-review.googlesource.com/83879
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 0f3ab149
......@@ -5343,11 +5343,13 @@ func TestGcflagsPatterns(t *testing.T) {
tg.grepStderr("compile.* -N .*-p reflect", "did not build reflect with -N flag")
tg.grepStderrNot("compile.* -N .*-p fmt", "incorrectly built fmt with -N flag")
tg.run("test", "-c", "-n", "-gcflags=-N", "strings")
tg.grepStderr("compile.* -N .*compare_test.go", "did not build strings_test package with -N flag")
tg.run("test", "-c", "-n", "-gcflags=-N", "-ldflags=-X=x.y=z", "strings")
tg.grepStderr("compile.* -N .*compare_test.go", "did not compile strings_test package with -N flag")
tg.grepStderr("link.* -X=x.y=z", "did not link strings.test binary with -X flag")
tg.run("test", "-c", "-n", "-gcflags=strings=-N", "strings")
tg.grepStderr("compile.* -N .*compare_test.go", "did not build strings_test package with -N flag")
tg.run("test", "-c", "-n", "-gcflags=strings=-N", "-ldflags=strings=-X=x.y=z", "strings")
tg.grepStderr("compile.* -N .*compare_test.go", "did not compile strings_test package with -N flag")
tg.grepStderr("link.* -X=x.y=z", "did not link strings.test binary with -X flag")
}
func TestGoTestMinusN(t *testing.T) {
......
......@@ -929,6 +929,11 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
Internal: load.PackageInternal{
Build: &build.Package{Name: "main"},
OmitDebug: !testC && !testNeedBinary,
Asmflags: p.Internal.Asmflags,
Gcflags: p.Internal.Gcflags,
Ldflags: p.Internal.Ldflags,
Gccgoflags: p.Internal.Gccgoflags,
},
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment