aboutsummaryrefslogtreecommitdiff
path: root/cmd/pkgsite
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2022-06-14 06:40:49 -0400
committerJonathan Amsterdam <jba@google.com>2022-06-14 14:00:03 +0000
commit9ffe8b928e4fbd3ff7dcf984254629a47f8b6e63 (patch)
treee4baa8bdc36a2d642c677f7bd120f471d3026679 /cmd/pkgsite
parent2de536ebca9d4d8ce652f3326158a7b62e8238a2 (diff)
downloadgo-x-pkgsite-9ffe8b928e4fbd3ff7dcf984254629a47f8b6e63.tar.xz
cmd/pkgsite: ignore indirect modules
When `go list -m` lists an indirect module, there is no GoMod path. This was confusing the pkgsite command, because it assumed there was one. Since `go list` doesn't provide enough information to serve indirect modules, ignore them. Fixes golang/go#53323 Change-Id: I0ff9658ee286b2f11dabf76d1bf5f65a9c16ed42 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/412058 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'cmd/pkgsite')
-rw-r--r--cmd/pkgsite/main.go11
-rw-r--r--cmd/pkgsite/main_test.go7
2 files changed, 17 insertions, 1 deletions
diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go
index d4ccf27e..659fcdcf 100644
--- a/cmd/pkgsite/main.go
+++ b/cmd/pkgsite/main.go
@@ -38,6 +38,7 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"flag"
"fmt"
"net/http"
@@ -234,7 +235,8 @@ func defaultCacheDir() (string, error) {
// listedMod has a subset of the fields written by `go list -m`.
type listedMod struct {
internal.Modver
- GoMod string // absolute path to go.mod file; in download cache or replaced
+ GoMod string // absolute path to go.mod file; in download cache or replaced
+ Indirect bool
}
var listModules = _listModules
@@ -275,6 +277,13 @@ func listModsForPaths(paths []string, cacheDir string) ([]string, []internal.Mod
return nil, nil, err
}
for _, lm := range lms {
+ // Ignore indirect modules.
+ if lm.Indirect {
+ continue
+ }
+ if lm.GoMod == "" {
+ return nil, nil, errors.New("empty GoMod: please file a pkgsite bug at https://go.dev/issues/new")
+ }
if strings.HasPrefix(lm.GoMod, cacheDir) {
cacheMods = append(cacheMods, lm.Modver)
} else { // probably the result of a replace directive
diff --git a/cmd/pkgsite/main_test.go b/cmd/pkgsite/main_test.go
index a0dfac3a..4dff62b0 100644
--- a/cmd/pkgsite/main_test.go
+++ b/cmd/pkgsite/main_test.go
@@ -207,10 +207,17 @@ func TestListModsForPaths(t *testing.T) {
{
internal.Modver{Path: "m1", Version: "v1.2.3"},
"/dir/cache/download/m1/@v/v1.2.3.mod",
+ false,
},
{
internal.Modver{Path: "m2", Version: "v1.0.0"},
"/repos/m2/go.mod",
+ false,
+ },
+ {
+ internal.Modver{Path: "indir", Version: "v2.3.4"},
+ "",
+ true,
},
}, nil
}