Skip to content

Commit

Permalink
Fix exit code check and virtual manifest break
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoRojo committed Dec 15, 2023
1 parent ae7438f commit 1ed982a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/Microsoft.ComponentDetection.Detectors/rust/RustCliDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RustCliDetector(
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 @@ public RustCliDetector(
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 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
"--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 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
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

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/

0 comments on commit 1ed982a

Please sign in to comment.