Skip to content

Commit f2dd3d7

Browse files
committed
cmd/go: use local state object in vet.runVet
This commit modifies `vet.runVet` to construct a new modload.State object using the new constructor instead of the current global `modload.LoaderState` variable. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/vet rf ' add vet.go:/func run\(/-0 var moduleLoaderState *modload.State ex { import "cmd/go/internal/modload"; modload.LoaderState -> moduleLoaderState } add run://+0 moduleLoaderState := modload.NewState() rm vet.go:/var moduleLoaderState \*modload.State/ ' Change-Id: I31c7f3ea8d301b9210f5afeb632afb5b53e93e46 Reviewed-on: https://go-review.googlesource.com/c/go/+/711130 Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 7847004 commit f2dd3d7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cmd/go/internal/vet/vet.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ var (
118118
)
119119

120120
// run implements both "go vet" and "go fix".
121+
121122
func run(ctx context.Context, cmd *base.Command, args []string) {
123+
moduleLoaderState := modload.NewState()
122124
// Compute flags for the vet/fix tool (e.g. cmd/{vet,fix}).
123125
toolFlags, pkgArgs := toolFlags(cmd, args)
124126

125127
// The vet/fix commands do custom flag processing;
126128
// initialize workspaces after that.
127-
modload.InitWorkfile(modload.LoaderState)
129+
modload.InitWorkfile(moduleLoaderState)
128130

129131
if cfg.DebugTrace != "" {
130132
var close func() error
@@ -143,7 +145,7 @@ func run(ctx context.Context, cmd *base.Command, args []string) {
143145
ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
144146
defer span.Done()
145147

146-
work.BuildInit(modload.LoaderState)
148+
work.BuildInit(moduleLoaderState)
147149

148150
// Flag theory:
149151
//
@@ -218,13 +220,13 @@ func run(ctx context.Context, cmd *base.Command, args []string) {
218220
work.VetFlags = toolFlags
219221

220222
pkgOpts := load.PackageOpts{ModResolveTests: true}
221-
pkgs := load.PackagesAndErrors(modload.LoaderState, ctx, pkgOpts, pkgArgs)
223+
pkgs := load.PackagesAndErrors(moduleLoaderState, ctx, pkgOpts, pkgArgs)
222224
load.CheckPackageErrors(pkgs)
223225
if len(pkgs) == 0 {
224226
base.Fatalf("no packages to %s", cmd.Name())
225227
}
226228

227-
b := work.NewBuilder("", modload.LoaderState.VendorDirOrEmpty)
229+
b := work.NewBuilder("", moduleLoaderState.VendorDirOrEmpty)
228230
defer func() {
229231
if err := b.Close(); err != nil {
230232
base.Fatal(err)
@@ -249,7 +251,7 @@ func run(ctx context.Context, cmd *base.Command, args []string) {
249251

250252
root := &work.Action{Mode: "go " + cmd.Name()}
251253
for _, p := range pkgs {
252-
_, ptest, pxtest, perr := load.TestPackagesFor(modload.LoaderState, ctx, pkgOpts, p, nil)
254+
_, ptest, pxtest, perr := load.TestPackagesFor(moduleLoaderState, ctx, pkgOpts, p, nil)
253255
if perr != nil {
254256
base.Errorf("%v", perr.Error)
255257
continue
@@ -260,10 +262,10 @@ func run(ctx context.Context, cmd *base.Command, args []string) {
260262
}
261263
if len(ptest.GoFiles) > 0 || len(ptest.CgoFiles) > 0 {
262264
// The test package includes all the files of primary package.
263-
root.Deps = append(root.Deps, b.VetAction(modload.LoaderState, work.ModeBuild, work.ModeBuild, ptest))
265+
root.Deps = append(root.Deps, b.VetAction(moduleLoaderState, work.ModeBuild, work.ModeBuild, ptest))
264266
}
265267
if pxtest != nil {
266-
root.Deps = append(root.Deps, b.VetAction(modload.LoaderState, work.ModeBuild, work.ModeBuild, pxtest))
268+
root.Deps = append(root.Deps, b.VetAction(moduleLoaderState, work.ModeBuild, work.ModeBuild, pxtest))
267269
}
268270
}
269271
b.Do(ctx, root)

0 commit comments

Comments
 (0)