From 988eb0d11e8d96e8ca150f401ed82326b276f653 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 21 May 2025 14:47:49 -0400 Subject: [PATCH] cmd/doc: better support for no network Allow skipping the deprecation check when GOPROXY=off. The deprecation check is an informational message so this doesn't affect the success of the command. We should probably skip the check in more cases when GOPROXY=off but that's a bigger change that should be made in a later release. There are still some deps.dev log messages that we should try to suppress. For #68106 Change-Id: Ifa0efd01ed623bb68c7ad7c5cfb6705547d157a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/675155 LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Matloob Reviewed-by: Michael Matloob Reviewed-by: Sam Thanawalla --- src/cmd/doc/main.go | 10 +++++++++- src/cmd/go/internal/load/pkg.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/doc/main.go b/src/cmd/doc/main.go index ccd8512006..22db39ecc9 100644 --- a/src/cmd/doc/main.go +++ b/src/cmd/doc/main.go @@ -259,10 +259,18 @@ func doPkgsite(urlPath string) error { signal.Ignore(signalsToIgnore...) const version = "v0.0.0-20250520201116-40659211760d" - cmd := exec.Command("go", "run", "golang.org/x/pkgsite/cmd/internal/doc@"+version, + docatversion := "golang.org/x/pkgsite/cmd/internal/doc@" + version + // First download the module and then try to run with GOPROXY=off to circumvent + // the deprecation check. This will allow the pkgsite command to run if it's + // in the module cache but there's no network. + if _, err := runCmd(nil, "go", "mod", "download", docatversion); err != nil { + return err + } + cmd := exec.Command("go", "run", docatversion, "-gorepo", buildCtx.GOROOT, "-http", addr, "-open", path) + cmd.Env = append(os.Environ(), "GOPROXY=off") cmd.Stdout = os.Stderr cmd.Stderr = os.Stderr diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index e913f98852..34e8c90b2f 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -3410,7 +3410,7 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args } rootMod := qrs[0].Mod deprecation, err := modload.CheckDeprecation(ctx, rootMod) - if err != nil { + if err != nil && !errors.Is(err, fs.ErrNotExist) { return nil, fmt.Errorf("%s: %w", args[0], err) } if deprecation != "" { -- 2.50.0