]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/doc: fix GOROOT skew and path joining bugs
authorMichael Matloob <matloob@golang.org>
Tue, 1 Jul 2025 21:16:53 +0000 (17:16 -0400)
committerMichael Matloob <matloob@google.com>
Mon, 7 Jul 2025 20:13:37 +0000 (13:13 -0700)
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 <matloob@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/internal/doc/main.go

index c51fbef5172497c6a1bab7b8409bd69aebea9fea..5032000cda165cfc0116763d3dd6a0e256fb11a0 100644 (file)
@@ -15,6 +15,7 @@ import (
        "io"
        "log"
        "net"
+       "net/url"
        "os"
        "os/exec"
        "os/signal"
@@ -214,7 +215,10 @@ func doPkgsite(urlPath string) error {
                return fmt.Errorf("failed to find port for documentation server: %v", err)
        }
        addr := fmt.Sprintf("localhost:%d", port)
-       path := path.Join("http://"+addr, urlPath)
+       path, err := url.JoinPath("http://"+addr, urlPath)
+       if err != nil {
+               return fmt.Errorf("internal error: failed to construct url: %v", err)
+       }
 
        // Turn off the default signal handler for SIGINT (and SIGQUIT on Unix)
        // and instead wait for the child process to handle the signal and
@@ -223,7 +227,7 @@ func doPkgsite(urlPath string) error {
 
        // Prepend the local download cache to GOPROXY to get around deprecation checks.
        env := os.Environ()
-       vars, err := runCmd(nil, "go", "env", "GOPROXY", "GOMODCACHE")
+       vars, err := runCmd(env, goCmd(), "env", "GOPROXY", "GOMODCACHE")
        fields := strings.Fields(vars)
        if err == nil && len(fields) == 2 {
                goproxy, gomodcache := fields[0], fields[1]
@@ -240,7 +244,7 @@ func doPkgsite(urlPath string) error {
        }
 
        const version = "v0.0.0-20250608123103-82c52f1754cd"
-       cmd := exec.Command("go", "run", "golang.org/x/pkgsite/cmd/internal/doc@"+version,
+       cmd := exec.Command(goCmd(), "run", "golang.org/x/pkgsite/cmd/internal/doc@"+version,
                "-gorepo", buildCtx.GOROOT,
                "-http", addr,
                "-open", path)