From bfc0fe820788a9afc433bdaa3cb0fad048612ba1 Mon Sep 17 00:00:00 2001 From: Kirtan Soni Date: Mon, 17 Mar 2025 03:29:52 -0700 Subject: [PATCH 1/2] cmd/go: respect -n flag in 'go tool' command Set BuildN to toolN to properly respect the -n flag in 'go tool' commands, preventing unnecessary builds when only printing commands. --- src/cmd/go/internal/tool/tool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/go/internal/tool/tool.go b/src/cmd/go/internal/tool/tool.go index 7033eb1d9c3587..f0ea21d1689707 100644 --- a/src/cmd/go/internal/tool/tool.go +++ b/src/cmd/go/internal/tool/tool.go @@ -302,6 +302,7 @@ func buildAndRunModtool(ctx context.Context, tool string, args []string) { p.Internal.OmitDebug = true p.Internal.ExeName = p.DefaultExecName() + cfg.BuildN = toolN a1 := b.LinkAction(work.ModeBuild, work.ModeBuild, p) a1.CacheExecutable = true a := &work.Action{Mode: "go tool", Actor: work.ActorFunc(runBuiltTool), Args: args, Deps: []*work.Action{a1}} From cb5699f7e154a07d71675b0bc30ac5409e0d3580 Mon Sep 17 00:00:00 2001 From: Kirtan Soni Date: Mon, 17 Mar 2025 13:25:09 -0700 Subject: [PATCH 2/2] cmd/go: more consistent documentation --- src/cmd/go/internal/tool/tool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/tool/tool.go b/src/cmd/go/internal/tool/tool.go index f0ea21d1689707..18d0804bc9aa9d 100644 --- a/src/cmd/go/internal/tool/tool.go +++ b/src/cmd/go/internal/tool/tool.go @@ -44,7 +44,7 @@ may be defined in the go.mod of the current module. With no arguments it prints the list of known tools. The -n flag causes tool to print the command that would be -executed but not execute it. +executed but not execute it. (the path to the executable shown may not actually exist.) The -modfile=file.mod build flag causes tool to use an alternate file instead of the go.mod in the module root directory.