github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/arch/dependency.go (about)

     1  package arch
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/anchore/syft/internal/log"
     7  	"github.com/anchore/syft/syft/pkg"
     8  	"github.com/anchore/syft/syft/pkg/cataloger/internal/dependency"
     9  )
    10  
    11  var _ dependency.Specifier = dbEntryDependencySpecifier
    12  
    13  func dbEntryDependencySpecifier(p pkg.Package) dependency.Specification {
    14  	meta, ok := p.Metadata.(pkg.AlpmDBEntry)
    15  	if !ok {
    16  		log.Tracef("cataloger failed to extract alpm metadata for package %+v", p.Name)
    17  		return dependency.Specification{}
    18  	}
    19  
    20  	provides := []string{p.Name}
    21  	for _, key := range meta.Provides {
    22  		if key == "" {
    23  			continue
    24  		}
    25  		provides = append(provides, key, stripVersionSpecifier(key))
    26  	}
    27  
    28  	var requires []string
    29  	for _, depSpecifier := range meta.Depends {
    30  		if depSpecifier == "" {
    31  			continue
    32  		}
    33  		requires = append(requires, depSpecifier)
    34  	}
    35  
    36  	return dependency.Specification{
    37  		ProvidesRequires: dependency.ProvidesRequires{
    38  			Provides: provides,
    39  			Requires: requires,
    40  		},
    41  	}
    42  }
    43  
    44  func stripVersionSpecifier(s string) string {
    45  	// examples:
    46  	// gcc-libs                  -->  gcc-libs
    47  	// libtree-sitter.so=0-64    -->  libtree-sitter.so
    48  
    49  	return strings.TrimSpace(strings.Split(s, "=")[0])
    50  }