Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Fixes #18 Add option to show whole feature space of dependency tree #59

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 30 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cargo::core::summary::FeatureMap;
use cargo::core::dependency::Kind;
use cargo::core::manifest::ManifestMetadata;
use cargo::core::package::PackageSet;
Expand Down Expand Up @@ -111,6 +112,9 @@ struct Args {
#[structopt(short = "Z", value_name = "FLAG")]
/// Unstable (nightly-only) flags to Cargo
unstable_flags: Vec<String>,
#[structopt(long = "show-feature-space")]
/// Display feature space for the dependency tree
show_feature_space: bool
}

enum Charset {
Expand Down Expand Up @@ -248,11 +252,11 @@ fn real_main(args: Args, config: &mut Config) -> CliResult {
if args.duplicates {
let dups = find_duplicates(&graph);
for dup in &dups {
print_tree(dup, &graph, &format, direction, symbols, prefix, args.all)?;
print_tree(dup, &graph, &format, direction, symbols, prefix, args.all, args.show_feature_space)?;
println!();
}
} else {
print_tree(&root, &graph, &format, direction, symbols, prefix, args.all)?;
print_tree(&root, &graph, &format, direction, symbols, prefix, args.all, args.show_feature_space)?;
}

Ok(())
Expand Down Expand Up @@ -343,6 +347,8 @@ fn resolve<'a, 'cfg>(
struct Node<'a> {
id: PackageId,
metadata: &'a ManifestMetadata,
enabled_features: &'a HashSet<String>,
feature_space: &'a FeatureMap
}

struct Graph<'a> {
Expand All @@ -364,6 +370,8 @@ fn build_graph<'a>(
let node = Node {
id: root.clone(),
metadata: packages.get_one(root)?.manifest().metadata(),
enabled_features: resolve.features(root),
feature_space: packages.get_one(root)?.summary().features(),
};
graph.nodes.insert(root.clone(), graph.graph.add_node(node));

Expand Down Expand Up @@ -395,6 +403,8 @@ fn build_graph<'a>(
let node = Node {
id: dep_id,
metadata: packages.get_one(dep_id)?.manifest().metadata(),
enabled_features: resolve.features(dep_id),
feature_space: packages.get_one(dep_id)?.summary().features(),
};
*e.insert(graph.graph.add_node(node))
}
Expand All @@ -415,6 +425,7 @@ fn print_tree<'a>(
symbols: &Symbols,
prefix: Prefix,
all: bool,
show_feature_space: bool,
) -> CargoResult<()> {
let mut visited_deps = HashSet::new();
let mut levels_continue = vec![];
Expand All @@ -434,6 +445,7 @@ fn print_tree<'a>(
&mut levels_continue,
prefix,
all,
show_feature_space,
);
Ok(())
}
Expand All @@ -448,6 +460,7 @@ fn print_dependency<'a>(
levels_continue: &mut Vec<bool>,
prefix: Prefix,
all: bool,
show_feature_space: bool,
) {
let new = all || visited_deps.insert(package.id);
let star = if new { "" } else { " (*)" };
Expand All @@ -472,7 +485,16 @@ fn print_dependency<'a>(
Prefix::None => (),
}

println!("{}{}", format.display(&package.id, package.metadata), star);
if show_feature_space {
print!("{}{} Enabled Features: {:?}", format.display(&package.id, package.metadata), star, package.enabled_features);
print!(" Feature Space: [");
for (key, _) in package.feature_space {
print!("{:?}, ", key);
}
println!("]")
} else {
println!("{}{}", format.display(&package.id, package.metadata), star);
}

if !new {
return;
Expand Down Expand Up @@ -507,6 +529,7 @@ fn print_dependency<'a>(
levels_continue,
prefix,
all,
show_feature_space,
);
print_dependency_kind(
Kind::Build,
Expand All @@ -519,6 +542,7 @@ fn print_dependency<'a>(
levels_continue,
prefix,
all,
show_feature_space,
);
print_dependency_kind(
Kind::Development,
Expand All @@ -531,6 +555,7 @@ fn print_dependency<'a>(
levels_continue,
prefix,
all,
show_feature_space,
);
}

Expand All @@ -545,6 +570,7 @@ fn print_dependency_kind<'a>(
levels_continue: &mut Vec<bool>,
prefix: Prefix,
all: bool,
show_feature_space: bool,
) {
if deps.is_empty() {
return;
Expand Down Expand Up @@ -582,6 +608,7 @@ fn print_dependency_kind<'a>(
levels_continue,
prefix,
all,
show_feature_space,
);
levels_continue.pop();
}
Expand Down