Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix exit code check and virtual manifest parsing (RustCli) #937

Merged
merged 2 commits into from
Dec 19, 2023
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 @@ -46,7 +46,7 @@
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" };
Expand All @@ -55,6 +55,7 @@
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
{
Expand All @@ -75,7 +76,7 @@
"--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;
Expand All @@ -85,6 +86,15 @@
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;

Check warning on line 95 in src/Microsoft.ComponentDetection.Detectors/rust/RustCliDetector.cs

View check run for this annotation

Codecov / codecov/patch

src/Microsoft.ComponentDetection.Detectors/rust/RustCliDetector.cs#L93-L95

Added lines #L93 - L95 were not covered by tests
}

this.TraverseAndRecordComponents(processRequest.SingleFileComponentRecorder, componentStream.Location, graph, root, null, null);
}
catch (InvalidOperationException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void CheckDetectorsRunTimesAndCounts()
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);

Expand Down Expand Up @@ -217,7 +217,7 @@ public void CheckDetectorsRunTimesAndCounts()
{
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}");

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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":{}}
Original file line number Diff line number Diff line change
@@ -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/