Fix exit code check and virtual manifest parsing (RustCli) (#937)
* Fix exit code check and virtual manifest break * Update test
This commit is contained in:
Родитель
ae7438f86c
Коммит
d4ca976992
|
@ -46,7 +46,7 @@ public class RustCliDetector : FileComponentDetector, IExperimentalDetector
|
|||
public override IEnumerable<ComponentType> SupportedComponentTypes => new[] { ComponentType.Cargo };
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Version => 1;
|
||||
public override int Version => 2;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IList<string> SearchPatterns { get; } = new[] { "Cargo.toml" };
|
||||
|
@ -55,6 +55,7 @@ public class RustCliDetector : FileComponentDetector, IExperimentalDetector
|
|||
protected override async Task OnFileFoundAsync(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
|
||||
{
|
||||
var componentStream = processRequest.ComponentStream;
|
||||
this.Logger.LogInformation("Discovered Cargo.toml: {Location}", componentStream.Location);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -75,7 +76,7 @@ public class RustCliDetector : FileComponentDetector, IExperimentalDetector
|
|||
"--format-version=1",
|
||||
"--locked");
|
||||
|
||||
if (cliResult.ExitCode < 0)
|
||||
if (cliResult.ExitCode != 0)
|
||||
{
|
||||
this.Logger.LogWarning("`cargo metadata` failed with {Location}. Ensure the Cargo.lock is up to date. stderr: {StdErr}", processRequest.ComponentStream.Location, cliResult.StdErr);
|
||||
return;
|
||||
|
@ -85,6 +86,15 @@ public class RustCliDetector : FileComponentDetector, IExperimentalDetector
|
|||
var graph = BuildGraph(metadata);
|
||||
var root = metadata.Resolve.Root;
|
||||
|
||||
// A cargo.toml can be used to declare a workspace and not a package (A Virtual Manifest).
|
||||
// In this case, the root will be null as it will not be pulling in dependencies itself.
|
||||
// https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace
|
||||
if (root == null)
|
||||
{
|
||||
this.Logger.LogWarning("Virtual Manifest: {Location}, skipping component mapping", processRequest.ComponentStream.Location);
|
||||
return;
|
||||
}
|
||||
|
||||
this.TraverseAndRecordComponents(processRequest.SingleFileComponentRecorder, componentStream.Location, graph, root, null, null);
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
|
|
|
@ -178,7 +178,7 @@ public class ComponentDetectionIntegrationTests
|
|||
using (new AssertionScope())
|
||||
{
|
||||
this.ProcessDetectorVersions();
|
||||
var regexPattern = @"Detection time: (\w+\.\w+) seconds.\w?|(\w+ *[\w()]+) *\|(\w+\.*\w*) seconds *\|(\d+)";
|
||||
var regexPattern = @"Detection time: (\w+\.\w+) seconds.\w?|(\w+) +[\w()]* *\|(\w+\.*\w*) seconds *\|(\d+)";
|
||||
var oldMatches = Regex.Matches(this.oldLogFileContents, regexPattern);
|
||||
var newMatches = Regex.Matches(this.newLogFileContents, regexPattern);
|
||||
|
||||
|
@ -217,7 +217,7 @@ public class ComponentDetectionIntegrationTests
|
|||
{
|
||||
var detectorId = match.Groups[2].Value;
|
||||
var newCount = int.Parse(match.Groups[4].Value);
|
||||
if (detectorCounts.TryGetValue(detectorId, out var oldCount))
|
||||
if (detectorCounts.TryGetValue(detectorId, out var oldCount) && detectorId != "Total")
|
||||
{
|
||||
newCount.Should().BeGreaterOrEqualTo(oldCount, $"{oldCount - newCount} Components were lost for detector {detectorId}. Verify this is expected behavior. \n Old Count: {oldCount}, PPE Count: {newCount}");
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "component-detection"
|
||||
name = "component-detection-rust-standard"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
[package]
|
||||
name = "component-detection"
|
||||
name = "component-detection-rust-standard"
|
||||
version = "0.1.0"
|
||||
authors = []
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "main.rs"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"rustc_fingerprint":6367476752289451207,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\ferojo\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-pc-windows-msvc\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""}},"successes":{}}
|
|
@ -0,0 +1,3 @@
|
|||
Signature: 8a477f597d28d172789f06886806bc55
|
||||
# This file is a cache directory tag created by cargo.
|
||||
# For information about cache directory tags see https://bford.info/cachedir/
|
Загрузка…
Ссылка в новой задаче