cmd/go: include 'dist' in 'go tool' list
Some environments remove the 'dist' binary from the toolchain to
save space, as it is primarily needed for building the toolchain itself.
However, 'go tool' users expect it to be listed as a known tool,
especially since 'go tool dist list' remains functional via
internal impersonation.
This change ensures that 'dist' is included in the list displayed
by 'go tool' even when the binary is not physically present in
the tool directory.
diff --git a/src/cmd/go/internal/tool/tool.go b/src/cmd/go/internal/tool/tool.go
index 97c27c8..81b0a16 100644
--- a/src/cmd/go/internal/tool/tool.go
+++ b/src/cmd/go/internal/tool/tool.go
@@ -159,6 +159,21 @@
return
}
+ // cmd/distpack removes the 'dist' tool from the toolchain to save space,
+ // as it is only needed for building the toolchain. However, 'go tool'
+ // users expect it to be listed as a known tool. If it is missing,
+ // manually add it to the list.
+ hasDist := false
+ for _, n := range names {
+ if strings.TrimSuffix(strings.ToLower(n), cfg.ToolExeSuffix()) == "dist" {
+ hasDist = true
+ break
+ }
+ }
+ if !hasDist {
+ names = append(names, "dist")
+ }
+
ambiguous := make(map[string]bool) // names that can't be used as aliases because they are ambiguous
sort.Strings(names)
for _, name := range names {
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I don't think we should be adding another special case,
rather https://github.com/golang/go/issues/75960 should be fixed and all builtin tools including dist should be listed.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I don't think we should be adding another special case,
rather https://github.com/golang/go/issues/75960 should be fixed and all builtin tools including dist should be listed.
Done. Replaced the one-off dist special case with a general
approach: enumerate $GOROOT/src/cmd/ and merge missing
builtin tools using loadBuiltinTool. loadBuiltinTool now also
verifies package main (via go/parser, excluding \_test.go) so
that non-tool packages like cmd/tools and cmd/api are
properly excluded. This fixes #75960 for all tools stripped
by distpack.
This aligns with Michael Matloob's feedback on CL 714560,
where he suggested that loadBuiltinTool itself should
properly return "" for non-tools.
This is my first contribution to Go, so I'd really appreciate
any additional feedback. I'll keep an eye on this CL and
respond promptly. Thanks!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
fmt.Println(name)This is the result of the program execution.
go/bin fix-tool-dist [?↑1] #just shell prompt
❯ ./go tool
addr2line
asm
buildid
cgo
compile
covdata
cover
dist
distpack
fix
link
nm
objdump
pack
pprof
preprofile
test2json
trace
vet
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
fmt.Println(name)This is the result of the program execution.
go/bin fix-tool-dist [?↑1] #just shell prompt
❯ ./go tool
addr2line
asm
buildid
cgo
compile
covdata
cover
dist
distpack
fix
link
nm
objdump
pack
pprof
preprofile
test2json
trace
vet
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
probably should have a test as well
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |