Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RustCrateDetector : FileComponentDetector

public override IEnumerable<ComponentType> SupportedComponentTypes => new[] { ComponentType.Cargo };

public override int Version { get; } = 5;
public override int Version { get; } = 6;

public override IEnumerable<string> Categories => new List<string> { "Rust" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,20 @@ public static DependencySpecification GenerateDependencySpecifications(TomlTable
return null;
}

dependencySpecifications.Add(dependency, versionSpecifier);
// If the dependency is renamed, use the actual name of the package:
// https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
string dependencyName;
if (dependencies[dependency].TomlType == TomlObjectType.Table &&
dependencies.Get<TomlTable>(dependency).ContainsKey("package"))
{
dependencyName = dependencies.Get<TomlTable>(dependency).Get<string>("package");
}
else
{
dependencyName = dependency;
}

dependencySpecifications.Add(dependencyName, versionSpecifier);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RustCrateV2Detector : FileComponentDetector

public override IEnumerable<ComponentType> SupportedComponentTypes => new[] { ComponentType.Cargo };

public override int Version { get; } = 4;
public override int Version { get; } = 5;

public override IEnumerable<string> Categories => new List<string> { "Rust" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,45 @@ public async Task TestRustDetector_UnequalButSemverCompatibleRoot()
graph.GetDependenciesForComponent("c-ares 7.5.2 - Cargo").Should().BeEquivalentTo(cAresDependencies);
}

[TestMethod]
public async Task TestRustDetector_RenamedDependency()
{
var testTomlString = @"
[package]
name = ""my_test_package""
version = ""1.2.3""
authors = [""example@example.com>""]

[dependencies]
foo_dependency = { package = ""my_dependency"", version = ""1.0.0""}
";
var testLockString = @"
[[package]]
name = ""my_dependency""
version = ""1.0.0""
source = ""registry+https://github.com/rust-lang/crates.io-index""
";
var (result, componentRecorder) = await detectorV2TestUtility
.WithFile("Cargo.lock", testLockString)
.WithFile("Cargo.toml", testTomlString, new List<string> { "Cargo.toml" })
.ExecuteDetector();

result.ResultCode.Should().Be(ProcessingResultCode.Success);

var dependencyGraphs = componentRecorder.GetDependencyGraphsByLocation();
dependencyGraphs.Count.Should().Be(1);

var dependencyGraph = dependencyGraphs.Single().Value;
var foundComponents = dependencyGraph.GetComponents();
foundComponents.Count().Should().Be(1);

var rootComponents = new List<string>
{
"my_dependency 1.0.0 - Cargo",
};
rootComponents.ForEach(rootComponentId => dependencyGraph.IsComponentExplicitlyReferenced(rootComponentId).Should().BeTrue());
}

/// <summary>
/// (my_dependency, 1.0, root)
/// (my_other_dependency, 0.1.0, root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ path = "main.rs"
name = "component-detection"

[dependencies]
serde = "1.0.136"
renamed_dependency = { package = "serde", version = "1.0.136"}

[dev-dependencies]
rand = "0.8.4"

[build-dependencies]
autocfg = "1.0.1"
autocfg = "1.0.1"