Skip to content

Commit 6425749

Browse files
committed
cmd/distpack: remove more tools from packaged distribution
The "doc", "fix", and "covdata" tools invoked by the go command are not needed for builds. Instead of invoking them directly using the installed binary in the tool directory, use "go tool" to run them, building them if needed. We can then stop distributing those tools in the distribution. covdata is used in tests and can form part of a cached test result, but test results don't have the same requirements as build outputs to be completely determined by the action id. We already don't include a toolid for the covdata tool in the action id for a test run. The more principled way to do things would be to load the covdata package, create the actions to build it, and then depend on the output of that action from the the test action and use that as the covdata tool. For now, it's probably not worth the effort, but, in the future, if we wanted to build a tool like cgo as needed, it would be best to build it in the same action graph. That would introduce a whole bunch of complexity because we'd need to build the tool in the host configuration, and all the configuration parameters are global. For #71867 Change-Id: Id9bbbb5c169296f66c072949f9da552424ecfa2f Reviewed-on: https://go-review.googlesource.com/c/go/+/673119 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Matloob <matloob@google.com>
1 parent 8798f9e commit 6425749

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/cmd/distpack/pack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ func main() {
169169
}
170170
// Inside pkg/tool/$GOOS_$GOARCH, discard helper tools, and tools not needed for builds.
171171
switch strings.TrimSuffix(path.Base(name), ".exe") {
172-
case "addr2line", "api", "buildid", "dist", "distpack", "metadata", "nm", "objdump", "pprof", "test2json", "trace":
172+
case "addr2line", "api", "buildid", "covdata", "dist", "distpack", "doc", "fix",
173+
"metadata", "nm", "objdump", "pprof", "test2json", "trace":
173174
return false
174175
}
175176
}

src/cmd/go/internal/doc/doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"cmd/go/internal/base"
1010
"cmd/go/internal/cfg"
1111
"context"
12+
"path/filepath"
1213
)
1314

1415
var CmdDoc = &base.Command{
@@ -130,5 +131,5 @@ Flags:
130131
}
131132

132133
func runDoc(ctx context.Context, cmd *base.Command, args []string) {
133-
base.Run(cfg.BuildToolexec, base.Tool("doc"), args)
134+
base.Run(cfg.BuildToolexec, filepath.Join(cfg.GOROOTbin, "go"), "tool", "doc", args)
134135
}

src/cmd/go/internal/fix/fix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"fmt"
1717
"go/build"
1818
"os"
19+
"path/filepath"
1920
)
2021

2122
var CmdFix = &base.Command{
@@ -80,6 +81,6 @@ func runFix(ctx context.Context, cmd *base.Command, args []string) {
8081
if *fixes != "" {
8182
fixArg = []string{"-r=" + *fixes}
8283
}
83-
base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), "-go="+goVersion, fixArg, files))
84+
base.Run(str.StringList(cfg.BuildToolexec, filepath.Join(cfg.GOROOTbin, "go"), "tool", "fix", "-go="+goVersion, fixArg, files))
8485
}
8586
}

src/cmd/go/internal/work/cover.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package work
88

99
import (
10-
"cmd/go/internal/base"
1110
"cmd/go/internal/cfg"
1211
"cmd/go/internal/str"
1312
"cmd/internal/cov/covcmd"
@@ -25,7 +24,7 @@ import (
2524
func (b *Builder) CovData(a *Action, cmdargs ...any) ([]byte, error) {
2625
cmdline := str.StringList(cmdargs...)
2726
args := append([]string{}, cfg.BuildToolexec...)
28-
args = append(args, base.Tool("covdata"))
27+
args = append(args, "go", "tool", "covdata")
2928
args = append(args, cmdline...)
3029
return b.Shell(a).runOut(a.Objdir, nil, args)
3130
}

0 commit comments

Comments
 (0)