Skip to content

Commit

Permalink
fix(internal/godocfx): filter out non-Cloud (#3878)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbpg authored Apr 1, 2021
1 parent b32bda9 commit 625aef9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/godocfx/godocfx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/godocfx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 8 additions & 3 deletions internal/godocfx/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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]".
Expand Down

0 comments on commit 625aef9

Please sign in to comment.