Skip to content

Commit

Permalink
Warn when excluding non-existing packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Feb 20, 2019
1 parent d347908 commit 45ce445
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
//! previously compiled dependency
//!

use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::iter::FromIterator;
use std::path::PathBuf;
use std::sync::Arc;

Expand Down Expand Up @@ -116,12 +117,23 @@ impl Packages {
.map(Package::package_id)
.map(PackageIdSpec::from_package_id)
.collect(),
Packages::OptOut(opt_out) => ws
.members()
.filter(|pkg| !opt_out.iter().any(|name| pkg.name().as_str() == name))
.map(Package::package_id)
.map(PackageIdSpec::from_package_id)
.collect(),
Packages::OptOut(opt_out) => {
let mut opt_out = BTreeSet::from_iter(opt_out.iter().cloned());
let packages = ws
.members()
.filter(|pkg| !opt_out.remove(pkg.name().as_str()))
.map(Package::package_id)
.map(PackageIdSpec::from_package_id)
.collect();
if !opt_out.is_empty() {
ws.config().shell().warn(format!(
"excluded package(s) {} not found in workspace `{}`",
opt_out.iter().map(|x| x.as_ref()).collect::<Vec<_>>().join(", "),
ws.root().display(),
))?;
}
packages
},
Packages::Packages(packages) if packages.is_empty() => {
vec![PackageIdSpec::from_package_id(ws.current()?.package_id())]
}
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ fn check_virtual_all_implied() {
.run();
}

#[test]
fn exclude_warns_on_non_existing_package() {
let p = project().file("src/lib.rs", "").build();
p.cargo("check --all --exclude bar")
.with_stdout("")
.with_stderr(
r#"[WARNING] excluded package(s) bar not found in workspace `[CWD]`
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
"#,
)
.run();
}

#[test]
fn targets_selected_default() {
let foo = project()
Expand Down

0 comments on commit 45ce445

Please sign in to comment.