Skip to content

Commit 451e6d6

Browse files
Jay Conroddmitshur
Jay Conrod
authored andcommitted
[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 <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit 3b8c804) Reviewed-on: https://go-review.googlesource.com/c/go/+/179677
1 parent 918368e commit 451e6d6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,10 @@ Search:
321321
// preal, packages that import the package under test should get ptest instead
322322
// of preal. This is particularly important if pxtest depends on functionality
323323
// exposed in test sources in ptest. Second, if there is a main package
324-
// (other than pmain) anywhere, we need to clear p.Internal.BuildInfo in
325-
// the test copy to prevent link conflicts. This may happen if both -coverpkg
326-
// and the command line patterns include multiple main packages.
324+
// (other than pmain) anywhere, we need to set p.Internal.ForceLibrary and
325+
// clear p.Internal.BuildInfo in the test copy to prevent link conflicts.
326+
// This may happen if both -coverpkg and the command line patterns include
327+
// multiple main packages.
327328
func recompileForTest(pmain, preal, ptest, pxtest *Package) {
328329
// The "test copy" of preal is ptest.
329330
// For each package that depends on preal, make a "test copy"
@@ -354,6 +355,7 @@ func recompileForTest(pmain, preal, ptest, pxtest *Package) {
354355
p = p1
355356
p.Target = ""
356357
p.Internal.BuildInfo = ""
358+
p.Internal.ForceLibrary = true
357359
}
358360

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

0 commit comments

Comments
 (0)