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

Rename --ignore-non-exist-features flag to --ignore-unknown-features #10

Merged
merged 1 commit into from
Nov 1, 2019
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ To install the current cargo-hack requires Rust 1.36 or later.

Skip to perform on `publish = false` packages.

* **`--ignore-non-exist-features`**
* **`--ignore-unknown-features`**

Skip passing `--features` to `cargo` if that feature does not exist.

This is a workaround for an issue that `cargo` does not support for `--features` with workspace ([rust-lang/cargo#3620], [rust-lang/cargo#4106], [rust-lang/cargo#4463], [rust-lang/cargo#4753], [rust-lang/cargo#5015], [rust-lang/cargo#5364], [rust-lang/cargo#6195]).

This feature was formerly called `--ignore-unknown-features`, but has been renamed. The old name can be used as an alias, but is deprecated.

`cargo-hack` changes the behavior of the following existing flags.

* **`--all`**, **`--workspace`**
Expand Down
23 changes: 18 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OPTIONS:
does not restore the original `Cargo.toml`
after execution
--ignore-private Skip to perform on `publish = false` packages
--ignore-non-exist-features Skip passing `--features` to `cargo` if that
--ignore-unknown-features Skip passing `--features` to `cargo` if that
feature does not exist in the package.
-v, --verbose Use verbose output
(this flag will be propagated to cargo)
Expand Down Expand Up @@ -81,7 +81,7 @@ pub(crate) struct Options {
pub(crate) no_dev_deps: bool,
pub(crate) remove_dev_deps: bool,
pub(crate) ignore_private: bool,
pub(crate) ignore_non_exist_features: bool,
pub(crate) ignore_unknown_features: bool,

pub(crate) color: Option<Coloring>,
pub(crate) verbose: bool,
Expand Down Expand Up @@ -141,6 +141,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Options> {
let mut remove_dev_deps = false;
let mut each_feature = false;
let mut ignore_private = false;
let mut ignore_unknown_features = false;
let mut ignore_non_exist_features = false;

let res = (|| -> Result<()> {
Expand Down Expand Up @@ -280,10 +281,16 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Options> {
}
ignore_private = true;
}
"--ignore-non-exist-features" => {
if ignore_non_exist_features {
"--ignore-unknown-features" => {
if ignore_unknown_features || ignore_non_exist_features {
return Err(multi_arg(&arg, subcommand.as_ref()));
}
ignore_unknown_features = true;
}
"--ignore-non-exist-features" => {
if ignore_unknown_features || ignore_non_exist_features {
return Err(multi_arg("--ignore-unknown-features", subcommand.as_ref()));
}
ignore_non_exist_features = true;
}
_ => first.push(arg),
Expand All @@ -297,6 +304,12 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Options> {
let color = color.map(|c| c.parse()).transpose()?;
*coloring = color;
let verbose = first.iter().any(|a| a == "--verbose" || a == "-v" || a == "-vv");
if ignore_non_exist_features {
warn!(
color,
"'--ignore-non-exist-features' flag is deprecated, use '--ignore-unknown-features' flag instead"
);
}

res.map(|()| Options {
first,
Expand All @@ -315,7 +328,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Options> {
no_dev_deps,
remove_dev_deps,
ignore_private,
ignore_non_exist_features,
ignore_unknown_features: ignore_unknown_features || ignore_non_exist_features,

color,
verbose,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn no_dev_deps(manifest: &Manifest, args: &Options) -> Result<()> {

fn each_feature(manifest: &Manifest, args: &Options) -> Result<()> {
let mut features = String::new();
if args.ignore_non_exist_features {
if args.ignore_unknown_features {
let f: Vec<_> = args
.features
.iter()
Expand All @@ -199,7 +199,7 @@ fn each_feature(manifest: &Manifest, args: &Options) -> Result<()> {
// ignored
info!(
args.color,
"skipped applying non-exist `{}` feature to {}",
"skipped applying unknown `{}` feature to {}",
f,
manifest.package_name_verbose(args)
);
Expand Down
19 changes: 17 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ fn test_exclude() {
.assert_stderr_contains("`--exclude` flag for `cargo hack` is currently ignored");
}

#[test]
fn test_ignore_unknown_features() {
let output = cargo_hack()
.args(&["hack", "check", "--ignore-unknown-features", "--features=f"])
.current_dir(test_dir("tests/fixtures/virtual"))
.output()
.unwrap();

output
.assert_success()
.assert_stderr_contains("skipped applying unknown `f` feature to member1")
.assert_stderr_contains("skipped applying unknown `f` feature to member2");
}

#[test]
fn test_ignore_non_exist_features() {
let output = cargo_hack()
Expand All @@ -256,8 +270,9 @@ fn test_ignore_non_exist_features() {

output
.assert_success()
.assert_stderr_contains("skipped applying non-exist `f` feature to member1")
.assert_stderr_contains("skipped applying non-exist `f` feature to member2");
.assert_stderr_contains("'--ignore-non-exist-features' flag is deprecated, use '--ignore-unknown-features' flag instead")
.assert_stderr_contains("skipped applying unknown `f` feature to member1")
.assert_stderr_contains("skipped applying unknown `f` feature to member2");
}

#[test]
Expand Down