Skip to content

Commit

Permalink
Add hashtable to resolve circular rust dependencies (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoRojo authored Jan 17, 2024
1 parent d38bde5 commit b65fa8a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class RustCliDetector : FileComponentDetector, IExperimentalDetector
{
private readonly ICommandLineInvocationService cliService;

private readonly HashSet<string> visitedDependencies = new();

This comment has been minimized.

Copy link
@melotic

melotic Jan 18, 2024

Member

This is global to the Detector, which is instantianted as a singleton. If we're scanning multiple Cargo.tomls, this might ignore crates previously scanned that may have different features enabled (and thus different transitive dependencies)

This comment has been minimized.

Copy link
@FernandoRojo

FernandoRojo Jan 18, 2024

Author Contributor

Good catch, the specific cargo.toml of the dependency is part of the hash key but this wouldn't account for different build environments/features causing different transitive dependencies, updating to create/pass the hashTable for each root cargo.toml


/// <summary>
/// Initializes a new instance of the <see cref="RustCliDetector"/> class.
/// </summary>
Expand Down Expand Up @@ -153,7 +155,12 @@ private void TraverseAndRecordComponents(

foreach (var dep in node.Deps)
{
this.TraverseAndRecordComponents(recorder, location, graph, dep.Pkg, detectedComponent, dep, packagesMetadata, parent == null);
var componentKey = $"{detectedComponent.Component.Id}{dep.Pkg}";
if (!this.visitedDependencies.Contains(componentKey))
{
this.visitedDependencies.Add(componentKey);
this.TraverseAndRecordComponents(recorder, location, graph, dep.Pkg, detectedComponent, dep, packagesMetadata, parent == null);
}
}
}
catch (IndexOutOfRangeException e)
Expand Down

0 comments on commit b65fa8a

Please sign in to comment.