facebookarchive/cargo-guppy

Improve PackageLink::dev_only documentation to indicate that it's local context only

Opened this issue · 1 comments

Shouldn't an edge to any dependency to a dev dependency of a project be a dev_only edge? However, this API, guppy::graph::PackageLink::dev_only, returns false for such an edge. In this way, I am not sure how this API is different from guppy::graph::PackageLink::dev()::is_present().

For example, for a test crate that has guppy as a dev dependency and no other dependency specified in the crate to make sure guppy doesn't appear elsewhere in the dep-graph, below code

// The crate has a single dependency, `guppy` as a dev-dependency
let pkg = graph.packages().find(|p| p.name() == "guppy").unwrap();
for link in pkg.direct_links_directed(DependencyDirection::Forward){
    println!("{:?}, {:?}, {:?}, {:?}",
    link.to().name(), link.normal().is_present(),
    link.dev().is_present(), link.dev_only());
}

outputs:

running 1 test
"target-spec", true, false, false
"supercow", true, false, false
"serde_json", true, false, false
"serde", true, false, false
"semver", true, false, false
"petgraph", true, false, false
"pathdiff", true, false, false
"once_cell", true, false, false
"nested", true, false, false
"itertools", true, false, false
"indexmap", true, false, false
"fixedbitset", true, false, false
"cargo_metadata", true, false, false
"camino", true, false, false

However, guppy::graph::PackageLink::dev_only in its description says:

Return true if this edge is dev-only, i.e. code from this edge will not be included in normal builds.

Below is how my test crate looked like:

[dependencies]


[build-dependencies]

[dev-dependencies]
guppy = "0.9.0"

Ahh I see what's going on there. PackageLinks only have local context: if guppy is built as a normal dependency, then these would be included as normal dependencies as well.

For the sort of global context you're looking for I think you can use the Cargo build simulation feature: https://docs.rs/guppy/0.9.0/guppy/graph/feature/struct.FeatureSet.html#method.into_cargo_set

The documentation could be improved here; I'll leave this issue open for that.