Skip to content

Commit b21b941

Browse files
authored
Auto merge of #3179 - alexcrichton:fix-features-mulitple, r=matklad
Parse --features in `cargo metadata` the same This accidentally didn't accept space-separated features passed through `--features` as the logic for doing the splitting wasn't shared. Let's share it!
2 parents f265c77 + 49fe650 commit b21b941

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/cargo/ops/cargo_compile.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions<'a>)
100100

101101
pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
102102
source: Option<Box<Source + 'a>>,
103-
features: Vec<String>,
103+
features: &[String],
104104
all_features: bool,
105105
no_default_features: bool,
106106
spec: &'a [String])
107107
-> CargoResult<(PackageSet<'a>, Resolve)> {
108+
let features = features.iter().flat_map(|s| {
109+
s.split_whitespace()
110+
}).map(|s| s.to_string()).collect::<Vec<String>>();
108111

109112
let mut registry = try!(PackageRegistry::new(ws.config()));
110113

@@ -161,9 +164,6 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
161164
ref target_rustc_args } = *options;
162165

163166
let target = target.map(|s| s.to_string());
164-
let features = features.iter().flat_map(|s| {
165-
s.split(' ')
166-
}).map(|s| s.to_string()).collect::<Vec<String>>();
167167

168168
if jobs == Some(0) {
169169
bail!("jobs must be at least 1")

src/cargo/ops/cargo_output_metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn metadata_full(ws: &Workspace,
4545
opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {
4646
let deps = try!(ops::resolve_dependencies(ws,
4747
None,
48-
opt.features.clone(),
48+
&opt.features,
4949
opt.all_features,
5050
opt.no_default_features,
5151
&[]));

tests/metadata.rs

+20
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,23 @@ fn carg_metadata_bad_version() {
429429
execs().with_status(101)
430430
.with_stderr("[ERROR] metadata version 2 not supported, only 1 is currently supported"));
431431
}
432+
433+
#[test]
434+
fn multiple_features() {
435+
let p = project("foo")
436+
.file("Cargo.toml", r#"
437+
[package]
438+
name = "foo"
439+
version = "0.1.0"
440+
authors = []
441+
442+
[features]
443+
a = []
444+
b = []
445+
"#)
446+
.file("src/lib.rs", "");
447+
448+
assert_that(p.cargo_process("metadata")
449+
.arg("--features").arg("a b"),
450+
execs().with_status(0));
451+
}

0 commit comments

Comments
 (0)