Skip to content
Permalink
Browse files
fix(internal/godocfx): filter out non-Cloud (#3878)
  • Loading branch information
tbpg committed Apr 1, 2021
1 parent b32bda9 commit 625aef9b47181cf627587cc9cde9e400713c6678
Showing with 15 additions and 6 deletions.
  1. +2 −2 internal/godocfx/godocfx_test.go
  2. +5 −1 internal/godocfx/main.go
  3. +8 −3 internal/godocfx/parse.go
@@ -37,7 +37,7 @@ func TestMain(m *testing.M) {

func TestParse(t *testing.T) {
mod := "cloud.google.com/go/bigquery"
r, err := parse(mod+"/...", ".", []string{"README.md"})
r, err := parse(mod+"/...", ".", []string{"README.md"}, nil)
if err != nil {
t.Fatalf("Parse: %v", err)
}
@@ -103,7 +103,7 @@ func TestGoldens(t *testing.T) {
extraFiles := []string{"README.md"}

testPath := "cloud.google.com/go/storage"
r, err := parse(testPath, ".", extraFiles)
r, err := parse(testPath, ".", extraFiles, nil)
if err != nil {
t.Fatalf("parse: %v", err)
}
@@ -148,7 +148,11 @@ func process(mod indexEntry, tempDir, outDir string, print bool) error {
}

optionalExtraFiles := []string{}
r, err := parse(mod.Path+"/...", tempDir, optionalExtraFiles)
filter := []string{
"cloud.google.com/go/analytics",
"cloud.google.com/go/area120",
}
r, err := parse(mod.Path+"/...", tempDir, optionalExtraFiles, filter)
if err != nil {
return fmt.Errorf("parse: %v", err)
}
@@ -124,10 +124,10 @@ type result struct {
// workingDir is the directory to use to run go commands.
//
// optionalExtraFiles is a list of paths relative to the module root to include.
func parse(glob string, workingDir string, optionalExtraFiles []string) (*result, error) {
func parse(glob string, workingDir string, optionalExtraFiles []string, filter []string) (*result, error) {
pages := map[string]*page{}

pkgInfos, err := loadPackages(glob, workingDir)
pkgInfos, err := loadPackages(glob, workingDir, filter)
if err != nil {
return nil, err
}
@@ -599,7 +599,7 @@ type pkgInfo struct {
importRenames map[string]string
}

func loadPackages(glob, workingDir string) ([]pkgInfo, error) {
func loadPackages(glob, workingDir string, filter []string) ([]pkgInfo, error) {
config := &packages.Config{
Mode: packages.NeedName | packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedModule | packages.NeedImports | packages.NeedDeps,
Tests: true,
@@ -626,6 +626,11 @@ func loadPackages(glob, workingDir string) ([]pkgInfo, error) {
idToPkg := map[string]*packages.Package{}
pkgNames := []string{}
for _, pkg := range allPkgs {
// Ignore filtered packages.
if hasPrefix(pkg.PkgPath, filter) {
continue
}

id := pkg.ID
// See https://pkg.go.dev/golang.org/x/tools/go/packages#Config.
// The uncompiled test package shows up as "foo_test [foo.test]".

0 comments on commit 625aef9

Please sign in to comment.