diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-01-29 18:44:53 -0500 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-02-02 19:36:47 +0000 |
| commit | 814534999dcbf4fa3d7b358a6de57bf2d44fc450 (patch) | |
| tree | 712ffee18ee7ac7953160860419735cfe0402eec /internal/fetch | |
| parent | 1fe92ed1d8906c5c7253e7f1f03cb008e08a640c (diff) | |
| download | go-x-pkgsite-814534999dcbf4fa3d7b358a6de57bf2d44fc450.tar.xz | |
many: allow for multiple documentations for a Unit
Change internal.Unit.Documentation from a single
internal.Documentation to a slice, so that a Unit can have doc for
multiple build contexts.
However, don't use this ability yet: fetch takes only the first
build context it finds, postgres inserts only the first, frontend
renders only the first, etc.
For golang/go#37232
Change-Id: I17fd1ff2378e0862c029c8077057c207001f6136
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/288217
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/fetch')
| -rw-r--r-- | internal/fetch/fetchdata_test.go | 86 | ||||
| -rw-r--r-- | internal/fetch/helper_test.go | 8 | ||||
| -rw-r--r-- | internal/fetch/unit.go | 2 |
3 files changed, 48 insertions, 48 deletions
diff --git a/internal/fetch/fetchdata_test.go b/internal/fetch/fetchdata_test.go index cfa917b1..dc7804a0 100644 --- a/internal/fetch/fetchdata_test.go +++ b/internal/fetch/fetchdata_test.go @@ -53,9 +53,9 @@ var moduleOnePackage = &testModule{ Name: "foo", Path: "github.com/basic/foo", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package foo exports a helpful constant.", - }, + }}, Imports: []string{"net/http"}, }, }, @@ -123,18 +123,18 @@ var moduleMultiPackage = &testModule{ Filepath: "bar/README.md", Contents: "Another README FILE FOR TESTING.", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package bar", - }, + }}, }, { UnitMeta: internal.UnitMeta{ Name: "foo", Path: "github.com/my/module/foo", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package foo", - }, + }}, Imports: []string{"fmt", "github.com/my/module/bar"}, }, }, @@ -177,9 +177,9 @@ var moduleNoGoMod = &testModule{ Name: "p", Path: "no.mod/module/p", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package p is inside a module where a go.mod file hasn't been explicitly added yet.", - }, + }}, }, }, }, @@ -240,9 +240,9 @@ var moduleBadPackages = &testModule{ Name: "good", Path: "bad.mod/module/good", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package good is inside a module that has bad packages.", - }, + }}, }, }, }, @@ -305,9 +305,9 @@ var moduleBuildConstraints = &testModule{ Name: "cpu", Path: "build.constraints/module/cpu", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package cpu implements processor feature detection used by the Go standard library.", - }, + }}, }, }, }, @@ -396,18 +396,18 @@ var moduleNonRedist = &testModule{ Name: "bar", Path: "nonredistributable.mod/module/bar", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package bar", - }, + }}, }, { UnitMeta: internal.UnitMeta{ Name: "baz", Path: "nonredistributable.mod/module/bar/baz", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package baz", - }, + }}, }, { UnitMeta: internal.UnitMeta{ @@ -418,9 +418,9 @@ var moduleNonRedist = &testModule{ Filepath: "foo/README.md", Contents: "README FILE SHOW UP HERE BUT WILL BE REMOVED BEFORE DB INSERT", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package foo", - }, + }}, Imports: []string{"fmt", "github.com/my/module/bar"}, }, }, @@ -468,7 +468,7 @@ var moduleBadImportPath = &testModule{ Name: "foo", Path: "bad.import.path.com/good/import/path", }, - Documentation: &internal.Documentation{}, + Documentation: []*internal.Documentation{{}}, }, }, }, @@ -526,9 +526,9 @@ var moduleDocTest = &testModule{ Name: "permalink", Path: "doc.test/permalink", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package permalink is for testing the heading permalink documentation rendering feature.", - }, + }}, }, }, }, @@ -565,9 +565,9 @@ var moduleDocTooLarge = &testModule{ Name: "bigdoc", Path: "bigdoc.test", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "This documentation is big.", - }, + }}, }, }, }, @@ -621,11 +621,11 @@ var moduleWasm = &testModule{ Name: "js", Path: "github.com/my/module/js/js", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package js only works with wasm.", GOOS: "js", GOARCH: "wasm", - }, + }}, }, }, }, @@ -673,9 +673,9 @@ var moduleStd = &testModule{ Name: "builtin", Path: "builtin", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package builtin provides documentation for Go's predeclared identifiers.", - }, + }}, }, { UnitMeta: internal.UnitMeta{ @@ -691,9 +691,9 @@ var moduleStd = &testModule{ Filepath: "cmd/pprof/README", Contents: "This directory is the copy of Google's pprof shipped as part of the Go distribution.\n", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Pprof interprets and displays profiles of Go programs.", - }, + }}, Imports: []string{ "cmd/internal/objfile", "crypto/tls", @@ -719,9 +719,9 @@ var moduleStd = &testModule{ Name: "context", Path: "context", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.", - }, + }}, Imports: []string{"errors", "fmt", "reflect", "sync", "time"}, }, { @@ -734,9 +734,9 @@ var moduleStd = &testModule{ Name: "json", Path: "encoding/json", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package json implements encoding and decoding of JSON as defined in RFC 7159.", - }, + }}, Imports: []string{ "bytes", "encoding", @@ -760,9 +760,9 @@ var moduleStd = &testModule{ Name: "errors", Path: "errors", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package errors implements functions to manipulate errors.", - }, + }}, }, { UnitMeta: internal.UnitMeta{ @@ -770,9 +770,9 @@ var moduleStd = &testModule{ Path: "flag", }, Imports: []string{"errors", "fmt", "io", "os", "reflect", "sort", "strconv", "strings", "time"}, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package flag implements command-line flag parsing.", - }, + }}, }, }, }, @@ -806,9 +806,9 @@ var moduleMaster = &testModule{ Name: "foo", Path: "github.com/my/module/foo", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package foo exports a helpful constant.", - }, + }}, }, }, }, @@ -842,9 +842,9 @@ var moduleLatest = &testModule{ Name: "foo", Path: "github.com/my/module/foo", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "package foo exports a helpful constant.", - }, + }}, }, }, }, @@ -891,9 +891,9 @@ package example_test Name: "example", Path: path + "/example", }, - Documentation: &internal.Documentation{ + Documentation: []*internal.Documentation{{ Synopsis: "Package example contains examples.", - }, + }}, }, }, }, diff --git a/internal/fetch/helper_test.go b/internal/fetch/helper_test.go index 1196d191..b03c9341 100644 --- a/internal/fetch/helper_test.go +++ b/internal/fetch/helper_test.go @@ -73,10 +73,10 @@ func cleanFetchResult(t *testing.T, fr *FetchResult, detector *licenses.Detector IsRedistributable: u.IsRedistributable, Licenses: u.Licenses, } - if u.Documentation != nil { - if u.Documentation.GOOS == "" { - u.Documentation.GOOS = "linux" - u.Documentation.GOARCH = "amd64" + if len(u.Documentation) > 0 { + if u.Documentation[0].GOOS == "" { + u.Documentation[0].GOOS = "linux" + u.Documentation[0].GOARCH = "amd64" } } if u.IsPackage() && shouldSetPVS { diff --git a/internal/fetch/unit.go b/internal/fetch/unit.go index 7bce5bb0..4e8d5b3b 100644 --- a/internal/fetch/unit.go +++ b/internal/fetch/unit.go @@ -62,7 +62,7 @@ func moduleUnits(modulePath, version string, dir.Name = pkg.name dir.Imports = pkg.imports // TODO(golang/go#37232): keep all docs - dir.Documentation = pkg.docs[0] + dir.Documentation = pkg.docs[:1] } units = append(units, dir) } |
