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

Support Cargo Non-Flat Dependency Graph Using cargo tree #1377

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

zahidblackduck
Copy link
Collaborator

@zahidblackduck zahidblackduck commented Mar 3, 2025

Ticket

IDETECT-4634

Description

This MR introduces a build-based Cargo detector that utilizes the cargo tree command to extract direct and transitive dependency relationships, addressing the previous limitation where Cargo dependencies were detected as a flat list.

The new implementation ensures backward compatibility by falling back to the existing build-less detector if cargo tree is unavailable. Additionally, it introduces support for the detect.cargo.path property, allowing users to specify a custom Cargo build tool path.

Key Changes:

  • New CargoCliDetectable Class:
    • Uses cargo tree to extract hierarchical dependency relationships.
  • Dependency Graph Transformation:
    • Implements CargoDependencyGraphTransformer to parse cargo tree output into a DependencyGraph.
  • Backward Compatibility:
    • Ensures build-less detection continues to work.
    • Falls back to the existing detector if cargo tree is unavailable.
  • New Property:
    • Adds detect.cargo.path to specify the Cargo build tool path.

Acceptance Criteria Met:

  • Build-based Cargo detection using cargo tree.
  • Backward compatibility with the existing build-less detector.
  • Uses Cargo.toml as the required file.
  • Fallback to build-less detection when necessary.
  • Support for detect.cargo.path to configure the Cargo executable path.

@zahidblackduck zahidblackduck marked this pull request as draft March 3, 2025 10:06
@zahidblackduck zahidblackduck requested a review from dterrybd March 3, 2025 10:07
@zahidblackduck zahidblackduck self-assigned this Mar 3, 2025
@dterrybd
Copy link
Contributor

dterrybd commented Mar 6, 2025

@zahidblackduck I think the code is looking great. The only thing I can currently think of is perhaps for the CLI Detectable class. When we are deciding if things are extractable and are looking for the cargo executable it might make sense to also confirm that the version of cargo we have is capable of running the tree command. Also, once you finish manual testing it would be great to add some junits.

@zahidblackduck zahidblackduck changed the title IDETECT-4634 Support Cargo non flat dependency graph using tree (Do not merge) Support Cargo Non-Flat Dependency Graph Using cargo tree Mar 10, 2025
@zahidblackduck zahidblackduck changed the title Support Cargo Non-Flat Dependency Graph Using cargo tree Support Cargo Non-Flat Dependency Graph Using cargo tree Mar 10, 2025
@zahidblackduck zahidblackduck changed the title Support Cargo Non-Flat Dependency Graph Using cargo tree Support Cargo Non-Flat Dependency Graph Using cargo tree Mar 10, 2025
@dterrybd dterrybd self-requested a review March 10, 2025 15:06
@@ -23,6 +23,9 @@
### New features

* Support for Conda has been extended to 25.1.1.
Here’s the revised line, following your requested format:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a comment that came over from a cut and paste?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I'll refactor. Thanks for pointing this out.

@dmamidibd dmamidibd requested a review from devmehtabd March 11, 2025 14:07
@@ -23,6 +23,8 @@
### New features

* Support for Conda has been extended to 25.1.1.
* A new detector leveraging `cargo tree` to extract direct and transitive dependencies, improving accuracy over the previous flat-list detection. This build-based detector is triggered for Cargo projects with a `Cargo.toml` file and requires Cargo version **1.44.0+**. Falls back to the existing build-less approach if `cargo tree` is unavailable.
Copy link
Contributor

@cpottsbd cpottsbd Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for a few tweaks to add links to further documentation:

* Cargo CLI Detector, leveraging `cargo tree` to extract direct and transitive dependencies, improving accuracy over the previous flat-list detection. This build-based detector is triggered for Cargo projects with a `Cargo.toml` file and requires Cargo version **1.44.0+**. For further information, see [Cargo package manager support](packagemgrs/cargo.md).
* Added property [detect.cargo.path](properties/detectors/cargo.md) to allow user specification of a custom Cargo executable path.  

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay @cpottsbd, I'll update accordingly. Thanks for the nice suggestion.


[detect_product_short] runs the Cargo detector if it finds either of the following files in your project:
[detect_product_short] now includes two Cargo detectors:
Copy link
Contributor

@cpottsbd cpottsbd Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the "now's" and "new's" from this information and leave that type of info for the release notes. (Since this part of the documentation lives on past the point where this detector is new.)
i.e.
[detect_product_short] includes two Cargo detectors:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems quite logical.


* Cargo.toml
* Cargo.lock
* **Cargo CLI Detector** (New)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* **Cargo CLI Detector**

The Cargo detector extracts the project's name and version from the Cargo.toml file. If it does not find a Cargo.toml file, it will defer to values derived by Git, from the project's directory, or defaults.
## Cargo CLI Detector

A new cli detector for Cargo projects, which extracts **direct and transitive dependencies** using the `cargo tree` command. This improves the accuracy of dependency detection over the previous flat-list detection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
Detector for Cargo projects, extracts **direct and transitive dependencies** using the cargo treecommand.

A new cli detector for Cargo projects, which extracts **direct and transitive dependencies** using the `cargo tree` command. This improves the accuracy of dependency detection over the previous flat-list detection.

**Requirements:**
* Cargo version **1.44.0+** is required (as `cargo tree` was introduced in this version).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  • Cargo version 1.44.0+ is required (as cargo tree was introduced in this version).
    to
  • Cargo version 1.44.0+ required to support cargo tree.

Copy link
Contributor

@cpottsbd cpottsbd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes. Thanks.

@zahidblackduck zahidblackduck requested a review from cpottsbd March 11, 2025 17:53
The Cargo detector extracts the project's name and version from the Cargo.toml file. If it does not find a Cargo.toml file, it will defer to values derived by Git, from the project's directory, or defaults.
## Cargo CLI Detector

Detector for Cargo projects, extracts **direct and transitive dependencies** using the `cargo tree` command.
Copy link
Contributor

@cpottsbd cpottsbd Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one new thought. ; ) perhaps link to the man page for the cargo tree command here.
i.e.
* Detector for Cargo projects, extracts **direct and transitive dependencies** using the [cargo tree command](https://doc.rust-lang.org/cargo/commands/cargo-tree.html).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've updated with the cargo tree documentation link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants