use guppy::{
graph::{DependencyDirection, PackageLink},
CargoMetadata, Error,
};
use std::iter;
fn main() -> Result<(), Error> {
let metadata =
CargoMetadata::parse_json(include_str!("../../fixtures/large/metadata_libra.json"))?;
let package_graph = metadata.build_graph()?;
let libra_node_id = package_graph
.workspace()
.member_by_path("libra-node")
.unwrap()
.id()
.clone();
let before_count = package_graph
.query_forward(iter::once(&libra_node_id))?
.resolve()
.package_ids(DependencyDirection::Forward)
.count();
println!("number of packages before: {}", before_count);
let resolver_fn = |link: PackageLink<'_>| {
if link.dev_only() {
println!(
"*** filtering out dev-only link: {} -> {}",
link.from().name(),
link.to().name()
);
return false;
}
true
};
let query = package_graph.query_forward(iter::once(&libra_node_id))?;
let resolve_with_len = query
.clone()
.resolve_with_fn(|_query, link| {
resolver_fn(link)
})
.package_ids(DependencyDirection::Forward)
.len();
println!("number of packages after: {}", resolve_with_len);
Ok(())
}