Skip to content

Commit

Permalink
Treat --all-features flag as one of feature combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 16, 2020
1 parent 45cafc0 commit abcbe71
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 142 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

* Treat `--all-features` flag as one of feature combinations. See [#42][42] for details.

* Add `--skip-all-features` flag. See [#42][42] for details.

[42]: https://github.com/taiki-e/cargo-hack/pull/42

## [0.3.14] - 2020-10-10

* [Add `--depth` option.][59] See [#59][59] for details.
Expand Down
32 changes: 19 additions & 13 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ const HELP: &[(&str, &str, &str, &[&str])] = &[
("", "--exclude <SPEC>...", "Exclude packages from the check", &[]),
("", "--manifest-path <PATH>", "Path to Cargo.toml", &[]),
("", "--features <FEATURES>...", "Space-separated list of features to activate", &[]),
(
"",
"--each-feature",
"Perform for each feature which includes --no-default-features flag and default features of the package",
&[],
),
(
"",
"--feature-powerset",
"Perform for the feature powerset which includes --no-default-features flag and default features of the package",
&[],
),
("", "--each-feature", "Perform for each feature of the package", &[
"This also includes runs with just --no-default-features flag, --all-features flag, and default features.",
]),
("", "--feature-powerset", "Perform for the feature powerset of the package", &[
"This also includes runs with just --no-default-features flag, --all-features flag, and default features.",
]),
("", "--optional-deps [DEPS]...", "Use optional dependencies as features", &[
"If DEPS are not specified, all optional dependencies are considered as features.",
"This flag can only be used with either --each-feature flag or --feature-powerset flag.",
Expand All @@ -39,6 +33,9 @@ const HELP: &[(&str, &str, &str, &[&str])] = &[
("", "--skip-no-default-features", "Skip run of just --no-default-features flag", &[
"This flag can only be used with either --each-feature flag or --feature-powerset flag.",
]),
("", "--skip-all-features", "Skip run of just --all-features flag", &[
"This flag can only be used with either --each-feature flag or --feature-powerset flag.",
]),
(
"",
"--depth <NUM>",
Expand Down Expand Up @@ -121,7 +118,7 @@ impl fmt::Display for Help {
writeln!(
f,
"\
{0} {1}\n\n{2}
{0} {1}\n{2}
USAGE:
cargo hack [OPTIONS] [SUBCOMMAND]\n
Use -h for short descriptions and --help for more details.\n
Expand Down Expand Up @@ -195,6 +192,8 @@ pub(crate) struct Args {
pub(crate) optional_deps: Option<Vec<String>>,
/// --skip-no-default-features
pub(crate) skip_no_default_features: bool,
/// --skip-all-features
pub(crate) skip_all_features: bool,
/// --clean-per-run
pub(crate) clean_per_run: bool,
/// -v, --verbose, -vv
Expand Down Expand Up @@ -279,6 +278,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
let mut ignore_unknown_features = false;
let mut ignore_non_exist_features = false;
let mut skip_no_default_features = false;
let mut skip_all_features = false;
let mut clean_per_run = false;
let mut verbose = false;
let mut depth = None;
Expand Down Expand Up @@ -420,6 +420,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
"--feature-powerset" => parse_flag!(feature_powerset),
"--ignore-private" => parse_flag!(ignore_private),
"--skip-no-default-features" => parse_flag!(skip_no_default_features),
"--skip-all-features" => parse_flag!(skip_all_features),
"--clean-per-run" => parse_flag!(clean_per_run),
"--ignore-unknown-features" => {
if ignore_unknown_features || ignore_non_exist_features {
Expand Down Expand Up @@ -474,6 +475,10 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
bail!(
"--skip-no-default-features can only be used with either --each-feature or --feature-powerset"
);
} else if skip_all_features {
bail!(
"--skip-all-features can only be used with either --each-feature or --feature-powerset"
);
}
}
if depth.is_some() && !feature_powerset {
Expand Down Expand Up @@ -562,6 +567,7 @@ For more information try --help
ignore_unknown_features: ignore_unknown_features || ignore_non_exist_features,
optional_deps,
skip_no_default_features,
skip_all_features,
clean_per_run,
depth,

Expand Down
40 changes: 22 additions & 18 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ impl<'a> Kind<'a> {
*total += 1;
Kind::Nomal { show_progress: true }
} else {
*total += features.len();
if !args.skip.iter().any(|x| x == "default") {
*total += 1;
}
if !args.skip_no_default_features {
*total += 1;
}
*total += features.len()
+ (!args.skip.iter().any(|x| x == "default")) as usize
+ (!args.skip_no_default_features) as usize
+ (!args.skip_all_features) as usize;
Kind::Each { features }
}
} else if args.feature_powerset {
Expand All @@ -102,13 +99,10 @@ impl<'a> Kind<'a> {
Kind::Nomal { show_progress: true }
} else {
// -1: the first element of a powerset is `[]`
*total += features.len() - 1;
if !args.skip.iter().any(|x| x == "default") {
*total += 1;
}
if !args.skip_no_default_features {
*total += 1;
}
*total += features.len() - 1
+ (!args.skip.iter().any(|x| x == "default")) as usize
+ (!args.skip_no_default_features) as usize
+ (!args.skip_all_features) as usize;
Kind::Powerset { features }
}
} else {
Expand Down Expand Up @@ -151,18 +145,28 @@ pub(crate) fn exec(
}

match &package.kind {
Kind::Each { features } => features
.iter()
.try_for_each(|f| exec_cargo_with_features(args, package, &line, info, Some(f))),
Kind::Each { features } => {
features
.iter()
.try_for_each(|f| exec_cargo_with_features(args, package, &line, info, Some(f)))?;
}
Kind::Powerset { features } => {
// The first element of a powerset is `[]` so it should be skipped.
features
.iter()
.skip(1)
.try_for_each(|f| exec_cargo_with_features(args, package, &line, info, f))
.try_for_each(|f| exec_cargo_with_features(args, package, &line, info, f))?;
}
_ => unreachable!(),
}

if !args.skip_all_features {
// run with all features
line.arg("--all-features");
exec_cargo(args, package, &mut line, info, true)?;
}

Ok(())
}

fn exec_cargo_with_features(
Expand Down
16 changes: 12 additions & 4 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cargo-hack 0.3.14

A tool to work around some limitations on cargo.

USAGE:
Expand Down Expand Up @@ -27,10 +26,14 @@ OPTIONS:
Space-separated list of features to activate.

--each-feature
Perform for each feature which includes --no-default-features flag and default features of the package.
Perform for each feature of the package.

This also includes runs of only --no-default-features flag, --all-features flag, and default features.

--feature-powerset
Perform for the feature powerset which includes --no-default-features flag and default features of the package.
Perform for the feature powerset of the package.

This also includes runs of only --no-default-features flag, --all-features flag, and default features.

--optional-deps [DEPS]...
Use optional dependencies as features.
Expand All @@ -47,7 +50,12 @@ OPTIONS:
This flag can only be used with either --each-feature flag or --feature-powerset flag.

--skip-no-default-features
Skip run of just --no-default-features flag.
Skip run of only --no-default-features flag.

This flag can only be used with either --each-feature flag or --feature-powerset flag.

--skip-all-features
Skip run of only --all-features flag.

This flag can only be used with either --each-feature flag or --feature-powerset flag.

Expand Down
8 changes: 4 additions & 4 deletions tests/short-help.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cargo-hack 0.3.14

A tool to work around some limitations on cargo.

USAGE:
Expand All @@ -14,11 +13,12 @@ OPTIONS:
--exclude <SPEC>... Exclude packages from the check
--manifest-path <PATH> Path to Cargo.toml
--features <FEATURES>... Space-separated list of features to activate
--each-feature Perform for each feature which includes --no-default-features flag and default features of the package
--feature-powerset Perform for the feature powerset which includes --no-default-features flag and default features of the package
--each-feature Perform for each feature of the package
--feature-powerset Perform for the feature powerset of the package
--optional-deps [DEPS]... Use optional dependencies as features
--skip <FEATURES>... Space-separated list of features to skip
--skip-no-default-features Skip run of just --no-default-features flag
--skip-no-default-features Skip run of only --no-default-features flag
--skip-all-features Skip run of only --all-features flag
--depth <NUM> Specify a max number of simultaneous feature flags of --feature-powerset
--no-dev-deps Perform without dev-dependencies
--remove-dev-deps Equivalent to --no-dev-deps flag except for does not restore the original `Cargo.toml` after performed
Expand Down
Loading

0 comments on commit abcbe71

Please sign in to comment.