Skip to content

Commit 625aef9

Browse files
authored
fix(internal/godocfx): filter out non-Cloud (#3878)
1 parent b32bda9 commit 625aef9

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

internal/godocfx/godocfx_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestMain(m *testing.M) {
3737

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

105105
testPath := "cloud.google.com/go/storage"
106-
r, err := parse(testPath, ".", extraFiles)
106+
r, err := parse(testPath, ".", extraFiles, nil)
107107
if err != nil {
108108
t.Fatalf("parse: %v", err)
109109
}

internal/godocfx/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ func process(mod indexEntry, tempDir, outDir string, print bool) error {
148148
}
149149

150150
optionalExtraFiles := []string{}
151-
r, err := parse(mod.Path+"/...", tempDir, optionalExtraFiles)
151+
filter := []string{
152+
"cloud.google.com/go/analytics",
153+
"cloud.google.com/go/area120",
154+
}
155+
r, err := parse(mod.Path+"/...", tempDir, optionalExtraFiles, filter)
152156
if err != nil {
153157
return fmt.Errorf("parse: %v", err)
154158
}

internal/godocfx/parse.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ type result struct {
124124
// workingDir is the directory to use to run go commands.
125125
//
126126
// optionalExtraFiles is a list of paths relative to the module root to include.
127-
func parse(glob string, workingDir string, optionalExtraFiles []string) (*result, error) {
127+
func parse(glob string, workingDir string, optionalExtraFiles []string, filter []string) (*result, error) {
128128
pages := map[string]*page{}
129129

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

602-
func loadPackages(glob, workingDir string) ([]pkgInfo, error) {
602+
func loadPackages(glob, workingDir string, filter []string) ([]pkgInfo, error) {
603603
config := &packages.Config{
604604
Mode: packages.NeedName | packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedModule | packages.NeedImports | packages.NeedDeps,
605605
Tests: true,
@@ -626,6 +626,11 @@ func loadPackages(glob, workingDir string) ([]pkgInfo, error) {
626626
idToPkg := map[string]*packages.Package{}
627627
pkgNames := []string{}
628628
for _, pkg := range allPkgs {
629+
// Ignore filtered packages.
630+
if hasPrefix(pkg.PkgPath, filter) {
631+
continue
632+
}
633+
629634
id := pkg.ID
630635
// See https://pkg.go.dev/golang.org/x/tools/go/packages#Config.
631636
// The uncompiled test package shows up as "foo_test [foo.test]".

0 commit comments

Comments
 (0)