Skip to content

Commit cfb4e9b

Browse files
committed
cmd/dist: don't install tools that won't be shipped in distribution
We shouldn't be installing these tools because we will remove them in distpack. Installing the tools will also prevent us from testing what happens when the tools are missing. The changes below this on the stack, CL 677775 (cmd/doc: build cmd/doc directly into the go command) and CL 677636 (cmd/go/internal/cfg: fix GOROOT setting when forcing host config) are needed for this change to pass tests. The doc change is being done so we preserve the properties in the tests that doc can be invoked without doing a build. It's not strictly necessary (we could just remove the tests) but it's nice to have. The GOROOT setting is a significant bug in switching the configuration to host mode: the value of GOROOT wasn't being reset, which caused issues for go commands built with trimpath, because runtime.GOROOT wouldn't have the correct goroot value. For #71867 Change-Id: I4181711ba117066b7d62d7d013ad4b186871cfb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/677558 Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 94764d0 commit cfb4e9b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/cmd/dist/build.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ func cmdbootstrap() {
15161516
}
15171517

15181518
// To recap, so far we have built the new toolchain
1519-
// (cmd/asm, cmd/cgo, cmd/compile, cmd/link)
1519+
// (cmd/asm, cmd/cgo, cmd/compile, cmd/link, cmd/preprofile)
15201520
// using the Go bootstrap toolchain and go command.
15211521
// Then we built the new go command (as go_bootstrap)
15221522
// using the new toolchain and our own build logic (above).
@@ -1589,6 +1589,18 @@ func cmdbootstrap() {
15891589
os.Setenv("GOCACHE", oldgocache)
15901590
}
15911591

1592+
// Keep in sync with binExes in cmd/distpack/pack.go.
1593+
binExesIncludedInDistpack := []string{"cmd/go", "cmd/gofmt"}
1594+
1595+
// Keep in sync with the filter in cmd/distpack/pack.go.
1596+
toolsIncludedInDistpack := []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/cover", "cmd/link", "cmd/preprofile", "cmd/vet"}
1597+
1598+
// We could install all tools in "cmd", but is unnecessary because we will
1599+
// remove them in distpack, so instead install the tools that will actually
1600+
// be included in distpack, which is a superset of toolchain. Not installing
1601+
// the tools will help us test what happens when the tools aren't present.
1602+
toolsToInstall := slices.Concat(binExesIncludedInDistpack, toolsIncludedInDistpack)
1603+
15921604
if goos == oldgoos && goarch == oldgoarch {
15931605
// Common case - not setting up for cross-compilation.
15941606
timelog("build", "toolchain")
@@ -1605,9 +1617,9 @@ func cmdbootstrap() {
16051617
xprintf("\n")
16061618
}
16071619
xprintf("Building commands for host, %s/%s.\n", goos, goarch)
1608-
goInstall(toolenv(), goBootstrap, "cmd")
1609-
checkNotStale(toolenv(), goBootstrap, "cmd")
1610-
checkNotStale(toolenv(), gorootBinGo, "cmd")
1620+
goInstall(toolenv(), goBootstrap, toolsToInstall...)
1621+
checkNotStale(toolenv(), goBootstrap, toolsToInstall...)
1622+
checkNotStale(toolenv(), gorootBinGo, toolsToInstall...)
16111623

16121624
timelog("build", "target toolchain")
16131625
if vflag > 0 {
@@ -1621,12 +1633,12 @@ func cmdbootstrap() {
16211633
xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
16221634
}
16231635
goInstall(nil, goBootstrap, "std")
1624-
goInstall(toolenv(), goBootstrap, "cmd")
1636+
goInstall(toolenv(), goBootstrap, toolsToInstall...)
16251637
checkNotStale(toolenv(), goBootstrap, toolchain...)
16261638
checkNotStale(nil, goBootstrap, "std")
1627-
checkNotStale(toolenv(), goBootstrap, "cmd")
1639+
checkNotStale(toolenv(), goBootstrap, toolsToInstall...)
16281640
checkNotStale(nil, gorootBinGo, "std")
1629-
checkNotStale(toolenv(), gorootBinGo, "cmd")
1641+
checkNotStale(toolenv(), gorootBinGo, toolsToInstall...)
16301642
if debug {
16311643
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
16321644
checkNotStale(toolenv(), goBootstrap, toolchain...)
@@ -1677,7 +1689,7 @@ func cmdbootstrap() {
16771689

16781690
if distpack {
16791691
xprintf("Packaging archives for %s/%s.\n", goos, goarch)
1680-
run("", ShowOutput|CheckExit, pathf("%s/distpack", tooldir))
1692+
run("", ShowOutput|CheckExit, gorootBinGo, "tool", "distpack")
16811693
}
16821694

16831695
// Print trailing banner unless instructed otherwise.

src/cmd/distpack/pack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func main() {
171171
switch strings.TrimSuffix(path.Base(name), ".exe") {
172172
default:
173173
return false
174+
// Keep in sync with toolsIncludedInDistpack in cmd/dist/build.go.
174175
case "asm", "cgo", "compile", "cover", "link", "preprofile", "vet":
175176
}
176177
}
@@ -179,6 +180,7 @@ func main() {
179180

180181
// Add go and gofmt to bin, using cross-compiled binaries
181182
// if this is a cross-compiled distribution.
183+
// Keep in sync with binExesIncludedInDistpack in cmd/dist/build.go.
182184
binExes := []string{
183185
"go",
184186
"gofmt",

0 commit comments

Comments
 (0)