Skip to content

Commit 4828981

Browse files
prattmicgopherbot
authored andcommitted
gopls/internal/telemetry/cmd/stacks: build compiler from root
Currently we build cmd/compile from the current directory. Unfortunately, if the current directory happens to contain a go.mod file, the `go` directive restricts the GOTOOLCHAINs that are allowed. For example, gopls go.mod says `go 1.23.4`. Running stacks from its directory is thus unable to build a compiler older than 1.23.4. To avoid this, switch to root when building the compiler, assuming that root won't contain a go.mod. We can now drop GOWORK=off, as root presumably won't contain a go.work either. Change-Id: I6a6a636ccb6fd2b04db3352e17dc28310fc8d069 Reviewed-on: https://go-review.googlesource.com/c/tools/+/642935 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 3f87563 commit 4828981

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gopls/internal/telemetry/cmd/stacks/stacks.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,11 @@ func readPCLineTable(info Info, stacksDir string) (map[string]FileLine, error) {
989989
buildDir = filepath.Join(revDir, "gopls")
990990
case "cmd/compile":
991991
// Nothing to do, GOTOOLCHAIN is sufficient.
992+
993+
// Switch build directories so if we happen to be in Go module
994+
// directory its go.mod doesn't restrict the toolchain versions
995+
// we're allowed to use.
996+
buildDir = "/"
992997
default:
993998
return nil, fmt.Errorf("don't know how to build unknown program %s", info.Program)
994999
}
@@ -1014,7 +1019,6 @@ func readPCLineTable(info Info, stacksDir string) (map[string]FileLine, error) {
10141019
"GOEXPERIMENT=", // Don't forward GOEXPERIMENT from current environment since the GOTOOLCHAIN selected might not support the same experiments.
10151020
"GOOS="+info.GOOS,
10161021
"GOARCH="+info.GOARCH,
1017-
"GOWORK=off",
10181022
)
10191023
if err := cmd.Run(); err != nil {
10201024
return nil, fmt.Errorf("building: %v (rm -fr %s?)", err, stacksDir)

0 commit comments

Comments
 (0)