Don't accumulate feature and rustdoc flags twice (fixes #4790)

This commit is contained in:
Anthony Ramine 2017-12-07 15:13:46 +01:00
parent 3992e5259b
commit c057d9e206
2 changed files with 21 additions and 5 deletions

View file

@ -226,14 +226,15 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
}
let feats = cx.resolve.features(unit.pkg.package_id());
cx.compilation.cfgs.entry(unit.pkg.package_id().clone())
.or_insert_with(HashSet::new)
.extend(feats.iter().map(|feat| format!("feature=\"{}\"", feat)));
if !feats.is_empty() {
cx.compilation.cfgs.entry(unit.pkg.package_id().clone()).or_insert_with(|| {
feats.iter().map(|feat| format!("feature=\"{}\"", feat)).collect()
});
}
let rustdocflags = cx.rustdocflags_args(&unit)?;
if !rustdocflags.is_empty() {
cx.compilation.rustdocflags.entry(unit.pkg.package_id().clone())
.or_insert_with(Vec::new)
.extend(rustdocflags);
.or_insert(rustdocflags);
}
output_depinfo(&mut cx, unit)?;

View file

@ -105,3 +105,18 @@ fn rustdocflags_passed_to_rustdoc_through_cargo_test() {
assert_that(p.cargo("test").arg("--doc").env("RUSTDOCFLAGS", "--cfg do_not_choke"),
execs().with_status(0));
}
#[test]
fn rustdocflags_passed_to_rustdoc_through_cargo_test_only_once() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
"#)
.file("src/lib.rs", "")
.build();
assert_that(p.cargo("test").arg("--doc").env("RUSTDOCFLAGS", "--markdown-no-toc"),
execs().with_status(0));
}