Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: emit dependency relationships found in Cargo.lock #3443

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions syft/pkg/cataloger/rust/parse_cargo_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,42 @@ func parseCargoLock(_ context.Context, _ file.Resolver, _ *generic.Environment,
}

var pkgs []pkg.Package
pkgIndex := make(map[string]int)

for _, p := range m.Packages {
if p.Dependencies == nil {
p.Dependencies = make([]string, 0)
}
newPkg := newPackageFromCargoMetadata(
p,
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
)
pkgs = append(
pkgs,
newPackageFromCargoMetadata(
p,
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
),
newPkg,
)
newIx := len(pkgs) - 1
keys := []string{
willmurphyscode marked this conversation as resolved.
Show resolved Hide resolved
newPkg.Name,
fmt.Sprintf("%s %s", newPkg.Name, newPkg.Version),
fmt.Sprintf("%s %s", newPkg.Name, newPkg.Metadata.(pkg.RustCargoLockEntry).Source),
fmt.Sprintf("%s %s %s", newPkg.Name, newPkg.Version, newPkg.Metadata.(pkg.RustCargoLockEntry).Source),
}
for _, k := range keys {
pkgIndex[k] = newIx
}
}
var relationships []artifact.Relationship
for _, p := range pkgs {
meta := p.Metadata.(pkg.RustCargoLockEntry)
for _, d := range meta.Dependencies {
relationships = append(relationships, artifact.Relationship{
From: p,
To: pkgs[pkgIndex[d]],
willmurphyscode marked this conversation as resolved.
Show resolved Hide resolved
Type: artifact.DependencyOfRelationship,
})
}
}

return pkgs, nil, unknown.IfEmptyf(pkgs, "unable to determine packages")
return pkgs, relationships, unknown.IfEmptyf(pkgs, "unable to determine packages")
}
Loading
Loading