Skip to content

Commit 648ffc8

Browse files
Fix for package classification
This fixes some edge cases in the package classification logic for Go 1.18 binaries. If the path was empty, the 3rd party libraries were classified as main module packages.
1 parent b697eef commit 648ffc8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

package.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,24 @@ func (c *ModPackageClassifier) Classify(pkg *Package) PackageClass {
264264
return ClassMain
265265
}
266266

267-
if strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Main.Path) {
267+
// If the build info path is not an empty string and the package has the path as a substring, it is part of the main module.
268+
if c.modInfo.Path != "" && (strings.HasPrefix(pkg.Filepath, c.modInfo.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Path)) {
269+
return ClassMain
270+
}
271+
272+
// If the main module path is not an empty string and the package has the path as a substring, it is part of the main module.
273+
if c.modInfo.Main.Path != "" && (strings.HasPrefix(pkg.Filepath, c.modInfo.Main.Path) || strings.HasPrefix(pkg.Name, c.modInfo.Main.Path)) {
268274
return ClassMain
269275
}
270276

271277
// Check if the package is a direct dependency.
272278
for _, dep := range c.modInfo.Deps {
273279
if strings.HasPrefix(pkg.Filepath, dep.Path) || strings.HasPrefix(pkg.Name, dep.Path) {
280+
// If the vendor it matched on has the version of "(devel)", it is treated as part of
281+
// the main module.
282+
if dep.Version == "(devel)" {
283+
return ClassMain
284+
}
274285
return ClassVendor
275286
}
276287
}

0 commit comments

Comments
 (0)