Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 22 additions & 7 deletions src/cargo/ops/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,46 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
.collect();

for SpecsAndResolvedFeatures {
specs,
specs: entry_specs,
resolved_features,
} in ws_resolve.specs_and_features
{
let mut graph = graph::build(
ws,
&ws_resolve.targeted_resolve,
&resolved_features,
&specs,
&entry_specs,
&opts.cli_features,
&target_data,
&requested_kinds,
package_map.clone(),
opts,
)?;

let root_specs = if opts.invert.is_empty() {
specs
let root_ids = if opts.invert.is_empty() {
let entry_ids = ws_resolve.targeted_resolve.specs_to_ids(&entry_specs)?;
let requested_ids = ws_resolve
.targeted_resolve
.specs_to_ids(&specs)?
.into_iter()
.collect::<HashSet<_>>();

// `entry_specs` can be broader than the CLI request (for example,
// all workspace members when `feature-unification=workspace`).
// Keep only the packages explicitly requested by `-p`.
entry_ids
.into_iter()
.filter(|id| requested_ids.contains(id))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something I need to dig into is why this filtering happens rather than just returning requested_ids

.collect()
} else {
opts.invert
let invert_specs = opts
.invert
.iter()
.map(|p| PackageIdSpec::parse(p))
.collect::<Result<Vec<PackageIdSpec>, _>>()?
.collect::<Result<Vec<PackageIdSpec>, _>>()?;

ws_resolve.targeted_resolve.specs_to_ids(&invert_specs)?
};
let root_ids = ws_resolve.targeted_resolve.specs_to_ids(&root_specs)?;
let root_indexes = graph.indexes_from_ids(&root_ids);

let root_indexes = if opts.duplicates {
Expand Down
12 changes: 12 additions & 0 deletions tests/testsuite/feature_unification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ b v0.1.0 ([ROOT]/foo/b)
└── outside feature "default"
└── outside v0.1.0

"#]])
.run();

p.cargo("tree -p a")
Comment thread
terror marked this conversation as resolved.
.arg("-Zfeature-unification")
.masquerade_as_nightly_cargo(&["feature-unification"])
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "workspace")
.with_stdout_data(str![[r#"
a v0.1.0 ([ROOT]/foo/a)
├── common v0.1.0 ([ROOT]/foo/common)
└── outside v0.1.0

"#]])
.run();
}
Expand Down
Loading