зеркало из https://github.com/golang/pkgsite.git
internal/postgres: delete Legacy functions
For golang/go#37102 Change-Id: Icda2856dd6af29267affd075a95974a3c65c0adc Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/317429 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:
Родитель
ab4eaf3df7
Коммит
671ddf2fc1
|
@ -37,7 +37,7 @@ func upsertSymbolHistory(ctx context.Context, ddb *database.DB,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for packagePath, docIDToDoc := range pathToDocIDToDoc {
|
for packagePath, docIDToDoc := range pathToDocIDToDoc {
|
||||||
dbVersionToNameToUnitSymbol, err := LegacyGetSymbolHistoryFromTable(ctx, ddb, packagePath, modulePath)
|
sh, err := GetSymbolHistoryFromTable(ctx, ddb, packagePath, modulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -49,10 +49,13 @@ func upsertSymbolHistory(ctx context.Context, ddb *database.DB,
|
||||||
}
|
}
|
||||||
for _, b := range builds {
|
for _, b := range builds {
|
||||||
dbNameToVersion := map[string]string{}
|
dbNameToVersion := map[string]string{}
|
||||||
for v, nameToUS := range dbVersionToNameToUnitSymbol {
|
for _, v := range sh.Versions() {
|
||||||
for name, us := range nameToUS {
|
nts := sh.SymbolsAtVersion(v)
|
||||||
if us.SupportsBuild(b) {
|
for name, stu := range nts {
|
||||||
dbNameToVersion[name] = v
|
for _, us := range stu {
|
||||||
|
if us.SupportsBuild(b) {
|
||||||
|
dbNameToVersion[name] = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,10 @@ func getPackageSymbols(ctx context.Context, ddb *database.DB, packagePath, modul
|
||||||
sh, collect := collectSymbolHistory(func(sh *internal.SymbolHistory, sm internal.SymbolMeta, v string, build internal.BuildContext) error {
|
sh, collect := collectSymbolHistory(func(sh *internal.SymbolHistory, sm internal.SymbolMeta, v string, build internal.BuildContext) error {
|
||||||
if sm.Section == internal.SymbolSectionTypes && sm.Kind != internal.SymbolKindType {
|
if sm.Section == internal.SymbolSectionTypes && sm.Kind != internal.SymbolKindType {
|
||||||
_, err := sh.GetSymbol(sm.ParentName, v, build)
|
_, err := sh.GetSymbol(sm.ParentName, v, build)
|
||||||
return err
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not find parent for %q: %v", sm.Name, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -88,99 +91,3 @@ func collectSymbolHistory(check func(sh *internal.SymbolHistory, sm internal.Sym
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// legacyGetPackageSymbols returns all of the symbols for a given package path and module path.
|
|
||||||
func legacyGetPackageSymbols(ctx context.Context, ddb *database.DB, packagePath, modulePath string,
|
|
||||||
) (_ map[string]map[string]*internal.UnitSymbol, err error) {
|
|
||||||
defer derrors.Wrap(&err, "legacyGetPackageSymbols(ctx, ddb, %q, %q)", packagePath, modulePath)
|
|
||||||
defer middleware.ElapsedStat(ctx, "getPackageSymbols")()
|
|
||||||
query := `
|
|
||||||
SELECT
|
|
||||||
s1.name AS symbol_name,
|
|
||||||
s2.name AS parent_symbol_name,
|
|
||||||
ps.section,
|
|
||||||
ps.type,
|
|
||||||
ps.synopsis,
|
|
||||||
m.version,
|
|
||||||
d.goos,
|
|
||||||
d.goarch
|
|
||||||
FROM modules m
|
|
||||||
INNER JOIN units u ON u.module_id = m.id
|
|
||||||
INNER JOIN documentation d ON d.unit_id = u.id
|
|
||||||
INNER JOIN documentation_symbols ds ON ds.documentation_id = d.id
|
|
||||||
INNER JOIN package_symbols ps ON ps.id = ds.package_symbol_id
|
|
||||||
INNER JOIN paths p1 ON u.path_id = p1.id
|
|
||||||
INNER JOIN symbol_names s1 ON ps.symbol_name_id = s1.id
|
|
||||||
INNER JOIN symbol_names s2 ON ps.parent_symbol_name_id = s2.id
|
|
||||||
WHERE
|
|
||||||
p1.path = $1
|
|
||||||
AND m.module_path = $2
|
|
||||||
AND NOT m.incompatible
|
|
||||||
AND m.version_type = 'release'
|
|
||||||
ORDER BY
|
|
||||||
CASE WHEN ps.type='Type' THEN 0 ELSE 1 END,
|
|
||||||
symbol_name;`
|
|
||||||
|
|
||||||
// versionToNameToUnitSymbol contains all of the types for this unit,
|
|
||||||
// grouped by name and build context. This is used to keep track of the
|
|
||||||
// parent types, so that we can map the children to those symbols.
|
|
||||||
versionToNameToUnitSymbol := map[string]map[string]*internal.UnitSymbol{}
|
|
||||||
collect := func(rows *sql.Rows) error {
|
|
||||||
var (
|
|
||||||
newUS internal.UnitSymbol
|
|
||||||
build internal.BuildContext
|
|
||||||
v string
|
|
||||||
)
|
|
||||||
if err := rows.Scan(
|
|
||||||
&newUS.Name,
|
|
||||||
&newUS.ParentName,
|
|
||||||
&newUS.Section,
|
|
||||||
&newUS.Kind,
|
|
||||||
&newUS.Synopsis,
|
|
||||||
&v,
|
|
||||||
&build.GOOS,
|
|
||||||
&build.GOARCH,
|
|
||||||
); err != nil {
|
|
||||||
return fmt.Errorf("row.Scan(): %v", err)
|
|
||||||
}
|
|
||||||
if newUS.Section == internal.SymbolSectionTypes && newUS.Kind != internal.SymbolKindType {
|
|
||||||
if err := validateChildSymbol(&newUS, v, build, versionToNameToUnitSymbol); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nts, ok := versionToNameToUnitSymbol[v]
|
|
||||||
if !ok {
|
|
||||||
nts = map[string]*internal.UnitSymbol{}
|
|
||||||
versionToNameToUnitSymbol[v] = nts
|
|
||||||
}
|
|
||||||
us, ok := nts[newUS.Name]
|
|
||||||
if !ok {
|
|
||||||
us = &newUS
|
|
||||||
nts[newUS.Name] = us
|
|
||||||
}
|
|
||||||
us.AddBuildContext(build)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := ddb.RunQuery(ctx, query, collect, packagePath, modulePath); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return versionToNameToUnitSymbol, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateChildSymbol(us *internal.UnitSymbol, v string, build internal.BuildContext,
|
|
||||||
versionToNameToUnitSymbol map[string]map[string]*internal.UnitSymbol) error {
|
|
||||||
nameToUnitSymbol, ok := versionToNameToUnitSymbol[v]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("version %q could not be found: %q", v, us.Name)
|
|
||||||
}
|
|
||||||
parent, ok := nameToUnitSymbol[us.ParentName]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("parent %q could not be found at version %q: %q",
|
|
||||||
us.ParentName, v, us.Name)
|
|
||||||
}
|
|
||||||
if !parent.SupportsBuild(build) {
|
|
||||||
return fmt.Errorf("parent %q does not have build %v at version %q: %q",
|
|
||||||
us.ParentName, build, v, us.Name)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -87,106 +87,6 @@ func GetSymbolHistoryWithPackageSymbols(ctx context.Context, ddb *database.DB,
|
||||||
return symbol.IntroducedHistory(sh)
|
return symbol.IntroducedHistory(sh)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyGetSymbolHistory returns a map of the first version when a symbol name is
|
|
||||||
// added to the API, to the symbol name, to the UnitSymbol struct. The
|
|
||||||
// UnitSymbol.Children field will always be empty, as children names are also
|
|
||||||
// tracked.
|
|
||||||
func (db *DB) LegacyGetSymbolHistory(ctx context.Context, packagePath, modulePath string,
|
|
||||||
) (_ map[string]map[string]*internal.UnitSymbol, err error) {
|
|
||||||
defer derrors.Wrap(&err, "LegacyGetSymbolHistory(ctx, %q, %q)", packagePath, modulePath)
|
|
||||||
defer middleware.ElapsedStat(ctx, "LegacyGetSymbolHistory")()
|
|
||||||
|
|
||||||
if experiment.IsActive(ctx, internal.ExperimentReadSymbolHistory) {
|
|
||||||
return LegacyGetSymbolHistoryFromTable(ctx, db.db, packagePath, modulePath)
|
|
||||||
}
|
|
||||||
return LegacyGetSymbolHistoryWithPackageSymbols(ctx, db.db, packagePath, modulePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LegacyGetSymbolHistoryFromTable fetches symbol history data from the symbol_history table.
|
|
||||||
//
|
|
||||||
// LegacyGetSymbolHistoryFromTable is exported for use in tests.
|
|
||||||
func LegacyGetSymbolHistoryFromTable(ctx context.Context, ddb *database.DB,
|
|
||||||
packagePath, modulePath string) (_ map[string]map[string]*internal.UnitSymbol, err error) {
|
|
||||||
defer derrors.WrapStack(&err, "LegacyGetSymbolHistoryFromTable(ctx, ddb, %q, %q)", packagePath, modulePath)
|
|
||||||
|
|
||||||
q := squirrel.Select(
|
|
||||||
"s1.name AS symbol_name",
|
|
||||||
"s2.name AS parent_symbol_name",
|
|
||||||
"ps.section",
|
|
||||||
"ps.type",
|
|
||||||
"ps.synopsis",
|
|
||||||
"sh.since_version",
|
|
||||||
"sh.goos",
|
|
||||||
"sh.goarch",
|
|
||||||
).From("symbol_history sh").
|
|
||||||
Join("package_symbols ps ON ps.id = sh.package_symbol_id").
|
|
||||||
Join("symbol_names s1 ON ps.symbol_name_id = s1.id").
|
|
||||||
Join("symbol_names s2 ON ps.parent_symbol_name_id = s2.id").
|
|
||||||
Join("paths p1 ON sh.package_path_id = p1.id").
|
|
||||||
Join("paths p2 ON sh.module_path_id = p2.id").
|
|
||||||
Where(squirrel.Eq{"p1.path": packagePath}).
|
|
||||||
Where(squirrel.Eq{"p2.path": modulePath})
|
|
||||||
query, args, err := q.PlaceholderFormat(squirrel.Dollar).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// versionToNameToUnitSymbol is a map of the version a symbol was
|
|
||||||
// introduced, to the name and unit symbol.
|
|
||||||
versionToNameToUnitSymbol := map[string]map[string]*internal.UnitSymbol{}
|
|
||||||
collect := func(rows *sql.Rows) error {
|
|
||||||
var (
|
|
||||||
newUS internal.UnitSymbol
|
|
||||||
build internal.BuildContext
|
|
||||||
v string
|
|
||||||
)
|
|
||||||
if err := rows.Scan(
|
|
||||||
&newUS.Name,
|
|
||||||
&newUS.ParentName,
|
|
||||||
&newUS.Section,
|
|
||||||
&newUS.Kind,
|
|
||||||
&newUS.Synopsis,
|
|
||||||
&v,
|
|
||||||
&build.GOOS,
|
|
||||||
&build.GOARCH,
|
|
||||||
); err != nil {
|
|
||||||
return fmt.Errorf("row.Scan(): %v", err)
|
|
||||||
}
|
|
||||||
nts, ok := versionToNameToUnitSymbol[v]
|
|
||||||
if !ok {
|
|
||||||
nts = map[string]*internal.UnitSymbol{}
|
|
||||||
versionToNameToUnitSymbol[v] = nts
|
|
||||||
}
|
|
||||||
us, ok := nts[newUS.Name]
|
|
||||||
if !ok {
|
|
||||||
us = &newUS
|
|
||||||
nts[newUS.Name] = us
|
|
||||||
}
|
|
||||||
us.AddBuildContext(build)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := ddb.RunQuery(ctx, query, collect, args...); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return versionToNameToUnitSymbol, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LegacyGetSymbolHistoryWithPackageSymbols fetches symbol history data by using data
|
|
||||||
// from package_symbols and documentation_symbols, and computed using
|
|
||||||
// symbol.IntroducedHistory.
|
|
||||||
//
|
|
||||||
// LegacyGetSymbolHistoryWithPackageSymbols is exported for use in tests.
|
|
||||||
func LegacyGetSymbolHistoryWithPackageSymbols(ctx context.Context, ddb *database.DB,
|
|
||||||
packagePath, modulePath string) (_ map[string]map[string]*internal.UnitSymbol, err error) {
|
|
||||||
defer derrors.WrapStack(&err, "GetSymbolHistoryWithPackageSymbols(ctx, ddb, %q, %q)", packagePath, modulePath)
|
|
||||||
defer middleware.ElapsedStat(ctx, "GetSymbolHistoryWithPackageSymbols")()
|
|
||||||
versionToNameToUnitSymbols, err := legacyGetPackageSymbols(ctx, ddb, packagePath, modulePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return symbol.LegacyIntroducedHistory(versionToNameToUnitSymbols), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSymbolHistoryForBuildContext returns a map of the first version when a symbol name is
|
// GetSymbolHistoryForBuildContext returns a map of the first version when a symbol name is
|
||||||
// added to the API for the specified build context, to the symbol name, to the
|
// added to the API for the specified build context, to the symbol name, to the
|
||||||
// UnitSymbol struct. The UnitSymbol.Children field will always be empty, as
|
// UnitSymbol struct. The UnitSymbol.Children field will always be empty, as
|
||||||
|
|
|
@ -63,27 +63,23 @@ func TestInsertSymbolNamesAndHistory(t *testing.T) {
|
||||||
}
|
}
|
||||||
compareUnitSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version,
|
compareUnitSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version,
|
||||||
map[internal.BuildContext][]*internal.Symbol{internal.BuildContextAll: api})
|
map[internal.BuildContext][]*internal.Symbol{internal.BuildContextAll: api})
|
||||||
want2 := map[string]map[string]*internal.UnitSymbol{}
|
want2 := symbolHistoryFromAPI(api, mod.Version)
|
||||||
want2[mod.Version] = unitSymbolsFromAPI(api, mod.Version)
|
|
||||||
comparePackageSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version, want2)
|
comparePackageSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version, want2)
|
||||||
|
|
||||||
gotHist, err := testDB.LegacyGetSymbolHistory(ctx, mod.Packages()[0].Path, mod.ModulePath)
|
gotHist, err := testDB.GetSymbolHistory(ctx, mod.Packages()[0].Path, mod.ModulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
wantHist := map[string]map[string]*internal.UnitSymbol{
|
wantHist := internal.NewSymbolHistory()
|
||||||
"v1.0.0": map[string]*internal.UnitSymbol{
|
wantHist.AddSymbol(sample.Constant.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Constant": unitSymbolFromSymbol(sample.Constant, "v1.0.0"),
|
wantHist.AddSymbol(sample.Variable.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Variable": unitSymbolFromSymbol(sample.Variable, "v1.0.0"),
|
wantHist.AddSymbol(sample.Function.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Function": unitSymbolFromSymbol(sample.Function, "v1.0.0"),
|
wantHist.AddSymbol(sample.Type.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Type": unitSymbolFromSymbol(sample.Type, "v1.0.0"),
|
wantHist.AddSymbol(*sample.Type.Children[0], "v1.0.0", internal.BuildContextAll)
|
||||||
"Type.Field": unitSymbolFromSymbolMeta(sample.Type.Children[0], "v1.0.0", internal.BuildContextAll),
|
wantHist.AddSymbol(*sample.Type.Children[1], "v1.0.0", internal.BuildContextAll)
|
||||||
"New": unitSymbolFromSymbolMeta(sample.Type.Children[1], "v1.0.0", internal.BuildContextAll),
|
wantHist.AddSymbol(*sample.Type.Children[2], "v1.0.0", internal.BuildContextAll)
|
||||||
"Type.Method": unitSymbolFromSymbolMeta(sample.Type.Children[2], "v1.0.0", internal.BuildContextAll),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if diff := cmp.Diff(wantHist, gotHist,
|
if diff := cmp.Diff(wantHist, gotHist,
|
||||||
cmp.AllowUnexported(internal.UnitSymbol{})); diff != "" {
|
cmp.AllowUnexported(internal.UnitSymbol{}, internal.SymbolHistory{})); diff != "" {
|
||||||
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,8 +112,7 @@ func TestInsertSymbolHistory_Basic(t *testing.T) {
|
||||||
|
|
||||||
compareUnitSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version,
|
compareUnitSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version,
|
||||||
map[internal.BuildContext][]*internal.Symbol{internal.BuildContextAll: api})
|
map[internal.BuildContext][]*internal.Symbol{internal.BuildContextAll: api})
|
||||||
want2 := map[string]map[string]*internal.UnitSymbol{}
|
want2 := symbolHistoryFromAPI(api, mod.Version)
|
||||||
want2[mod.Version] = unitSymbolsFromAPI(api, mod.Version)
|
|
||||||
comparePackageSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version, want2)
|
comparePackageSymbols(ctx, t, testDB, mod.Packages()[0].Path, mod.ModulePath, mod.Version, want2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +182,7 @@ func TestInsertSymbolHistory_MultiVersions(t *testing.T) {
|
||||||
compareUnitSymbols(ctx, t, testDB, mod11.Packages()[0].Path, mod11.ModulePath, mod11.Version, want11)
|
compareUnitSymbols(ctx, t, testDB, mod11.Packages()[0].Path, mod11.ModulePath, mod11.Version, want11)
|
||||||
compareUnitSymbols(ctx, t, testDB, mod12.Packages()[0].Path, mod12.ModulePath, mod12.Version, want12)
|
compareUnitSymbols(ctx, t, testDB, mod12.Packages()[0].Path, mod12.ModulePath, mod12.Version, want12)
|
||||||
|
|
||||||
want2 := map[string]map[string]*internal.UnitSymbol{}
|
want2 := internal.NewSymbolHistory()
|
||||||
for _, want := range []struct {
|
for _, want := range []struct {
|
||||||
version string
|
version string
|
||||||
buildToSymbols map[internal.BuildContext][]*internal.Symbol
|
buildToSymbols map[internal.BuildContext][]*internal.Symbol
|
||||||
|
@ -196,13 +191,16 @@ func TestInsertSymbolHistory_MultiVersions(t *testing.T) {
|
||||||
{mod11.Version, want11},
|
{mod11.Version, want11},
|
||||||
{mod12.Version, want12},
|
{mod12.Version, want12},
|
||||||
} {
|
} {
|
||||||
for _, api := range want.buildToSymbols {
|
for build, api := range want.buildToSymbols {
|
||||||
want2[want.version] = unitSymbolsFromAPI(api, want.version)
|
updateSymbols(api, func(s *internal.SymbolMeta) error {
|
||||||
|
want2.AddSymbol(*s, want.version, build)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comparePackageSymbols(ctx, t, testDB, mod10.Packages()[0].Path, mod10.ModulePath, mod10.Version, want2)
|
comparePackageSymbols(ctx, t, testDB, mod10.Packages()[0].Path, mod10.ModulePath, mod10.Version, want2)
|
||||||
|
|
||||||
gotHist, err := testDB.LegacyGetSymbolHistory(ctx, mod10.Packages()[0].Path, mod10.ModulePath)
|
gotHist, err := testDB.GetSymbolHistory(ctx, mod10.Packages()[0].Path, mod10.ModulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -212,19 +210,12 @@ func TestInsertSymbolHistory_MultiVersions(t *testing.T) {
|
||||||
typA.GOARCH = internal.All
|
typA.GOARCH = internal.All
|
||||||
methodA.GOARCH = internal.All
|
methodA.GOARCH = internal.All
|
||||||
methodB.GOARCH = internal.All
|
methodB.GOARCH = internal.All
|
||||||
wantHist := map[string]map[string]*internal.UnitSymbol{
|
wantHist := internal.NewSymbolHistory()
|
||||||
"v1.0.0": map[string]*internal.UnitSymbol{
|
wantHist.AddSymbol(typA.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Foo": unitSymbolFromSymbol(&typA, "v1.0.0"),
|
wantHist.AddSymbol(methodA.SymbolMeta, "v1.1.0", internal.BuildContextAll)
|
||||||
},
|
wantHist.AddSymbol(methodB.SymbolMeta, "v1.2.0", internal.BuildContextAll)
|
||||||
"v1.1.0": {
|
|
||||||
"Foo.A": unitSymbolFromSymbol(&methodA, "v1.1.0"),
|
|
||||||
},
|
|
||||||
"v1.2.0": {
|
|
||||||
"Foo.B": unitSymbolFromSymbol(&methodB, "v1.2.0"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if diff := cmp.Diff(wantHist, gotHist,
|
if diff := cmp.Diff(wantHist, gotHist,
|
||||||
cmp.AllowUnexported(internal.UnitSymbol{})); diff != "" {
|
cmp.AllowUnexported(internal.UnitSymbol{}, internal.SymbolHistory{})); diff != "" {
|
||||||
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,15 +330,19 @@ func TestInsertSymbolHistory_MultiGOOS(t *testing.T) {
|
||||||
compareUnitSymbols(ctx, t, testDB, mod11.Packages()[0].Path, mod11.ModulePath, mod11.Version, want11)
|
compareUnitSymbols(ctx, t, testDB, mod11.Packages()[0].Path, mod11.ModulePath, mod11.Version, want11)
|
||||||
compareUnitSymbols(ctx, t, testDB, mod12.Packages()[0].Path, mod12.ModulePath, mod12.Version, want12)
|
compareUnitSymbols(ctx, t, testDB, mod12.Packages()[0].Path, mod12.ModulePath, mod12.Version, want12)
|
||||||
|
|
||||||
want2 := map[string]map[string]*internal.UnitSymbol{}
|
want2 := internal.NewSymbolHistory()
|
||||||
for _, mod := range []*internal.Module{mod10, mod11, mod12} {
|
for _, mod := range []*internal.Module{mod10, mod11, mod12} {
|
||||||
want2[mod.Version] = map[string]*internal.UnitSymbol{}
|
|
||||||
for _, pkg := range mod.Packages() {
|
for _, pkg := range mod.Packages() {
|
||||||
for _, doc := range pkg.Documentation {
|
for _, doc := range pkg.Documentation {
|
||||||
nameToUnitSym := unitSymbolsFromAPI(doc.API, mod.Version)
|
sh := symbolHistoryFromAPI(doc.API, mod.Version)
|
||||||
for name, unitSym := range nameToUnitSym {
|
for _, v := range sh.Versions() {
|
||||||
if _, ok := want2[mod.Version][name]; !ok {
|
nts := sh.SymbolsAtVersion(v)
|
||||||
want2[mod.Version][name] = unitSym
|
for _, stu := range nts {
|
||||||
|
for sm, us := range stu {
|
||||||
|
for _, b := range us.BuildContexts() {
|
||||||
|
want2.AddSymbol(sm, mod.Version, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,52 +350,25 @@ func TestInsertSymbolHistory_MultiGOOS(t *testing.T) {
|
||||||
}
|
}
|
||||||
comparePackageSymbols(ctx, t, testDB, mod10.Packages()[0].Path, mod10.ModulePath, mod10.Version, want2)
|
comparePackageSymbols(ctx, t, testDB, mod10.Packages()[0].Path, mod10.ModulePath, mod10.Version, want2)
|
||||||
|
|
||||||
gotHist, err := testDB.LegacyGetSymbolHistory(ctx, mod10.Packages()[0].Path, mod10.ModulePath)
|
gotHist, err := testDB.GetSymbolHistory(ctx, mod10.Packages()[0].Path, mod10.ModulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
typ.GOOS = internal.All
|
typ.GOOS = internal.All
|
||||||
typ.GOARCH = internal.All
|
typ.GOARCH = internal.All
|
||||||
wantHist := map[string]map[string]*internal.UnitSymbol{
|
wantHist := internal.NewSymbolHistory()
|
||||||
"v1.0.0": map[string]*internal.UnitSymbol{
|
wantHist.AddSymbol(typ.SymbolMeta, "v1.0.0", internal.BuildContextAll)
|
||||||
"Foo": unitSymbolFromSymbol(&typ, "v1.0.0"),
|
wantHist.AddSymbol(methodA.SymbolMeta, "v1.1.0", internal.BuildContextLinux)
|
||||||
},
|
wantHist.AddSymbol(methodA.SymbolMeta, "v1.1.0", internal.BuildContextWindows)
|
||||||
"v1.1.0": map[string]*internal.UnitSymbol{
|
wantHist.AddSymbol(methodB.SymbolMeta, "v1.1.0", internal.BuildContextJS)
|
||||||
"Foo.A": func() *internal.UnitSymbol {
|
wantHist.AddSymbol(methodB.SymbolMeta, "v1.1.0", internal.BuildContextDarwin)
|
||||||
us := unitSymbolFromSymbol(&methodA, "v1.1.0")
|
wantHist.AddSymbol(methodA.SymbolMeta, "v1.2.0", internal.BuildContextJS)
|
||||||
us.RemoveBuildContexts()
|
wantHist.AddSymbol(methodA.SymbolMeta, "v1.2.0", internal.BuildContextDarwin)
|
||||||
us.AddBuildContext(internal.BuildContextLinux)
|
wantHist.AddSymbol(methodB.SymbolMeta, "v1.2.0", internal.BuildContextLinux)
|
||||||
us.AddBuildContext(internal.BuildContextWindows)
|
wantHist.AddSymbol(methodB.SymbolMeta, "v1.2.0", internal.BuildContextWindows)
|
||||||
return us
|
|
||||||
}(),
|
|
||||||
"Foo.B": func() *internal.UnitSymbol {
|
|
||||||
us := unitSymbolFromSymbol(&methodB, "v1.1.0")
|
|
||||||
us.RemoveBuildContexts()
|
|
||||||
us.AddBuildContext(internal.BuildContextJS)
|
|
||||||
us.AddBuildContext(internal.BuildContextDarwin)
|
|
||||||
return us
|
|
||||||
}(),
|
|
||||||
},
|
|
||||||
"v1.2.0": map[string]*internal.UnitSymbol{
|
|
||||||
"Foo.A": func() *internal.UnitSymbol {
|
|
||||||
us := unitSymbolFromSymbol(&methodA, "v1.2.0")
|
|
||||||
us.RemoveBuildContexts()
|
|
||||||
us.AddBuildContext(internal.BuildContextJS)
|
|
||||||
us.AddBuildContext(internal.BuildContextDarwin)
|
|
||||||
return us
|
|
||||||
}(),
|
|
||||||
"Foo.B": func() *internal.UnitSymbol {
|
|
||||||
us := unitSymbolFromSymbol(&methodB, "v1.2.0")
|
|
||||||
us.RemoveBuildContexts()
|
|
||||||
us.AddBuildContext(internal.BuildContextLinux)
|
|
||||||
us.AddBuildContext(internal.BuildContextWindows)
|
|
||||||
return us
|
|
||||||
}(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if diff := cmp.Diff(wantHist, gotHist,
|
if diff := cmp.Diff(wantHist, gotHist,
|
||||||
cmp.AllowUnexported(internal.UnitSymbol{})); diff != "" {
|
cmp.AllowUnexported(internal.UnitSymbol{}, internal.SymbolHistory{})); diff != "" {
|
||||||
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
t.Fatalf("mismatch on symbol history(-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,42 +441,24 @@ func compareUnitSymbols(ctx context.Context, t *testing.T, testDB *DB,
|
||||||
}
|
}
|
||||||
|
|
||||||
func comparePackageSymbols(ctx context.Context, t *testing.T, testDB *DB,
|
func comparePackageSymbols(ctx context.Context, t *testing.T, testDB *DB,
|
||||||
path, modulePath, version string, want map[string]map[string]*internal.UnitSymbol) {
|
path, modulePath, version string, want *internal.SymbolHistory) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
got, err := legacyGetPackageSymbols(ctx, testDB.db, path, modulePath)
|
got, err := getPackageSymbols(ctx, testDB.db, path, modulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if diff := cmp.Diff(want, got,
|
if diff := cmp.Diff(want, got,
|
||||||
|
cmp.AllowUnexported(internal.UnitSymbol{}, internal.SymbolHistory{}),
|
||||||
cmpopts.IgnoreFields(internal.UnitSymbol{}, "builds")); diff != "" {
|
cmpopts.IgnoreFields(internal.UnitSymbol{}, "builds")); diff != "" {
|
||||||
t.Errorf("mismatch (-want +got):\n%s", diff)
|
t.Errorf("mismatch (-want +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func unitSymbolsFromAPI(api []*internal.Symbol, version string) map[string]*internal.UnitSymbol {
|
func symbolHistoryFromAPI(api []*internal.Symbol, version string) *internal.SymbolHistory {
|
||||||
nameToUnitSymbols := map[string]*internal.UnitSymbol{}
|
sh := internal.NewSymbolHistory()
|
||||||
updateSymbols(api, func(s *internal.SymbolMeta) error {
|
updateSymbols(api, func(s *internal.SymbolMeta) error {
|
||||||
if _, ok := nameToUnitSymbols[s.Name]; !ok {
|
sh.AddSymbol(*s, version, internal.BuildContextAll)
|
||||||
us := unitSymbolFromSymbolMeta(s, version, internal.BuildContextAll)
|
|
||||||
nameToUnitSymbols[s.Name] = us
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return nameToUnitSymbols
|
return sh
|
||||||
}
|
|
||||||
|
|
||||||
func unitSymbolFromSymbol(s *internal.Symbol, version string) *internal.UnitSymbol {
|
|
||||||
us := &internal.UnitSymbol{
|
|
||||||
SymbolMeta: s.SymbolMeta,
|
|
||||||
}
|
|
||||||
us.AddBuildContext(internal.BuildContext{GOOS: s.GOOS, GOARCH: s.GOARCH})
|
|
||||||
return us
|
|
||||||
}
|
|
||||||
|
|
||||||
func unitSymbolFromSymbolMeta(sm *internal.SymbolMeta, version string, b internal.BuildContext) *internal.UnitSymbol {
|
|
||||||
us := &internal.UnitSymbol{
|
|
||||||
SymbolMeta: *sm,
|
|
||||||
}
|
|
||||||
us.AddBuildContext(b)
|
|
||||||
return us
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -540,13 +540,14 @@ func (db *DB) getUnitWithAllFields(ctx context.Context, um *internal.UnitMeta, b
|
||||||
}
|
}
|
||||||
return &u, nil
|
return &u, nil
|
||||||
}
|
}
|
||||||
versionToNameToUnitSymbol, err := LegacyGetSymbolHistoryWithPackageSymbols(ctx, db.db, um.Path,
|
sh, err := GetSymbolHistoryWithPackageSymbols(ctx, db.db, um.Path,
|
||||||
um.ModulePath)
|
um.ModulePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nameToVersion := map[string]string{}
|
nameToVersion := map[string]string{}
|
||||||
for v, nts := range versionToNameToUnitSymbol {
|
for _, v := range sh.Versions() {
|
||||||
|
nts := sh.SymbolsAtVersion(v)
|
||||||
for n := range nts {
|
for n := range nts {
|
||||||
nameToVersion[n] = v
|
nameToVersion[n] = v
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче