зеркало из https://github.com/golang/pkgsite.git
Revert "internal: support "all" in BuildContext"
This reverts commit 5289fe63bf
.
Reason for revert: breaks build
Change-Id: Iedc647645373a2c3e1ddf6a414564edfc4cae406
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290069
Reviewed-by: Julie Qiu <julie@golang.org>
Trust: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Родитель
5289fe63bf
Коммит
33309b4d71
|
@ -11,9 +11,6 @@ type BuildContext struct {
|
|||
GOOS, GOARCH string
|
||||
}
|
||||
|
||||
// All represents all values for a build context element (GOOS or GOARCH).
|
||||
const All = "all"
|
||||
|
||||
// BuildContexts are the build contexts we check when loading a package (see
|
||||
// internal/fetch/load.go).
|
||||
// We store documentation for all of the listed contexts.
|
||||
|
@ -28,14 +25,6 @@ var BuildContexts = []BuildContext{
|
|||
// CompareBuildContexts returns a negative number, 0, or a positive number depending on
|
||||
// the relative positions of c1 and c2 in BuildContexts.
|
||||
func CompareBuildContexts(c1, c2 BuildContext) int {
|
||||
if c1 == c2 {
|
||||
return 0
|
||||
}
|
||||
// We should never see a BuildContext with "all" here.
|
||||
if c1.GOOS == All || c1.GOARCH == All || c2.GOOS == All || c2.GOARCH == All {
|
||||
panic("BuildContext with 'all'")
|
||||
}
|
||||
|
||||
pos := func(c BuildContext) int {
|
||||
for i, d := range BuildContexts {
|
||||
if c == d {
|
||||
|
@ -55,12 +44,12 @@ func (d *Documentation) BuildContext() BuildContext {
|
|||
// DocumentationForBuildContext returns the first Documentation the list that
|
||||
// matches the BuildContext, or nil if none does. A Documentation matches if its
|
||||
// GOOS and GOARCH fields are the same as those of the BuildContext, or if the
|
||||
// Documentation field is "all", or if the BuildContext field is empty. That is,
|
||||
// empty BuildContext fields act as wildcards. So the zero BuildContext will
|
||||
// match the first element of docs, if there is one.
|
||||
// BuildContext field is empty. That is, empty BuildContext fields act as
|
||||
// wildcards. So the zero BuildContext will match the first element of docs, if
|
||||
// there is one.
|
||||
func DocumentationForBuildContext(docs []*Documentation, bc BuildContext) *Documentation {
|
||||
for _, d := range docs {
|
||||
if (bc.GOOS == "" || d.GOOS == All || bc.GOOS == d.GOOS) && (bc.GOARCH == "" || d.GOARCH == All || bc.GOARCH == d.GOARCH) {
|
||||
if (bc.GOOS == "" || bc.GOOS == d.GOOS) && (bc.GOARCH == "" || bc.GOARCH == d.GOARCH) {
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,33 +7,21 @@ package internal
|
|||
import "testing"
|
||||
|
||||
func TestCompareBuildContexts(t *testing.T) {
|
||||
check := func(c1, c2 BuildContext, want int) {
|
||||
t.Helper()
|
||||
got := CompareBuildContexts(c1, c2)
|
||||
switch want {
|
||||
case 0:
|
||||
if got != 0 {
|
||||
t.Errorf("%v vs. %v: got %d, want 0", c1, c2, got)
|
||||
}
|
||||
case 1:
|
||||
if got <= 0 {
|
||||
t.Errorf("%v vs. %v: got %d, want > 0", c1, c2, got)
|
||||
}
|
||||
case -1:
|
||||
if got >= 0 {
|
||||
t.Errorf("%v vs. %v: got %d, want < 0", c1, c2, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, c1 := range BuildContexts {
|
||||
check(c1, c1, 0)
|
||||
if got := CompareBuildContexts(c1, c1); got != 0 {
|
||||
t.Errorf("%v: got %d, want 0", c1, got)
|
||||
}
|
||||
for _, c2 := range BuildContexts[i+1:] {
|
||||
check(c1, c2, -1)
|
||||
check(c2, c1, 1)
|
||||
if got := CompareBuildContexts(c1, c2); got >= 0 {
|
||||
t.Errorf("%v, %v: got %d, want < 0", c1, c2, got)
|
||||
}
|
||||
if got := CompareBuildContexts(c2, c1); got <= 0 {
|
||||
t.Errorf("%v, %v: got %d, want > 0", c2, c1, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special cases.
|
||||
check(BuildContext{"?", "?"}, BuildContexts[len(BuildContexts)-1], 1) // unknown is last
|
||||
got := CompareBuildContexts(BuildContext{"?", "?"}, BuildContexts[len(BuildContexts)-1])
|
||||
if got <= 0 {
|
||||
t.Errorf("unknown vs. last: got %d, want > 0", got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,6 @@ var moduleOnePackage = &testModule{
|
|||
Path: "github.com/basic/foo",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package foo exports a helpful constant.",
|
||||
}},
|
||||
Imports: []string{"net/http"},
|
||||
|
@ -126,8 +124,6 @@ var moduleMultiPackage = &testModule{
|
|||
Contents: "Another README FILE FOR TESTING.",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package bar",
|
||||
}},
|
||||
},
|
||||
|
@ -137,8 +133,6 @@ var moduleMultiPackage = &testModule{
|
|||
Path: "github.com/my/module/foo",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package foo",
|
||||
}},
|
||||
Imports: []string{"fmt", "github.com/my/module/bar"},
|
||||
|
@ -184,8 +178,6 @@ var moduleNoGoMod = &testModule{
|
|||
Path: "no.mod/module/p",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package p is inside a module where a go.mod file hasn't been explicitly added yet.",
|
||||
}},
|
||||
},
|
||||
|
@ -249,8 +241,6 @@ var moduleBadPackages = &testModule{
|
|||
Path: "bad.mod/module/good",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package good is inside a module that has bad packages.",
|
||||
}},
|
||||
},
|
||||
|
@ -407,8 +397,6 @@ var moduleNonRedist = &testModule{
|
|||
Path: "nonredistributable.mod/module/bar",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package bar",
|
||||
}},
|
||||
},
|
||||
|
@ -418,8 +406,6 @@ var moduleNonRedist = &testModule{
|
|||
Path: "nonredistributable.mod/module/bar/baz",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package baz",
|
||||
}},
|
||||
},
|
||||
|
@ -433,8 +419,6 @@ var moduleNonRedist = &testModule{
|
|||
Contents: "README FILE SHOW UP HERE BUT WILL BE REMOVED BEFORE DB INSERT",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package foo",
|
||||
}},
|
||||
Imports: []string{"fmt", "github.com/my/module/bar"},
|
||||
|
@ -484,7 +468,7 @@ var moduleBadImportPath = &testModule{
|
|||
Name: "foo",
|
||||
Path: "bad.import.path.com/good/import/path",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{GOOS: internal.All, GOARCH: internal.All}},
|
||||
Documentation: []*internal.Documentation{{}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -543,8 +527,6 @@ var moduleDocTest = &testModule{
|
|||
Path: "doc.test/permalink",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package permalink is for testing the heading permalink documentation rendering feature.",
|
||||
}},
|
||||
},
|
||||
|
@ -584,8 +566,6 @@ var moduleDocTooLarge = &testModule{
|
|||
Path: "bigdoc.test",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "This documentation is big.",
|
||||
}},
|
||||
},
|
||||
|
@ -694,8 +674,6 @@ var moduleStd = &testModule{
|
|||
Path: "builtin",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package builtin provides documentation for Go's predeclared identifiers.",
|
||||
}},
|
||||
},
|
||||
|
@ -742,8 +720,6 @@ var moduleStd = &testModule{
|
|||
Path: "context",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
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"},
|
||||
|
@ -759,8 +735,6 @@ var moduleStd = &testModule{
|
|||
Path: "encoding/json",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package json implements encoding and decoding of JSON as defined in RFC 7159.",
|
||||
}},
|
||||
Imports: []string{
|
||||
|
@ -787,8 +761,6 @@ var moduleStd = &testModule{
|
|||
Path: "errors",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package errors implements functions to manipulate errors.",
|
||||
}},
|
||||
},
|
||||
|
@ -799,8 +771,6 @@ var moduleStd = &testModule{
|
|||
},
|
||||
Imports: []string{"errors", "fmt", "io", "os", "reflect", "sort", "strconv", "strings", "time"},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package flag implements command-line flag parsing.",
|
||||
}},
|
||||
},
|
||||
|
@ -837,8 +807,6 @@ var moduleMaster = &testModule{
|
|||
Path: "github.com/my/module/foo",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package foo exports a helpful constant.",
|
||||
}},
|
||||
},
|
||||
|
@ -875,8 +843,6 @@ var moduleLatest = &testModule{
|
|||
Path: "github.com/my/module/foo",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "package foo exports a helpful constant.",
|
||||
}},
|
||||
},
|
||||
|
@ -926,8 +892,6 @@ package example_test
|
|||
Path: path + "/example",
|
||||
},
|
||||
Documentation: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
Synopsis: "Package example contains examples.",
|
||||
}},
|
||||
},
|
||||
|
|
|
@ -112,8 +112,8 @@ func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath string,
|
|||
name: name,
|
||||
imports: imports,
|
||||
docs: []*internal.Documentation{{
|
||||
GOOS: internal.All,
|
||||
GOARCH: internal.All,
|
||||
GOOS: bc.GOOS,
|
||||
GOARCH: bc.GOARCH,
|
||||
Synopsis: synopsis,
|
||||
Source: source,
|
||||
}},
|
||||
|
@ -149,14 +149,6 @@ func loadPackage(ctx context.Context, zipGoFiles []*zip.File, innerPath string,
|
|||
pkg.docs = append(pkg.docs, doc)
|
||||
}
|
||||
}
|
||||
// If all the build contexts succeeded and had the same set of files, then
|
||||
// assume that the package doc is valid for all build contexts. Represent
|
||||
// this with a single Documentation whose GOOS and GOARCH are both "all".
|
||||
if len(docsByFiles) == 1 && len(pkg.docs) == len(internal.BuildContexts) {
|
||||
pkg.docs = pkg.docs[:1]
|
||||
pkg.docs[0].GOOS = internal.All
|
||||
pkg.docs[0].GOARCH = internal.All
|
||||
}
|
||||
return pkg, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ var (
|
|||
Synopsis = "This is a package synopsis"
|
||||
ReadmeFilePath = "README.md"
|
||||
ReadmeContents = "readme"
|
||||
GOOS = internal.All
|
||||
GOARCH = internal.All
|
||||
GOOS = "linux"
|
||||
GOARCH = "amd64"
|
||||
)
|
||||
|
||||
// LicenseCmpOpts are options to use when comparing licenses with the cmp package.
|
||||
|
|
Загрузка…
Ссылка в новой задаче