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

Add warning when cargo tree -i <spec> can not find packages #11377

Merged
merged 2 commits into from
Nov 20, 2022
Merged
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
10 changes: 9 additions & 1 deletion src/cargo/ops/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,15 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
})
.collect::<CargoResult<Vec<PackageIdSpec>>>()?;

print(ws.config(), opts, root_indexes, &pkgs_to_prune, &graph)?;
if root_indexes.len() == 0 {
ws.config().shell().warn(
"nothing to print.\n\n\
To find dependencies that require specific target platforms, \
try use option `--target all` first, and then narrow your search scope accordingly.",
Copy link
Member

Choose a reason for hiding this comment

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

I think the grammar is wrong here, should be "try to use" or "try using"

Copy link
Member Author

Choose a reason for hiding this comment

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

aha, I'll fix it later. Thanks!

)?;
} else {
print(ws.config(), opts, root_indexes, &pkgs_to_prune, &graph)?;
}
Ok(())
}

Expand Down
56 changes: 56 additions & 0 deletions tests/testsuite/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,62 @@ foo v0.1.0 ([..]/foo)
.run();
}

#[cargo_test]
fn no_selected_target_dependency() {
// --target flag
if cross_compile::disabled() {
return;
}
Package::new("targetdep", "1.0.0").publish();

let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"

[target.'{alt}'.dependencies]
targetdep = "1.0"

"#,
alt = alternate(),
),
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.build();

p.cargo("tree")
.with_stdout(
"\
foo v0.1.0 ([..]/foo)
",
)
.run();

p.cargo("tree -i targetdep")
.with_stderr(
"\
[WARNING] nothing to print.

To find dependencies that require specific target platforms, \
try use option `--target all` first, and then narrow your search scope accordingly.
",
)
.run();
p.cargo("tree -i targetdep --target all")
.with_stdout(
"\
targetdep v1.0.0
└── foo v0.1.0 ([..]/foo)
",
)
.run();
}

#[cargo_test]
fn dep_kinds() {
Package::new("inner-devdep", "1.0.0").publish();
Expand Down