mirror of
https://github.com/golang/go.git
synced 2026-06-27 11:20:41 +00:00
cmd/go/internal/load: fix a data race in test.go
Invoking setToolFlags in TestPackagesAndErrors can cause a data race when executing the command 'go list -e -test'. Moving this call to loadImport avoids this issue. Updates #77053. Change-Id: I33dd956bde1cb0153ca35e6645c73ef7c122cfe9 Reviewed-on: https://go-review.googlesource.com/c/go/+/738220 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev>
This commit is contained in:
parent
729d18bcc0
commit
e4e2474e12
2 changed files with 3 additions and 18 deletions
|
|
@ -742,6 +742,7 @@ func loadImport(ld *modload.Loader, ctx context.Context, opts PackageOpts, pre *
|
|||
defer stk.Pop()
|
||||
}
|
||||
p.setLoadPackageDataError(err, path, stk, nil)
|
||||
setToolFlags(ld, p)
|
||||
return p, nil
|
||||
}
|
||||
|
||||
|
|
@ -768,6 +769,7 @@ func loadImport(ld *modload.Loader, ctx context.Context, opts PackageOpts, pre *
|
|||
packageCache[importPath] = p
|
||||
|
||||
setCmdline(p)
|
||||
setToolFlags(ld, p)
|
||||
|
||||
// Load package.
|
||||
// loadPackageData may return bp != nil even if an error occurs,
|
||||
|
|
@ -2838,17 +2840,6 @@ func TestPackageList(ld *modload.Loader, ctx context.Context, opts PackageOpts,
|
|||
return all
|
||||
}
|
||||
|
||||
// LoadImportWithFlags loads the package with the given import path and
|
||||
// sets tool flags on that package. This function is useful loading implicit
|
||||
// dependencies (like sync/atomic for coverage).
|
||||
// TODO(jayconrod): delete this function and set flags automatically
|
||||
// in LoadImport instead.
|
||||
func LoadImportWithFlags(ld *modload.Loader, path, srcDir string, parent *Package, stk *ImportStack, importPos []token.Position, mode int) (*Package, *PackageError) {
|
||||
p, err := loadImport(ld, context.TODO(), PackageOpts{}, nil, path, srcDir, parent, stk, importPos, mode)
|
||||
setToolFlags(ld, p)
|
||||
return p, err
|
||||
}
|
||||
|
||||
// LoadPackageWithFlags is the same as LoadImportWithFlags but without a parent.
|
||||
// It's then guaranteed to not return an error
|
||||
func LoadPackageWithFlags(ld *modload.Loader, path, srcDir string, stk *ImportStack, importPos []token.Position, mode int) *Package {
|
||||
|
|
@ -3481,7 +3472,7 @@ func EnsureImport(s *modload.Loader, p *Package, pkg string) {
|
|||
}
|
||||
}
|
||||
|
||||
p1, err := LoadImportWithFlags(s, pkg, p.Dir, p, &ImportStack{}, nil, 0)
|
||||
p1, err := loadImport(s, context.TODO(), PackageOpts{}, nil, pkg, p.Dir, p, &ImportStack{}, nil, 0)
|
||||
if err != nil {
|
||||
base.Fatalf("load %s: %v", pkg, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,12 +324,6 @@ func TestPackagesAndErrors(ld *modload.Loader, ctx context.Context, done func(),
|
|||
stk.Pop()
|
||||
|
||||
parallelizablePart := func() {
|
||||
allTestImports := make([]*Package, 0, len(pmain.Internal.Imports)+len(imports)+len(ximports))
|
||||
allTestImports = append(allTestImports, pmain.Internal.Imports...)
|
||||
allTestImports = append(allTestImports, imports...)
|
||||
allTestImports = append(allTestImports, ximports...)
|
||||
setToolFlags(ld, allTestImports...)
|
||||
|
||||
// Do initial scan for metadata needed for writing _testmain.go
|
||||
// Use that metadata to update the list of imports for package main.
|
||||
// The list of imports is used by recompileForTest and by the loop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue