Skip to content

Commit 3b8c804

Browse files
author
Jay Conrod
committed
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 #31946 Change-Id: Id147527b1dbdc14bb33ac133c30d50c250b4365c Reviewed-on: https://go-review.googlesource.com/c/go/+/176558 Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent ef4666e commit 3b8c804

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cmd/go/internal/load/test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ Search:
353353
// preal, packages that import the package under test should get ptest instead
354354
// of preal. This is particularly important if pxtest depends on functionality
355355
// exposed in test sources in ptest. Second, if there is a main package
356-
// (other than pmain) anywhere, we need to clear p.Internal.BuildInfo in
357-
// the test copy to prevent link conflicts. This may happen if both -coverpkg
358-
// and the command line patterns include multiple main packages.
356+
// (other than pmain) anywhere, we need to set p.Internal.ForceLibrary and
357+
// clear p.Internal.BuildInfo in the test copy to prevent link conflicts.
358+
// This may happen if both -coverpkg and the command line patterns include
359+
// multiple main packages.
359360
func recompileForTest(pmain, preal, ptest, pxtest *Package) {
360361
// The "test copy" of preal is ptest.
361362
// For each package that depends on preal, make a "test copy"
@@ -386,6 +387,7 @@ func recompileForTest(pmain, preal, ptest, pxtest *Package) {
386387
p = p1
387388
p.Target = ""
388389
p.Internal.BuildInfo = ""
390+
p.Internal.ForceLibrary = true
389391
}
390392

391393
// Update p.Internal.Imports to use test copies.

0 commit comments

Comments
 (0)