Skip to content

Commit 71978c4

Browse files
authored
Ignore vendor/ while scanning pkgs (#5)
Ignore vendor/ while scanning pkgs
2 parents 6331eca + 0657349 commit 71978c4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,18 @@ func parseAPIPackages(dir string) ([]*types.Package, error) {
190190
}
191191
var pkgNames []string
192192
for p := range scan {
193-
klog.V(3).Infof("trying package=%v groupName=%s", p, groupName(scan[p]))
194-
if groupName(scan[p]) != "" && len(scan[p].Types) > 0 {
193+
pkg := scan[p]
194+
klog.V(3).Infof("trying package=%v groupName=%s", p, groupName(pkg))
195+
196+
// Do not pick up packages that are in vendor/ as API packages. (This
197+
// happened in knative/eventing-sources/vendor/..., where a package
198+
// matched the pattern, but it didn't have a compatible import path).
199+
if isVendorPackage(pkg) {
200+
klog.V(3).Infof("package=%v coming from vendor/, ignoring.", p)
201+
continue
202+
}
203+
204+
if groupName(pkg) != "" && len(pkg.Types) > 0 {
195205
klog.V(3).Infof("package=%v has groupName and has types", p)
196206
pkgNames = append(pkgNames, p)
197207
}
@@ -205,6 +215,12 @@ func parseAPIPackages(dir string) ([]*types.Package, error) {
205215
return pkgs, nil
206216
}
207217

218+
// isVendorPackage determines if package is coming from vendor/ dir.
219+
func isVendorPackage(pkg *types.Package) bool {
220+
vendorPattern := string(os.PathSeparator) + "vendor" + string(os.PathSeparator)
221+
return strings.Contains(pkg.SourcePath, vendorPattern)
222+
}
223+
208224
func findTypeReferences(pkgs []*types.Package) map[*types.Type][]*types.Type {
209225
m := make(map[*types.Type][]*types.Type)
210226
for _, pkg := range pkgs {

0 commit comments

Comments
 (0)