github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/homebrew/package.go (about) 1 package homebrew 2 3 import ( 4 "context" 5 "path" 6 7 "github.com/anchore/packageurl-go" 8 "github.com/anchore/syft/syft/file" 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/pkg/cataloger/internal/licenses" 11 ) 12 13 func newHomebrewPackage(ctx context.Context, resolver file.Resolver, pd parsedHomebrewData, formulaLocation file.Location) pkg.Package { 14 var lics []pkg.License 15 if pd.License != "" { 16 lics = append(lics, pkg.NewLicensesFromValues(pd.License)...) 17 } else { 18 // sometimes licenses are included in the parent directory 19 lics = licenses.FindInDirs(ctx, resolver, path.Dir(formulaLocation.Path())) 20 } 21 22 p := pkg.Package{ 23 Name: pd.Name, 24 Version: pd.Version, 25 Type: pkg.HomebrewPkg, 26 Locations: file.NewLocationSet(formulaLocation.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)), 27 Licenses: pkg.NewLicenseSet(lics...), 28 FoundBy: "homebrew-cataloger", 29 PURL: packageURL(pd.Name, pd.Version), 30 Metadata: pkg.HomebrewFormula{ 31 Tap: pd.Tap, 32 Homepage: pd.Homepage, 33 Description: pd.Desc, 34 }, 35 } 36 37 p.SetID() 38 return p 39 } 40 41 func packageURL(name, version string) string { 42 purl := packageurl.NewPackageURL( 43 "brew", 44 "", 45 name, 46 version, 47 nil, 48 "", 49 ) 50 return purl.ToString() 51 }