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

Do not emit "specified feature not found" warning when building multiple packages #158

Merged
merged 1 commit into from
Jul 30, 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
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