Skip to content

Commit ef46e1b

Browse files
committed
cmd/internal/doc: fix GOROOT skew and path joining bugs
Use the goCmd() function to get the go command to invoke, so that when GOROOT is set, the go command that's invoked uses the same GOROOT. Otherwise there will be skew between the go command and the tools and runtime. Also use the environment when determining GOPROXY and GOMODCACHE, and use url.Join so the slashes in 'http://' aren't collapsed into one. Change-Id: Ie36ca2fffdb015a7f5f9bd7f514850e41fad2c1a Reviewed-on: https://go-review.googlesource.com/c/go/+/685319 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 75b43f9 commit ef46e1b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/cmd/internal/doc/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"io"
1616
"log"
1717
"net"
18+
"net/url"
1819
"os"
1920
"os/exec"
2021
"os/signal"
@@ -214,7 +215,10 @@ func doPkgsite(urlPath string) error {
214215
return fmt.Errorf("failed to find port for documentation server: %v", err)
215216
}
216217
addr := fmt.Sprintf("localhost:%d", port)
217-
path := path.Join("http://"+addr, urlPath)
218+
path, err := url.JoinPath("http://"+addr, urlPath)
219+
if err != nil {
220+
return fmt.Errorf("internal error: failed to construct url: %v", err)
221+
}
218222

219223
// Turn off the default signal handler for SIGINT (and SIGQUIT on Unix)
220224
// and instead wait for the child process to handle the signal and
@@ -223,7 +227,7 @@ func doPkgsite(urlPath string) error {
223227

224228
// Prepend the local download cache to GOPROXY to get around deprecation checks.
225229
env := os.Environ()
226-
vars, err := runCmd(nil, "go", "env", "GOPROXY", "GOMODCACHE")
230+
vars, err := runCmd(env, goCmd(), "env", "GOPROXY", "GOMODCACHE")
227231
fields := strings.Fields(vars)
228232
if err == nil && len(fields) == 2 {
229233
goproxy, gomodcache := fields[0], fields[1]
@@ -240,7 +244,7 @@ func doPkgsite(urlPath string) error {
240244
}
241245

242246
const version = "v0.0.0-20250608123103-82c52f1754cd"
243-
cmd := exec.Command("go", "run", "golang.org/x/pkgsite/cmd/internal/doc@"+version,
247+
cmd := exec.Command(goCmd(), "run", "golang.org/x/pkgsite/cmd/internal/doc@"+version,
244248
"-gorepo", buildCtx.GOROOT,
245249
"-http", addr,
246250
"-open", path)

0 commit comments

Comments
 (0)