aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-04-05 15:01:21 -0400
committerRuss Cox <rsc@golang.org>2017-04-05 20:34:00 +0000
commit166f2159d8fef1f52a6529a59070bcdf44c6e4d4 (patch)
tree251ce2ab11189bba3481b0d894772be4f562e2fc
parent95a5b80e6d7096923dc0ffd8b88b1bd9e2670858 (diff)
downloadgo-166f2159d8fef1f52a6529a59070bcdf44c6e4d4.tar.gz
go-166f2159d8fef1f52a6529a59070bcdf44c6e4d4.zip
[release-branch.go1.8] cmd/go: do not install broken libraries during 'go test -i -race'
Manual port of CL 37598 (submitted for Go 1.9) to Go 1.8.1. Fixes #19133. Fixes #19151. Change-Id: I51707ea35068a393022f554b391ee2638dba16b5 Reviewed-on: https://go-review.googlesource.com/39617 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
-rw-r--r--src/cmd/go/pkg.go4
-rw-r--r--src/cmd/go/test.go21
2 files changed, 21 insertions, 4 deletions
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index e40f9420c7..575f187f3b 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -955,10 +955,6 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
if p.Name == "main" && goarch == "arm" {
importPaths = append(importPaths, "math")
}
- // In coverage atomic mode everything depends on sync/atomic.
- if testCoverMode == "atomic" && (!p.Standard || (p.ImportPath != "runtime/cgo" && p.ImportPath != "runtime/race" && p.ImportPath != "sync/atomic")) {
- importPaths = append(importPaths, "sync/atomic")
- }
}
// Runtime and its internal packages depend on runtime/internal/sys,
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index 6482f0fd32..35250c9f6b 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -545,6 +545,10 @@ func runTest(cmd *Command, args []string) {
// Prepare build + run + print actions for all packages being tested.
for _, p := range pkgs {
+ // sync/atomic import is inserted by the cover tool. See #18486
+ if testCover && testCoverMode == "atomic" {
+ ensureImport(p, "sync/atomic")
+ }
buildTest, runTest, printTest, err := b.test(p)
if err != nil {
str := err.Error()
@@ -636,6 +640,23 @@ func runTest(cmd *Command, args []string) {
b.do(root)
}
+// ensures that package p imports the named package.
+func ensureImport(p *Package, pkg string) {
+ for _, d := range p.deps {
+ if d.Name == pkg {
+ return
+ }
+ }
+
+ a := loadPackage(pkg, &importStack{})
+ if a.Error != nil {
+ fatalf("load %s: %v", pkg, a.Error)
+ }
+ computeStale(a)
+
+ p.imports = append(p.imports, a)
+}
+
func contains(x []string, s string) bool {
for _, t := range x {
if t == s {