Skip to content

Commit dab6e85

Browse files
committed
internal/fetch: collapse identical build contexts
If all the build contexts for a package produce the same documentation, then return a single Documentation with build context all/all. This will save a lot of space in the documentation table, since most packages will fit into this case. For golang/go#37232 Change-Id: I15237242e0c3ca3c7b8f8c8944b227afebd23785 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/289680 Trust: Jonathan Amsterdam <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent 7425dc1 commit dab6e85

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

internal/fetch/fetchdata_test.go

+50-9
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,28 @@ var moduleBuildConstraints = &testModule{
315315
Name: "cpu",
316316
Path: "build.constraints/module/cpu",
317317
},
318-
Documentation: []*internal.Documentation{{
319-
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
320-
}},
318+
Documentation: []*internal.Documentation{
319+
{
320+
GOOS: "linux",
321+
GOARCH: "amd64",
322+
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
323+
},
324+
{
325+
GOOS: "windows",
326+
GOARCH: "amd64",
327+
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
328+
},
329+
{
330+
GOOS: "darwin",
331+
GOARCH: "amd64",
332+
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
333+
},
334+
{
335+
GOOS: "js",
336+
GOARCH: "wasm",
337+
Synopsis: "Package cpu implements processor feature detection used by the Go standard library.",
338+
},
339+
},
321340
},
322341
},
323342
},
@@ -609,7 +628,6 @@ var moduleWasm = &testModule{
609628
mod: &proxy.Module{
610629
ModulePath: "github.com/my/module/js",
611630
Files: map[string]string{
612-
613631
"README.md": "THIS IS A README",
614632
"LICENSE": testhelper.BSD0License,
615633
"js/js.go": `
@@ -666,6 +684,8 @@ var moduleStd = &testModule{
666684
mod: &proxy.Module{
667685
ModulePath: stdlib.ModulePath,
668686
Version: "v1.12.5",
687+
// No files necessary because the internal/stdlib package will read from
688+
// internal/stdlib/testdata.
669689
},
670690
fr: &FetchResult{
671691
Module: &internal.Module{
@@ -679,8 +699,7 @@ var moduleStd = &testModule{
679699
Units: []*internal.Unit{
680700
{
681701
UnitMeta: internal.UnitMeta{
682-
Path: "std",
683-
702+
Path: "std",
684703
IsRedistributable: true,
685704
},
686705
Readme: &internal.Readme{
@@ -713,9 +732,31 @@ var moduleStd = &testModule{
713732
Filepath: "cmd/pprof/README",
714733
Contents: "This directory is the copy of Google's pprof shipped as part of the Go distribution.\n",
715734
},
716-
Documentation: []*internal.Documentation{{
717-
Synopsis: "Pprof interprets and displays profiles of Go programs.",
718-
}},
735+
// cmd/pprof has a file with a build constraint that does not include js/wasm.
736+
// Since the set files isn't the same across all build contexts, we represent
737+
// every build context.
738+
Documentation: []*internal.Documentation{
739+
{
740+
GOOS: "linux",
741+
GOARCH: "amd64",
742+
Synopsis: "Pprof interprets and displays profiles of Go programs.",
743+
},
744+
{
745+
GOOS: "windows",
746+
GOARCH: "amd64",
747+
Synopsis: "Pprof interprets and displays profiles of Go programs.",
748+
},
749+
{
750+
GOOS: "darwin",
751+
GOARCH: "amd64",
752+
Synopsis: "Pprof interprets and displays profiles of Go programs.",
753+
},
754+
{
755+
GOOS: "js",
756+
GOARCH: "wasm",
757+
Synopsis: "Pprof interprets and displays profiles of Go programs.",
758+
},
759+
},
719760
Imports: []string{
720761
"cmd/internal/objfile",
721762
"crypto/tls",

internal/fetch/helper_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ func cleanFetchResult(t *testing.T, fr *FetchResult, detector *licenses.Detector
7373
IsRedistributable: u.IsRedistributable,
7474
Licenses: u.Licenses,
7575
}
76-
if len(u.Documentation) > 0 {
77-
if u.Documentation[0].GOOS == "" {
78-
u.Documentation[0].GOOS = "linux"
79-
u.Documentation[0].GOARCH = "amd64"
80-
}
81-
}
8276
if u.IsPackage() && shouldSetPVS {
8377
fr.PackageVersionStates = append(
8478
fr.PackageVersionStates, &internal.PackageVersionState{

internal/fetch/load.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath string,
103103
// No package for this build context.
104104
continue
105105
case errors.Is(err, godoc.ErrTooLarge):
106-
// The doc for this build context is too large. Remember that and
107-
// return the package for this build context; ignore the others.
106+
// The doc for this build context is too large. To keep things
107+
// simple, return a single package with this error that will be used
108+
// for all build contexts, and ignore the others.
108109
return &goPackage{
109110
err: err,
110111
path: importPath,
@@ -162,6 +163,7 @@ func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath string,
162163

163164
// mapKeyForFiles generates a value that corresponds to the given set of file
164165
// names and can be used as a map key.
166+
// It assumes the filenames do not contain spaces.
165167
func mapKeyForFiles(files map[string][]byte) string {
166168
var names []string
167169
for n := range files {

internal/fetch/unit.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ func moduleUnits(modulePath, version string,
6161
if pkg, ok := pkgLookup[dirPath]; ok {
6262
dir.Name = pkg.name
6363
dir.Imports = pkg.imports
64-
// TODO(golang/go#37232): keep all docs
65-
dir.Documentation = pkg.docs[:1]
64+
dir.Documentation = pkg.docs
6665
}
6766
units = append(units, dir)
6867
}

0 commit comments

Comments
 (0)