Skip to content

Commit 45ce445

Browse files
committed
Warn when excluding non-existing packages
1 parent d347908 commit 45ce445

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
//! previously compiled dependency
2323
//!
2424
25-
use std::collections::{HashMap, HashSet};
25+
use std::collections::{BTreeSet, HashMap, HashSet};
26+
use std::iter::FromIterator;
2627
use std::path::PathBuf;
2728
use std::sync::Arc;
2829

@@ -116,12 +117,23 @@ impl Packages {
116117
.map(Package::package_id)
117118
.map(PackageIdSpec::from_package_id)
118119
.collect(),
119-
Packages::OptOut(opt_out) => ws
120-
.members()
121-
.filter(|pkg| !opt_out.iter().any(|name| pkg.name().as_str() == name))
122-
.map(Package::package_id)
123-
.map(PackageIdSpec::from_package_id)
124-
.collect(),
120+
Packages::OptOut(opt_out) => {
121+
let mut opt_out = BTreeSet::from_iter(opt_out.iter().cloned());
122+
let packages = ws
123+
.members()
124+
.filter(|pkg| !opt_out.remove(pkg.name().as_str()))
125+
.map(Package::package_id)
126+
.map(PackageIdSpec::from_package_id)
127+
.collect();
128+
if !opt_out.is_empty() {
129+
ws.config().shell().warn(format!(
130+
"excluded package(s) {} not found in workspace `{}`",
131+
opt_out.iter().map(|x| x.as_ref()).collect::<Vec<_>>().join(", "),
132+
ws.root().display(),
133+
))?;
134+
}
135+
packages
136+
},
125137
Packages::Packages(packages) if packages.is_empty() => {
126138
vec![PackageIdSpec::from_package_id(ws.current()?.package_id())]
127139
}

tests/testsuite/check.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,20 @@ fn check_virtual_all_implied() {
427427
.run();
428428
}
429429

430+
#[test]
431+
fn exclude_warns_on_non_existing_package() {
432+
let p = project().file("src/lib.rs", "").build();
433+
p.cargo("check --all --exclude bar")
434+
.with_stdout("")
435+
.with_stderr(
436+
r#"[WARNING] excluded package(s) bar not found in workspace `[CWD]`
437+
[CHECKING] foo v0.0.1 ([CWD])
438+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
439+
"#,
440+
)
441+
.run();
442+
}
443+
430444
#[test]
431445
fn targets_selected_default() {
432446
let foo = project()

0 commit comments

Comments
 (0)