Skip to content

Commit

Permalink
cmd/go: force -coverpkg main packages to be built as libraries
Browse files Browse the repository at this point in the history
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 #31946

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>
  • Loading branch information
Jay Conrod committed May 10, 2019
1 parent ef4666e commit 3b8c804
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cmd/go/internal/load/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,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"
Expand Down Expand Up @@ -386,6 +387,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.
Expand Down

0 comments on commit 3b8c804

Please sign in to comment.