diff options
author | Jay Conrod <jayconrod@google.com> | 2019-05-10 11:49:08 -0400 |
---|---|---|
committer | Dmitri Shuralyov <dmitshur@golang.org> | 2019-06-07 22:33:16 +0000 |
commit | 451e6d61b375ed8b7d2411af9514df12e9970d45 (patch) | |
tree | 839ffd3881387c1a23a04862946cff0ecdee818e | |
parent | 918368e46c53e716f6c4137c174f19d9a907f887 (diff) | |
download | go-451e6d61b375ed8b7d2411af9514df12e9970d45.tar.gz go-451e6d61b375ed8b7d2411af9514df12e9970d45.zip |
[release-branch.go1.12] cmd/go: force -coverpkg main packages to be built as libraries
This fixes TestScript/cover_pkgall_multiple_mains, which started
failing after CL 174657.
When compiling main packages with coverage instrumentation
(e.g., for -coverpkg all), we now pass -p with the full import path
instead of '-p main'. This avoids link errors
'duplicate symbol main.main (types 1 and 1)'.
Fixes #32295
Updates #31946
Updates #32150
Change-Id: Id147527b1dbdc14bb33ac133c30d50c250b4365c
Reviewed-on: https://go-review.googlesource.com/c/go/+/176558
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(cherry picked from commit 3b8c804164e26bdec6ca94a5ab1b5c35fa119e5e)
Reviewed-on: https://go-review.googlesource.com/c/go/+/179677
-rw-r--r-- | src/cmd/go/internal/load/test.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go index 48d03d8fce..4d4d144791 100644 --- a/src/cmd/go/internal/load/test.go +++ b/src/cmd/go/internal/load/test.go @@ -321,9 +321,10 @@ Search: // preal, packages that import the package under test should get ptest instead // of preal. This is particularly important if pxtest depends on functionality // exposed in test sources in ptest. Second, if there is a main package -// (other than pmain) anywhere, we need to clear p.Internal.BuildInfo in -// the test copy to prevent link conflicts. This may happen if both -coverpkg -// and the command line patterns include multiple main packages. +// (other than pmain) anywhere, we need to set p.Internal.ForceLibrary and +// clear p.Internal.BuildInfo in the test copy to prevent link conflicts. +// This may happen if both -coverpkg and the command line patterns include +// multiple main packages. func recompileForTest(pmain, preal, ptest, pxtest *Package) { // The "test copy" of preal is ptest. // For each package that depends on preal, make a "test copy" @@ -354,6 +355,7 @@ func recompileForTest(pmain, preal, ptest, pxtest *Package) { p = p1 p.Target = "" p.Internal.BuildInfo = "" + p.Internal.ForceLibrary = true } // Update p.Internal.Imports to use test copies. |