зеркало из https://github.com/golang/pkgsite.git
internal/postgres: change buildcontext key in getSymbolHistory
Instead of using a custom string as the key in getSymbolHistory, just use internal.BuildContext. For golang/go#37102 Change-Id: I87feabd36a6b33fc9a34bd5cf3ab0012bdbbf012 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/294689 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Родитель
8902259535
Коммит
a45850f691
|
@ -14,15 +14,23 @@ type BuildContext struct {
|
|||
// All represents all values for a build context element (GOOS or GOARCH).
|
||||
const All = "all"
|
||||
|
||||
var (
|
||||
BuildContextAll = BuildContext{All, All}
|
||||
BuildContextLinux = BuildContext{"linux", "amd64"}
|
||||
BuildContextWindows = BuildContext{"windows", "amd64"}
|
||||
BuildContextDarwin = BuildContext{"darwin", "amd64"}
|
||||
BuildContextJS = BuildContext{"js", "wasm"}
|
||||
)
|
||||
|
||||
// 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.
|
||||
// The order determines which environment's docs we will show as the default.
|
||||
var BuildContexts = []BuildContext{
|
||||
{"linux", "amd64"},
|
||||
{"windows", "amd64"},
|
||||
{"darwin", "amd64"},
|
||||
{"js", "wasm"},
|
||||
BuildContextLinux,
|
||||
BuildContextWindows,
|
||||
BuildContextDarwin,
|
||||
BuildContextJS,
|
||||
}
|
||||
|
||||
// CompareBuildContexts returns a negative number, 0, or a positive number depending on
|
||||
|
|
|
@ -45,7 +45,7 @@ func insertSymbols(ctx context.Context, db *database.DB, modulePath, version str
|
|||
builds = internal.BuildContexts
|
||||
}
|
||||
for _, build := range builds {
|
||||
nameToSymbol := buildToNameToSym[goosgoarch(build.GOOS, build.GOARCH)]
|
||||
nameToSymbol := buildToNameToSym[internal.BuildContext{GOOS: build.GOOS, GOARCH: build.GOARCH}]
|
||||
updateSymbols(doc.API, func(s *internal.Symbol) (err error) {
|
||||
defer derrors.WrapStack(&err, "updateSymbols(%q)", s.Name)
|
||||
if !shouldUpdateSymbolHistory(s.Name, version, nameToSymbol) {
|
||||
|
@ -207,7 +207,7 @@ func upsertSymbolNamesReturningIDs(ctx context.Context, db *database.DB, pathToD
|
|||
return symbols, nil
|
||||
}
|
||||
|
||||
func getSymbolHistory(ctx context.Context, db *database.DB, packagePath, modulePath string) (_ map[string]map[string]*internal.Symbol, err error) {
|
||||
func getSymbolHistory(ctx context.Context, db *database.DB, packagePath, modulePath string) (_ map[internal.BuildContext]map[string]*internal.Symbol, err error) {
|
||||
defer derrors.Wrap(&err, "getSymbolHistoryForPath(ctx, db, %q, %q)", packagePath, modulePath)
|
||||
query := `
|
||||
SELECT
|
||||
|
@ -228,7 +228,7 @@ func getSymbolHistory(ctx context.Context, db *database.DB, packagePath, moduleP
|
|||
WHERE p1.path = $1 AND p2.path = $2;`
|
||||
|
||||
// Map from GOOS/GOARCH to (map from symbol name to symbol).
|
||||
buildToNameToSym := map[string]map[string]*internal.Symbol{}
|
||||
buildToNameToSym := map[internal.BuildContext]map[string]*internal.Symbol{}
|
||||
collect := func(rows *sql.Rows) error {
|
||||
var (
|
||||
sh internal.Symbol
|
||||
|
@ -245,10 +245,10 @@ func getSymbolHistory(ctx context.Context, db *database.DB, packagePath, moduleP
|
|||
); err != nil {
|
||||
return fmt.Errorf("row.Scan(): %v", err)
|
||||
}
|
||||
nameToSym, ok := buildToNameToSym[goosgoarch(sh.GOOS, sh.GOARCH)]
|
||||
nameToSym, ok := buildToNameToSym[internal.BuildContext{GOOS: sh.GOOS, GOARCH: sh.GOARCH}]
|
||||
if !ok {
|
||||
nameToSym = map[string]*internal.Symbol{}
|
||||
buildToNameToSym[goosgoarch(sh.GOOS, sh.GOARCH)] = nameToSym
|
||||
buildToNameToSym[internal.BuildContext{GOOS: sh.GOOS, GOARCH: sh.GOARCH}] = nameToSym
|
||||
}
|
||||
nameToSym[sh.Name] = &sh
|
||||
return nil
|
||||
|
@ -259,10 +259,6 @@ func getSymbolHistory(ctx context.Context, db *database.DB, packagePath, moduleP
|
|||
return buildToNameToSym, nil
|
||||
}
|
||||
|
||||
func goosgoarch(goos, goarch string) string {
|
||||
return fmt.Sprintf("goos=%s_goarch=%s", goos, goarch)
|
||||
}
|
||||
|
||||
func updateSymbols(symbols []*internal.Symbol, updateFunc func(s *internal.Symbol) error) error {
|
||||
for _, s := range symbols {
|
||||
if err := updateFunc(s); err != nil {
|
||||
|
@ -292,7 +288,7 @@ func (db *DB) CompareStdLib(ctx context.Context) (map[string][]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
// symbol.ParsePackageAPIInfo does not support OS/ARCH-dependent symbols.
|
||||
data := hist[goosgoarch("linux", "amd64")]
|
||||
data := hist[internal.BuildContext{GOOS: "linux", GOARCH: "amd64"}]
|
||||
errs := symbol.CompareStdLib(path, apiVersions[path], data)
|
||||
if len(errs) > 0 {
|
||||
pkgToErrors[path] = errs
|
||||
|
|
|
@ -196,11 +196,11 @@ func TestInsertSymbolHistory(t *testing.T) {
|
|||
SinceVersion: "v1.0.0",
|
||||
},
|
||||
}
|
||||
wantHist := map[string]map[string]*internal.Symbol{
|
||||
goosgoarch("darwin", "amd64"): symbols,
|
||||
goosgoarch("js", "wasm"): symbols,
|
||||
goosgoarch("linux", "amd64"): symbols,
|
||||
goosgoarch("windows", "amd64"): symbols,
|
||||
wantHist := map[internal.BuildContext]map[string]*internal.Symbol{
|
||||
internal.BuildContextDarwin: symbols,
|
||||
internal.BuildContextJS: symbols,
|
||||
internal.BuildContextLinux: symbols,
|
||||
internal.BuildContextWindows: symbols,
|
||||
}
|
||||
if diff := cmp.Diff(wantHist, gotHist,
|
||||
cmpopts.IgnoreFields(internal.Symbol{}, "GOOS", "GOARCH")); diff != "" {
|
||||
|
@ -259,11 +259,11 @@ func TestInsertSymbolHistory_MultiVersions(t *testing.T) {
|
|||
"Foo.A": methodA,
|
||||
"Foo.B": methodB,
|
||||
}
|
||||
wantHist := map[string]map[string]*internal.Symbol{
|
||||
goosgoarch("darwin", "amd64"): symbols,
|
||||
goosgoarch("js", "wasm"): symbols,
|
||||
goosgoarch("linux", "amd64"): symbols,
|
||||
goosgoarch("windows", "amd64"): symbols,
|
||||
wantHist := map[internal.BuildContext]map[string]*internal.Symbol{
|
||||
internal.BuildContextDarwin: symbols,
|
||||
internal.BuildContextJS: symbols,
|
||||
internal.BuildContextLinux: symbols,
|
||||
internal.BuildContextWindows: symbols,
|
||||
}
|
||||
if diff := cmp.Diff(wantHist, gotHist,
|
||||
cmpopts.IgnoreFields(internal.Symbol{}, "GOOS", "GOARCH")); diff != "" {
|
||||
|
@ -342,23 +342,23 @@ func TestInsertSymbolHistory_MultiGOOS(t *testing.T) {
|
|||
b1 := func() *internal.Symbol { b := methodB; b.SinceVersion = "v1.2.0"; return &b }()
|
||||
a2 := func() *internal.Symbol { a := methodA; a.SinceVersion = "v1.2.0"; return &a }()
|
||||
b2 := func() *internal.Symbol { b := methodB; b.SinceVersion = "v1.1.0"; return &b }()
|
||||
wantHist := map[string]map[string]*internal.Symbol{
|
||||
goosgoarch("linux", "amd64"): {
|
||||
wantHist := map[internal.BuildContext]map[string]*internal.Symbol{
|
||||
internal.BuildContextLinux: {
|
||||
"Foo": parent,
|
||||
"Foo.A": a1,
|
||||
"Foo.B": b1,
|
||||
},
|
||||
goosgoarch("windows", "amd64"): {
|
||||
internal.BuildContextWindows: {
|
||||
"Foo": parent,
|
||||
"Foo.A": a1,
|
||||
"Foo.B": b1,
|
||||
},
|
||||
goosgoarch("darwin", "amd64"): {
|
||||
internal.BuildContextDarwin: {
|
||||
"Foo": parent,
|
||||
"Foo.A": a2,
|
||||
"Foo.B": b2,
|
||||
},
|
||||
goosgoarch("js", "wasm"): {
|
||||
internal.BuildContextJS: {
|
||||
"Foo": parent,
|
||||
"Foo.A": a2,
|
||||
"Foo.B": b2,
|
||||
|
|
Загрузка…
Ссылка в новой задаче