Skip to content

Commit 26a8a21

Browse files
committed
cmd/go: use local state object in env.runEnv
This commit modifies `env.runEnv` 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/envcmd rf ' add env.go:/func runEnv\(/-0 var moduleLoaderState *modload.State ex { import "cmd/go/internal/modload"; modload.LoaderState -> moduleLoaderState } add runEnv://+0 moduleLoaderState := modload.NewState() rm env.go:/var moduleLoaderState \*modload.State/ ' Change-Id: I1177df5d09a6ee642eade6cfa4278bb1629843a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/711131 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f2dd3d7 commit 26a8a21

File tree

1 file changed

+4
-3
lines changed
  • src/cmd/go/internal/envcmd

1 file changed

+4
-3
lines changed

src/cmd/go/internal/envcmd/env.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func argKey(arg string) string {
272272
}
273273

274274
func runEnv(ctx context.Context, cmd *base.Command, args []string) {
275+
moduleLoaderState := modload.NewState()
275276
if *envJson && *envU {
276277
base.Fatalf("go: cannot use -json with -u")
277278
}
@@ -306,7 +307,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
306307
}
307308

308309
env := cfg.CmdEnv
309-
env = append(env, ExtraEnvVars(modload.LoaderState)...)
310+
env = append(env, ExtraEnvVars(moduleLoaderState)...)
310311

311312
if err := fsys.Init(); err != nil {
312313
base.Fatal(err)
@@ -336,8 +337,8 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
336337
}
337338
}
338339
if needCostly {
339-
work.BuildInit(modload.LoaderState)
340-
env = append(env, ExtraEnvVarsCostly(modload.LoaderState)...)
340+
work.BuildInit(moduleLoaderState)
341+
env = append(env, ExtraEnvVarsCostly(moduleLoaderState)...)
341342
}
342343

343344
if len(args) > 0 {

0 commit comments

Comments
 (0)