Skip to content

Commit 7b506d1

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

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/cmd/go/internal/generate/generate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ func init() {
182182
}
183183

184184
func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
185-
modload.InitWorkfile(modload.LoaderState)
185+
moduleLoaderState := modload.NewState()
186+
modload.InitWorkfile(moduleLoaderState)
186187

187188
if generateRunFlag != "" {
188189
var err error
@@ -204,8 +205,8 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
204205
// Even if the arguments are .go files, this loop suffices.
205206
printed := false
206207
pkgOpts := load.PackageOpts{IgnoreImports: true}
207-
for _, pkg := range load.PackagesAndErrors(modload.LoaderState, ctx, pkgOpts, args) {
208-
if modload.Enabled(modload.LoaderState) && pkg.Module != nil && !pkg.Module.Main {
208+
for _, pkg := range load.PackagesAndErrors(moduleLoaderState, ctx, pkgOpts, args) {
209+
if modload.Enabled(moduleLoaderState) && pkg.Module != nil && !pkg.Module.Main {
209210
if !printed {
210211
fmt.Fprintf(os.Stderr, "go: not generating in packages in dependency modules\n")
211212
printed = true

0 commit comments

Comments
 (0)