github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/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  		Provides: provides,
    38  		Requires: requires,
    39  	}
    40  }
    41  
    42  func stripVersionSpecifier(s string) string {
    43  	// examples:
    44  	// gcc-libs                  -->  gcc-libs
    45  	// libtree-sitter.so=0-64    -->  libtree-sitter.so
    46  
    47  	return strings.TrimSpace(strings.Split(s, "=")[0])
    48  }