mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: inject State parameter into test.runTest
This command modifies the call tree starting at `test.runTest` to inject a `State` parameter to every function that is currently using the global `modload.LoaderState` variable. By explicilty passing a `State` parameter, we can begin to eliminate the usage of the global `modload.LoaderState`. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/test rf 'inject modload.LoaderState runTest' cd .. ./rf-cleanup.zsh Change-Id: I6ee495c3beabdc5568ad338f4998a5927491db1a Reviewed-on: https://go-review.googlesource.com/c/go/+/709986 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
35e8309be2
commit
441e7194a4
4 changed files with 19 additions and 19 deletions
|
|
@ -2797,7 +2797,7 @@ func PackageList(roots []*Package) []*Package {
|
||||||
// TestPackageList returns the list of packages in the dag rooted at roots
|
// TestPackageList returns the list of packages in the dag rooted at roots
|
||||||
// as visited in a depth-first post-order traversal, including the test
|
// as visited in a depth-first post-order traversal, including the test
|
||||||
// imports of the roots. This ignores errors in test packages.
|
// imports of the roots. This ignores errors in test packages.
|
||||||
func TestPackageList(ctx context.Context, opts PackageOpts, roots []*Package) []*Package {
|
func TestPackageList(loaderstate *modload.State, ctx context.Context, opts PackageOpts, roots []*Package) []*Package {
|
||||||
seen := map[*Package]bool{}
|
seen := map[*Package]bool{}
|
||||||
all := []*Package{}
|
all := []*Package{}
|
||||||
var walk func(*Package)
|
var walk func(*Package)
|
||||||
|
|
@ -2813,7 +2813,7 @@ func TestPackageList(ctx context.Context, opts PackageOpts, roots []*Package) []
|
||||||
}
|
}
|
||||||
walkTest := func(root *Package, path string) {
|
walkTest := func(root *Package, path string) {
|
||||||
var stk ImportStack
|
var stk ImportStack
|
||||||
p1, err := loadImport(modload.LoaderState, ctx, opts, nil, path, root.Dir, root, &stk, root.Internal.Build.TestImportPos[path], ResolveImport)
|
p1, err := loadImport(loaderstate, ctx, opts, nil, path, root.Dir, root, &stk, root.Internal.Build.TestImportPos[path], ResolveImport)
|
||||||
if err != nil && root.Error == nil {
|
if err != nil && root.Error == nil {
|
||||||
// Assign error importing the package to the importer.
|
// Assign error importing the package to the importer.
|
||||||
root.Error = err
|
root.Error = err
|
||||||
|
|
|
||||||
|
|
@ -872,7 +872,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
|
|
||||||
// Select for coverage all dependencies matching the -coverpkg
|
// Select for coverage all dependencies matching the -coverpkg
|
||||||
// patterns.
|
// patterns.
|
||||||
plist := load.TestPackageList(ctx, pkgOpts, pkgs)
|
plist := load.TestPackageList(modload.LoaderState, ctx, pkgOpts, pkgs)
|
||||||
testCoverPkgs = load.SelectCoverPackages(modload.LoaderState, plist, match, "test")
|
testCoverPkgs = load.SelectCoverPackages(modload.LoaderState, plist, match, "test")
|
||||||
if len(testCoverPkgs) > 0 {
|
if len(testCoverPkgs) > 0 {
|
||||||
// create a new singleton action that will collect up the
|
// create a new singleton action that will collect up the
|
||||||
|
|
@ -951,7 +951,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
"testing": true,
|
"testing": true,
|
||||||
"time": true,
|
"time": true,
|
||||||
}
|
}
|
||||||
for _, p := range load.TestPackageList(ctx, pkgOpts, pkgs) {
|
for _, p := range load.TestPackageList(modload.LoaderState, ctx, pkgOpts, pkgs) {
|
||||||
if !skipInstrumentation[p.ImportPath] {
|
if !skipInstrumentation[p.ImportPath] {
|
||||||
p.Internal.FuzzInstrument = true
|
p.Internal.FuzzInstrument = true
|
||||||
}
|
}
|
||||||
|
|
@ -1048,7 +1048,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
reportSetupFailed(firstErrPkg, firstErrPkg.Error)
|
reportSetupFailed(firstErrPkg, firstErrPkg.Error)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
buildTest, runTest, printTest, perr, err := builderTest(b, ctx, pkgOpts, p, allImports[p], writeCoverMetaAct)
|
buildTest, runTest, printTest, perr, err := builderTest(modload.LoaderState, b, ctx, pkgOpts, p, allImports[p], writeCoverMetaAct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reportErr(perr, err)
|
reportErr(perr, err)
|
||||||
reportSetupFailed(perr, err)
|
reportSetupFailed(perr, err)
|
||||||
|
|
@ -1129,7 +1129,7 @@ var windowsBadWords = []string{
|
||||||
"update",
|
"update",
|
||||||
}
|
}
|
||||||
|
|
||||||
func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts, p *load.Package, imported bool, writeCoverMetaAct *work.Action) (buildAction, runAction, printAction *work.Action, perr *load.Package, err error) {
|
func builderTest(loaderstate *modload.State, b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts, p *load.Package, imported bool, writeCoverMetaAct *work.Action) (buildAction, runAction, printAction *work.Action, perr *load.Package, err error) {
|
||||||
if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
|
if len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
|
||||||
build := b.CompileAction(work.ModeBuild, work.ModeBuild, p)
|
build := b.CompileAction(work.ModeBuild, work.ModeBuild, p)
|
||||||
run := &work.Action{
|
run := &work.Action{
|
||||||
|
|
@ -1157,7 +1157,7 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
|
||||||
run.Deps = append(run.Deps, writeCoverMetaAct)
|
run.Deps = append(run.Deps, writeCoverMetaAct)
|
||||||
writeCoverMetaAct.Deps = append(writeCoverMetaAct.Deps, build)
|
writeCoverMetaAct.Deps = append(writeCoverMetaAct.Deps, build)
|
||||||
}
|
}
|
||||||
addTestVet(b, p, run, nil)
|
addTestVet(loaderstate, b, p, run, nil)
|
||||||
print := &work.Action{
|
print := &work.Action{
|
||||||
Mode: "test print",
|
Mode: "test print",
|
||||||
Actor: work.ActorFunc(builderPrintTest),
|
Actor: work.ActorFunc(builderPrintTest),
|
||||||
|
|
@ -1181,7 +1181,7 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
|
||||||
Paths: cfg.BuildCoverPkg,
|
Paths: cfg.BuildCoverPkg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pmain, ptest, pxtest, perr := load.TestPackagesFor(modload.LoaderState, ctx, pkgOpts, p, cover)
|
pmain, ptest, pxtest, perr := load.TestPackagesFor(loaderstate, ctx, pkgOpts, p, cover)
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
return nil, nil, nil, perr, perr.Error
|
return nil, nil, nil, perr, perr.Error
|
||||||
}
|
}
|
||||||
|
|
@ -1221,7 +1221,7 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a := b.LinkAction(modload.LoaderState, work.ModeBuild, work.ModeBuild, pmain)
|
a := b.LinkAction(loaderstate, work.ModeBuild, work.ModeBuild, pmain)
|
||||||
a.Target = testDir + testBinary + cfg.ExeSuffix
|
a.Target = testDir + testBinary + cfg.ExeSuffix
|
||||||
if cfg.Goos == "windows" {
|
if cfg.Goos == "windows" {
|
||||||
// There are many reserved words on Windows that,
|
// There are many reserved words on Windows that,
|
||||||
|
|
@ -1347,10 +1347,10 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
|
if len(ptest.GoFiles)+len(ptest.CgoFiles) > 0 {
|
||||||
addTestVet(b, ptest, vetRunAction, installAction)
|
addTestVet(loaderstate, b, ptest, vetRunAction, installAction)
|
||||||
}
|
}
|
||||||
if pxtest != nil {
|
if pxtest != nil {
|
||||||
addTestVet(b, pxtest, vetRunAction, installAction)
|
addTestVet(loaderstate, b, pxtest, vetRunAction, installAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
if installAction != nil {
|
if installAction != nil {
|
||||||
|
|
@ -1365,12 +1365,12 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
|
||||||
return buildAction, runAction, printAction, nil, nil
|
return buildAction, runAction, printAction, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTestVet(b *work.Builder, p *load.Package, runAction, installAction *work.Action) {
|
func addTestVet(loaderstate *modload.State, b *work.Builder, p *load.Package, runAction, installAction *work.Action) {
|
||||||
if testVet.off {
|
if testVet.off {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
vet := b.VetAction(work.ModeBuild, work.ModeBuild, p)
|
vet := b.VetAction(loaderstate, work.ModeBuild, work.ModeBuild, p)
|
||||||
runAction.Deps = append(runAction.Deps, vet)
|
runAction.Deps = append(runAction.Deps, vet)
|
||||||
// Install will clean the build directory.
|
// Install will clean the build directory.
|
||||||
// Make sure vet runs first.
|
// Make sure vet runs first.
|
||||||
|
|
|
||||||
|
|
@ -260,10 +260,10 @@ func run(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
}
|
}
|
||||||
if len(ptest.GoFiles) > 0 || len(ptest.CgoFiles) > 0 {
|
if len(ptest.GoFiles) > 0 || len(ptest.CgoFiles) > 0 {
|
||||||
// The test package includes all the files of primary package.
|
// The test package includes all the files of primary package.
|
||||||
root.Deps = append(root.Deps, b.VetAction(work.ModeBuild, work.ModeBuild, ptest))
|
root.Deps = append(root.Deps, b.VetAction(modload.LoaderState, work.ModeBuild, work.ModeBuild, ptest))
|
||||||
}
|
}
|
||||||
if pxtest != nil {
|
if pxtest != nil {
|
||||||
root.Deps = append(root.Deps, b.VetAction(work.ModeBuild, work.ModeBuild, pxtest))
|
root.Deps = append(root.Deps, b.VetAction(modload.LoaderState, work.ModeBuild, work.ModeBuild, pxtest))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Do(ctx, root)
|
b.Do(ctx, root)
|
||||||
|
|
|
||||||
|
|
@ -867,13 +867,13 @@ func (b *Builder) cgoAction(p *load.Package, objdir string, deps []*Action, hasC
|
||||||
// It depends on the action for compiling p.
|
// It depends on the action for compiling p.
|
||||||
// If the caller may be causing p to be installed, it is up to the caller
|
// If the caller may be causing p to be installed, it is up to the caller
|
||||||
// to make sure that the install depends on (runs after) vet.
|
// to make sure that the install depends on (runs after) vet.
|
||||||
func (b *Builder) VetAction(mode, depMode BuildMode, p *load.Package) *Action {
|
func (b *Builder) VetAction(loaderstate *modload.State, mode, depMode BuildMode, p *load.Package) *Action {
|
||||||
a := b.vetAction(mode, depMode, p)
|
a := b.vetAction(loaderstate, mode, depMode, p)
|
||||||
a.VetxOnly = false
|
a.VetxOnly = false
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
|
func (b *Builder) vetAction(loaderstate *modload.State, mode, depMode BuildMode, p *load.Package) *Action {
|
||||||
// Construct vet action.
|
// Construct vet action.
|
||||||
a := b.cacheAction("vet", p, func() *Action {
|
a := b.cacheAction("vet", p, func() *Action {
|
||||||
a1 := b.CompileAction(mode|ModeVetOnly, depMode, p)
|
a1 := b.CompileAction(mode|ModeVetOnly, depMode, p)
|
||||||
|
|
@ -889,7 +889,7 @@ func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
|
||||||
deps = []*Action{a1}
|
deps = []*Action{a1}
|
||||||
}
|
}
|
||||||
for _, p1 := range p.Internal.Imports {
|
for _, p1 := range p.Internal.Imports {
|
||||||
deps = append(deps, b.vetAction(mode, depMode, p1))
|
deps = append(deps, b.vetAction(loaderstate, mode, depMode, p1))
|
||||||
}
|
}
|
||||||
|
|
||||||
a := &Action{
|
a := &Action{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue