Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal/godocfx): filter out non-Cloud #3878

Merged
merged 3 commits into from Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/godocfx/godocfx_test.go
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
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
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