Skip to content

Commit

Permalink
Do not emit "specified feature not found" warning when build multiple…
Browse files Browse the repository at this point in the history
… packages
  • Loading branch information
taiki-e committed Jul 30, 2022
1 parent 24dd021 commit 1b9d46b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Fix an issue that a warning was displayed when excluding a feature that exists only in some crates in the workspace. ([#158](https://github.com/taiki-e/cargo-hack/pull/158))

## [0.5.15] - 2022-07-18

- Support namespaced features (features with `dep:` prefix). ([#154](https://github.com/taiki-e/cargo-hack/pull/154))
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Context {
&self.metadata.packages[id]
}

pub(crate) fn workspace_members(&self) -> impl Iterator<Item = &PackageId> {
pub(crate) fn workspace_members(&self) -> impl ExactSizeIterator<Item = &PackageId> {
self.metadata.workspace_members.iter()
}

Expand Down
35 changes: 25 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ enum Kind<'a> {
Powerset { features: Vec<Vec<&'a Feature>> },
}

fn determine_kind<'a>(cx: &'a Context, id: &PackageId, progress: &mut Progress) -> Kind<'a> {
fn determine_kind<'a>(
cx: &'a Context,
id: &PackageId,
progress: &mut Progress,
multiple_packages: bool,
) -> Kind<'a> {
if cx.ignore_private && cx.is_private(id) {
info!("skipped running on private package `{}`", cx.name_verbose(id));
return Kind::SkipAsPrivate;
Expand All @@ -151,18 +156,22 @@ fn determine_kind<'a>(cx: &'a Context, id: &PackageId, progress: &mut Progress)
&& !cx.group_features.iter().any(|g| g.matches(f.name()))
};
let features = if cx.include_features.is_empty() {
cx.exclude_features.iter().for_each(|d| {
if !pkg_features.contains(d) {
warn!("specified feature `{}` not found in package `{}`", d, package.name);
// TODO
if !multiple_packages {
for name in &cx.exclude_features {
if !pkg_features.contains(name) {
warn!("specified feature `{}` not found in package `{}`", name, package.name);
}
}
});
}

let mut features: Vec<_> = pkg_features.normal().iter().filter(filter).collect();

if let Some(opt_deps) = &cx.optional_deps {
if opt_deps.len() == 1 && opt_deps[0].is_empty() {
// --optional-deps=
} else {
} else if !multiple_packages {
// TODO
for d in opt_deps {
if !pkg_features.optional_deps().iter().any(|f| f == d) {
warn!(
Expand Down Expand Up @@ -244,9 +253,10 @@ fn determine_package_list<'a>(
}
}

let multiple_packages = cx.workspace_members().len().saturating_sub(cx.exclude.len()) > 1;
cx.workspace_members()
.filter(|id| !cx.exclude.contains(&cx.packages(id).name))
.map(|id| (id, determine_kind(cx, id, progress)))
.map(|id| (id, determine_kind(cx, id, progress, multiple_packages)))
.collect()
} else if !cx.package.is_empty() {
if let Some(spec) = cx
Expand All @@ -257,17 +267,22 @@ fn determine_package_list<'a>(
bail!("package ID specification `{}` matched no packages", spec)
}

let multiple_packages = cx.package.len() > 1;
cx.workspace_members()
.filter(|id| cx.package.contains(&cx.packages(id).name))
.map(|id| (id, determine_kind(cx, id, progress)))
.map(|id| (id, determine_kind(cx, id, progress, multiple_packages)))
.collect()
} else if cx.current_package().is_none() {
cx.workspace_members().map(|id| (id, determine_kind(cx, id, progress))).collect()
let multiple_packages = cx.workspace_members().len() > 1;
cx.workspace_members()
.map(|id| (id, determine_kind(cx, id, progress, multiple_packages)))
.collect()
} else {
let current_package = &cx.packages(cx.current_package().unwrap()).name;
let multiple_packages = false;
cx.workspace_members()
.find(|id| cx.packages(id).name == *current_package)
.map(|id| vec![(id, determine_kind(cx, id, progress))])
.map(|id| vec![(id, determine_kind(cx, id, progress, multiple_packages))])
.unwrap_or_default()
})
}
Expand Down
7 changes: 7 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,13 @@ fn include_features() {
);
}

#[test]
fn exclude_features() {
cargo_hack(["check", "--each-feature", "--exclude-features", "f"])
.assert_success("virtual")
.stderr_not_contains("specified feature `f` not found");
}

#[test]
fn exclude_features_failure() {
cargo_hack(["check", "--exclude-features", "a"])
Expand Down

0 comments on commit 1b9d46b

Please sign in to comment.