Skip to content

Commit

Permalink
Properly reflect stabilization of namespaced features in exclude_all_…
Browse files Browse the repository at this point in the history
…features
  • Loading branch information
taiki-e committed Apr 2, 2024
1 parent 64895b7 commit aa0d0f6
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 145 deletions.
24 changes: 1 addition & 23 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,8 @@ impl Args {

// https://github.com/taiki-e/cargo-hack/issues/42
// https://github.com/rust-lang/cargo/pull/8799
let namespaced_features = has_z_flag(&cargo_args, "namespaced-features");
exclude_no_default_features |= !include_features.is_empty();
exclude_all_features |= !include_features.is_empty()
|| !exclude_features.is_empty()
|| (feature_powerset && !namespaced_features && depth.is_none());
exclude_all_features |= !include_features.is_empty() || !exclude_features.is_empty();
exclude_features.extend_from_slice(&features);

term::verbose::set(verbose != 0);
Expand Down Expand Up @@ -668,25 +665,6 @@ fn parse_grouped_features(
Ok(group_features)
}

fn has_z_flag(args: &[String], name: &str) -> bool {
let mut iter = args.iter().map(String::as_str);
while let Some(mut arg) = iter.next() {
if arg == "-Z" {
arg = iter.next().unwrap();
} else if let Some(a) = arg.strip_prefix("-Z") {
arg = a;
} else {
continue;
}
if let Some(rest) = arg.strip_prefix(name) {
if rest.is_empty() || rest.starts_with('=') {
return true;
}
}
}
false
}

// (short flag, long flag, value name, short descriptions, additional descriptions)
type HelpText<'a> = (&'a str, &'a str, &'a str, &'a str, &'a [&'a str]);

Expand Down
38 changes: 31 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ fn determine_kind<'a>(
let kind = Kind::Normal;
Some(PackageRuns { id, kind, feature_count })
} else {
// See exec_on_package
let feature_count = features.len()
+ usize::from(!cx.exclude_no_default_features)
+ usize::from(
!cx.exclude_all_features
&& pkg_features.normal().len() + pkg_features.optional_deps().len() > 1,
!(cx.exclude_all_features
|| pkg_features.optional_deps().is_empty()
&& pkg_features.normal().len() <= 1),
);
let kind = Kind::Each { features };
Some(PackageRuns { id, kind, feature_count })
Expand All @@ -290,11 +292,17 @@ fn determine_kind<'a>(
let kind = Kind::Normal;
Some(PackageRuns { id, kind, feature_count })
} else {
// See exec_on_package
let feature_count = features.len()
+ usize::from(!cx.exclude_no_default_features)
+ usize::from(
!cx.exclude_all_features
&& pkg_features.normal().len() + pkg_features.optional_deps().len() > 1,
!(cx.exclude_all_features
|| (pkg_features.optional_deps().is_empty()
|| match &cx.optional_deps {
// Skip when all optional deps are already included in powerset
Some(opt_deps) => opt_deps.is_empty(),
None => false,
})),
);
let kind = Kind::Powerset { features };
Some(PackageRuns { id, kind, feature_count })
Expand Down Expand Up @@ -478,10 +486,26 @@ fn exec_on_package(
}

// Run with --all-features first: https://github.com/taiki-e/cargo-hack/issues/246
// https://github.com/taiki-e/cargo-hack/issues/42
// https://github.com/rust-lang/cargo/pull/8799
// > --all-features will now enable features for inactive optional dependencies.
let pkg_features = cx.pkg_features(id);
if !cx.exclude_all_features
&& pkg_features.normal().len() + pkg_features.optional_deps().len() > 1
{
let exclude_all_features = cx.exclude_all_features
|| match kind {
Kind::Each { .. } => {
pkg_features.optional_deps().is_empty() && pkg_features.normal().len() <= 1
}
Kind::Powerset { .. } => {
pkg_features.optional_deps().is_empty()
|| match &cx.optional_deps {
// Skip when all optional deps are already included in powerset
Some(opt_deps) => opt_deps.is_empty() && cx.depth.is_none(),
None => false,
}
}
Kind::Normal => unreachable!(),
};
if !exclude_all_features {
let mut line = line.clone();
// run with all features
// https://github.com/taiki-e/cargo-hack/issues/42
Expand Down
Loading

0 comments on commit aa0d0f6

Please sign in to comment.