Skip to content

Commit

Permalink
Auto merge of #4084 - shiver:issue-3360, r=alexcrichton
Browse files Browse the repository at this point in the history
3360 - Allow for features to be either comma or space delimited.

This is my attempt at tackling issue #3360.
Hopefully I interpreted the original request correctly and this is what you were looking for.

Any suggestions you might have to improve the submission would be great.
Thanks!
  • Loading branch information
bors committed May 22, 2017
2 parents 483e0ab + 72f8427 commit 26d1d9d
Showing 2 changed files with 124 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
@@ -28,9 +28,12 @@ pub fn resolve_ws_precisely<'a>(ws: &Workspace<'a>,
no_default_features: bool,
specs: &[PackageIdSpec])
-> CargoResult<(PackageSet<'a>, Resolve)> {
let features = features.iter().flat_map(|s| {
s.split_whitespace()
}).map(|s| s.to_string()).collect::<Vec<String>>();
let features = features.iter()
.flat_map(|s| s.split_whitespace())
.flat_map(|s| s.split(','))
.filter(|s| s.len() > 0)
.map(|s| s.to_string())
.collect::<Vec<String>>();

let mut registry = PackageRegistry::new(ws.config())?;
if let Some(source) = source {
118 changes: 118 additions & 0 deletions tests/features.rs
Original file line number Diff line number Diff line change
@@ -1007,3 +1007,121 @@ fn all_features_flag_enables_all_features() {
assert_that(p.cargo_process("build").arg("--all-features"),
execs().with_status(0));
}

#[test]
fn many_cli_features_comma_delimited() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.bar]
path = "bar"
optional = true
[dependencies.baz]
path = "baz"
optional = true
"#)
.file("src/main.rs", r#"
extern crate bar;
extern crate baz;
fn main() {}
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("baz/Cargo.toml", r#"
[package]
name = "baz"
version = "0.0.1"
authors = []
"#)
.file("baz/src/lib.rs", "pub fn baz() {}");

assert_that(p.cargo_process("build").arg("--features").arg("bar,baz"),
execs().with_status(0).with_stderr(format!("\
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", dir = p.url())));
}

#[test]
fn many_cli_features_comma_and_space_delimited() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.bar]
path = "bar"
optional = true
[dependencies.baz]
path = "baz"
optional = true
[dependencies.bam]
path = "bam"
optional = true
[dependencies.bap]
path = "bap"
optional = true
"#)
.file("src/main.rs", r#"
extern crate bar;
extern crate baz;
extern crate bam;
extern crate bap;
fn main() {}
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("baz/Cargo.toml", r#"
[package]
name = "baz"
version = "0.0.1"
authors = []
"#)
.file("baz/src/lib.rs", "pub fn baz() {}")
.file("bam/Cargo.toml", r#"
[package]
name = "bam"
version = "0.0.1"
authors = []
"#)
.file("bam/src/lib.rs", "pub fn bam() {}")
.file("bap/Cargo.toml", r#"
[package]
name = "bap"
version = "0.0.1"
authors = []
"#)
.file("bap/src/lib.rs", "pub fn bap() {}");

assert_that(p.cargo_process("build").arg("--features").arg("bar,baz bam bap"),
execs().with_status(0).with_stderr(format!("\
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] ba[..] v0.0.1 ({dir}/ba[..])
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", dir = p.url())));
}

0 comments on commit 26d1d9d

Please sign in to comment.