]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use local state object in `env.runEnv`
authorIan Alexander <jitsu@google.com>
Fri, 10 Oct 2025 01:05:35 +0000 (21:05 -0400)
committerIan Alexander <jitsu@google.com>
Sat, 25 Oct 2025 01:10:22 +0000 (18:10 -0700)
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 <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index aaadc2fde1e322351a65e31fbf202b9de6cd7128..f600a354727ae1a95122155a67785383376ec293 100644 (file)
@@ -272,6 +272,7 @@ func argKey(arg string) string {
 }
 
 func runEnv(ctx context.Context, cmd *base.Command, args []string) {
+       moduleLoaderState := modload.NewState()
        if *envJson && *envU {
                base.Fatalf("go: cannot use -json with -u")
        }
@@ -306,7 +307,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
        }
 
        env := cfg.CmdEnv
-       env = append(env, ExtraEnvVars(modload.LoaderState)...)
+       env = append(env, ExtraEnvVars(moduleLoaderState)...)
 
        if err := fsys.Init(); err != nil {
                base.Fatal(err)
@@ -336,8 +337,8 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
                }
        }
        if needCostly {
-               work.BuildInit(modload.LoaderState)
-               env = append(env, ExtraEnvVarsCostly(modload.LoaderState)...)
+               work.BuildInit(moduleLoaderState)
+               env = append(env, ExtraEnvVarsCostly(moduleLoaderState)...)
        }
 
        if len(args) > 0 {