Skip to content

Commit 69673e9

Browse files
committed
cmd/go: use local state object in tool.runTool
This commit modifies `tool.runTool` 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/tool rf ' add tool.go:/func runTool\(/-0 var moduleLoaderState *modload.State ex { import "cmd/go/internal/modload"; modload.LoaderState -> moduleLoaderState } add runTool://+0 moduleLoaderState := modload.NewState() rm tool.go:/var moduleLoaderState \*modload.State/ ' Change-Id: I0aff1bc2b57d973c258510dc52fb877fa824355c Reviewed-on: https://go-review.googlesource.com/c/go/+/711128 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>
1 parent 2e12c5d commit 69673e9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/cmd/go/internal/tool/tool.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ func init() {
7878
}
7979

8080
func runTool(ctx context.Context, cmd *base.Command, args []string) {
81+
moduleLoaderState := modload.NewState()
8182
if len(args) == 0 {
8283
counter.Inc("go/subcommand:tool")
83-
listTools(modload.LoaderState, ctx)
84+
listTools(moduleLoaderState, ctx)
8485
return
8586
}
8687
toolName := args[0]
@@ -108,14 +109,14 @@ func runTool(ctx context.Context, cmd *base.Command, args []string) {
108109
if tool := loadBuiltinTool(toolName); tool != "" {
109110
// Increment a counter for the tool subcommand with the tool name.
110111
counter.Inc("go/subcommand:tool-" + toolName)
111-
buildAndRunBuiltinTool(modload.LoaderState, ctx, toolName, tool, args[1:])
112+
buildAndRunBuiltinTool(moduleLoaderState, ctx, toolName, tool, args[1:])
112113
return
113114
}
114115

115116
// Try to build and run mod tool.
116-
tool := loadModTool(modload.LoaderState, ctx, toolName)
117+
tool := loadModTool(moduleLoaderState, ctx, toolName)
117118
if tool != "" {
118-
buildAndRunModtool(modload.LoaderState, ctx, toolName, tool, args[1:])
119+
buildAndRunModtool(moduleLoaderState, ctx, toolName, tool, args[1:])
119120
return
120121
}
121122

0 commit comments

Comments
 (0)