]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: inject State parameter into `workcmd.runSync`
authorIan Alexander <jitsu@google.com>
Thu, 2 Oct 2025 21:00:18 +0000 (17:00 -0400)
committerIan Alexander <jitsu@google.com>
Mon, 20 Oct 2025 20:00:14 +0000 (13:00 -0700)
This command modifies the call tree starting at `workcmd.runSync` 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/workcmd
rf 'inject modload.LoaderState runSync'
cd ..
./rf-cleanup.zsh

Change-Id: Ib8a7b332b89762a7463ace53243cae6aa0ffcc2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/709987
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>
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/workcmd/sync.go

index ba88713b36edd046d5642de75ed089e466bd5a28..12f52381b045e74566f1ec3d685d40cb6e821df6 100644 (file)
@@ -57,14 +57,14 @@ var (
 )
 
 // EnterModule resets MainModules and requirements to refer to just this one module.
-func EnterModule(ctx context.Context, enterModroot string) {
-       LoaderState.MainModules = nil // reset MainModules
-       LoaderState.requirements = nil
-       LoaderState.workFilePath = "" // Force module mode
+func EnterModule(loaderstate *State, ctx context.Context, enterModroot string) {
+       loaderstate.MainModules = nil // reset MainModules
+       loaderstate.requirements = nil
+       loaderstate.workFilePath = "" // Force module mode
        modfetch.Reset()
 
-       LoaderState.modRoots = []string{enterModroot}
-       LoadModFile(LoaderState, ctx)
+       loaderstate.modRoots = []string{enterModroot}
+       LoadModFile(loaderstate, ctx)
 }
 
 // EnterWorkspace enters workspace mode from module mode, applying the updated requirements to the main
index 7f45909de5c3771d38a6a444a72b54878c5f8435..233d12986da76916cb72256fa53bf74c93895adb 100644 (file)
@@ -104,7 +104,7 @@ func runSync(ctx context.Context, cmd *base.Command, args []string) {
 
                // Use EnterModule to reset the global state in modload to be in
                // single-module mode using the modroot of m.
-               modload.EnterModule(ctx, mms.ModRoot(m))
+               modload.EnterModule(modload.LoaderState, ctx, mms.ModRoot(m))
 
                // Edit the build list in the same way that 'go get' would if we
                // requested the relevant module versions explicitly.