mirror of
https://github.com/golang/go
synced 2024-09-30 11:28:36 -06:00
cmd/go: fix race libraries rebuilding by go test -i
`go test -i -race` adds the "sync/atomic" package to every package dependency tree that makes buildIDs different from packages installed with `go install -race` and causes cache rebuilding. Fixes #19133 Fixes #19151 Change-Id: I0536c6fa41b0d20fe361b5d35b3c0937b146d07d Reviewed-on: https://go-review.googlesource.com/37598 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
b9f6b22a01
commit
be04da8f0c
@ -41,9 +41,6 @@ func init() {
|
||||
BuildToolchainLinker = func() string { return "missing-linker" }
|
||||
}
|
||||
|
||||
// The test coverage mode affects package loading. Sigh.
|
||||
var TestCoverMode string // -covermode flag
|
||||
|
||||
// An EnvVar is an environment variable Name=Value.
|
||||
type EnvVar struct {
|
||||
Name string
|
||||
|
@ -959,10 +959,6 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) *Package
|
||||
if p.Name == "main" && cfg.Goarch == "arm" {
|
||||
ImportPaths = append(ImportPaths, "math")
|
||||
}
|
||||
// In coverage atomic mode everything depends on sync/atomic.
|
||||
if cfg.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,
|
||||
|
@ -388,9 +388,9 @@ See the documentation of the testing package for more information.
|
||||
}
|
||||
|
||||
var (
|
||||
testC bool // -c flag
|
||||
testCover bool // -cover flag
|
||||
// Note: testCoverMode is cfg.TestCoverMode (-covermode)
|
||||
testC bool // -c flag
|
||||
testCover bool // -cover flag
|
||||
testCoverMode string // -covermode flag
|
||||
testCoverPaths []string // -coverpkg flag
|
||||
testCoverPkgs []*load.Package // -coverpkg flag
|
||||
testO string // -o flag
|
||||
@ -548,7 +548,7 @@ func runTest(cmd *base.Command, args []string) {
|
||||
p.Stale = true // rebuild
|
||||
p.StaleReason = "rebuild for coverage"
|
||||
p.Internal.Fake = true // do not warn about rebuild
|
||||
p.Internal.CoverMode = cfg.TestCoverMode
|
||||
p.Internal.CoverMode = testCoverMode
|
||||
var coverFiles []string
|
||||
coverFiles = append(coverFiles, p.GoFiles...)
|
||||
coverFiles = append(coverFiles, p.CgoFiles...)
|
||||
@ -559,6 +559,11 @@ func runTest(cmd *base.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 := builderTest(&b, p)
|
||||
if err != nil {
|
||||
str := err.Error()
|
||||
@ -650,6 +655,23 @@ func runTest(cmd *base.Command, args []string) {
|
||||
b.Do(root)
|
||||
}
|
||||
|
||||
// ensures that package p imports the named package
|
||||
func ensureImport(p *load.Package, pkg string) {
|
||||
for _, d := range p.Internal.Deps {
|
||||
if d.Name == pkg {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
a := load.LoadPackage(pkg, &load.ImportStack{})
|
||||
if a.Error != nil {
|
||||
base.Fatalf("load %s: %v", pkg, a.Error)
|
||||
}
|
||||
load.ComputeStale(a)
|
||||
|
||||
p.Internal.Imports = append(p.Internal.Imports, a)
|
||||
}
|
||||
|
||||
var windowsBadWords = []string{
|
||||
"install",
|
||||
"patch",
|
||||
@ -788,7 +810,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
|
||||
ptest.Internal.Build.ImportPos = m
|
||||
|
||||
if localCover {
|
||||
ptest.Internal.CoverMode = cfg.TestCoverMode
|
||||
ptest.Internal.CoverMode = testCoverMode
|
||||
var coverFiles []string
|
||||
coverFiles = append(coverFiles, ptest.GoFiles...)
|
||||
coverFiles = append(coverFiles, ptest.CgoFiles...)
|
||||
@ -1361,7 +1383,7 @@ type testFuncs struct {
|
||||
}
|
||||
|
||||
func (t *testFuncs) CoverMode() string {
|
||||
return cfg.TestCoverMode
|
||||
return testCoverMode
|
||||
}
|
||||
|
||||
func (t *testFuncs) CoverEnabled() bool {
|
||||
|
@ -174,7 +174,7 @@ func testFlags(args []string) (packageNames, passToTest []string) {
|
||||
case "covermode":
|
||||
switch value {
|
||||
case "set", "count", "atomic":
|
||||
cfg.TestCoverMode = value
|
||||
testCoverMode = value
|
||||
default:
|
||||
base.Fatalf("invalid flag argument for -covermode: %q", value)
|
||||
}
|
||||
@ -191,11 +191,11 @@ func testFlags(args []string) (packageNames, passToTest []string) {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.TestCoverMode == "" {
|
||||
cfg.TestCoverMode = "set"
|
||||
if testCoverMode == "" {
|
||||
testCoverMode = "set"
|
||||
if cfg.BuildRace {
|
||||
// Default coverage mode is atomic when -race is set.
|
||||
cfg.TestCoverMode = "atomic"
|
||||
testCoverMode = "atomic"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user