]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: inject State parameter into `work.runBuild`
authorIan Alexander <jitsu@google.com>
Fri, 3 Oct 2025 21:05:08 +0000 (17:05 -0400)
committerIan Alexander <jitsu@google.com>
Mon, 20 Oct 2025 20:02:33 +0000 (13:02 -0700)
This command modifies the call tree starting at `work.runBuild` and
`work.runInstall` 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/work
rf 'inject modload.LoaderState runBuild'
cd ..
./rf-cleanup.zsh
 # cd work
 # rf 'inject modload.LoaderState runInstall'
 # cd ..
 # ./rf-cleanup.zsh

Change-Id: I232452d877211d4ac72f42aa193b30dab9649481
Reviewed-on: https://go-review.googlesource.com/c/go/+/709990
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/internal/work/action.go
src/cmd/go/internal/work/build.go

index 7ef7686942a260ba390b416077f2b2d905c67069..1c6d253be2eead1c80ef9b434d62b90be9fb11f8 100644 (file)
@@ -1112,12 +1112,12 @@ func (b *Builder) addInstallHeaderAction(a *Action) {
 
 // buildmodeShared takes the "go build" action a1 into the building of a shared library of a1.Deps.
 // That is, the input a1 represents "go build pkgs" and the result represents "go build -buildmode=shared pkgs".
-func (b *Builder) buildmodeShared(mode, depMode BuildMode, args []string, pkgs []*load.Package, a1 *Action) *Action {
+func (b *Builder) buildmodeShared(loaderstate *modload.State, mode, depMode BuildMode, args []string, pkgs []*load.Package, a1 *Action) *Action {
        name, err := libname(args, pkgs)
        if err != nil {
                base.Fatalf("%v", err)
        }
-       return b.linkSharedAction(modload.LoaderState, mode, depMode, name, a1)
+       return b.linkSharedAction(loaderstate, mode, depMode, name, a1)
 }
 
 // linkSharedAction takes a grouping action a1 corresponding to a list of built packages
index c02273664396acd27e0ffcc954b5d7e4e49740f6..496247b9a7a7d460b223433e5a311135b2cc96a4 100644 (file)
@@ -554,7 +554,7 @@ func runBuild(ctx context.Context, cmd *base.Command, args []string) {
                a.Deps = append(a.Deps, b.AutoAction(modload.LoaderState, ModeBuild, depMode, p))
        }
        if cfg.BuildBuildmode == "shared" {
-               a = b.buildmodeShared(ModeBuild, depMode, args, pkgs, a)
+               a = b.buildmodeShared(modload.LoaderState, ModeBuild, depMode, args, pkgs, a)
        }
        b.Do(ctx, a)
 }
@@ -819,7 +819,7 @@ func InstallPackages(ctx context.Context, patterns []string, pkgs []*load.Packag
                // tools above did not apply, and a is just a simple Action
                // with a list of Deps, one per package named in pkgs,
                // the same as in runBuild.
-               a = b.buildmodeShared(ModeInstall, ModeInstall, patterns, pkgs, a)
+               a = b.buildmodeShared(modload.LoaderState, ModeInstall, ModeInstall, patterns, pkgs, a)
        }
 
        b.Do(ctx, a)