Skip to content

Commit

Permalink
Auto merge of #5794 - Nemo157:rustdoc-rename-extern, r=alexcrichton
Browse files Browse the repository at this point in the history
Apply dependency renamings when running rustdoc

Fixes #5792
  • Loading branch information
bors committed Jul 26, 2018
2 parents 80f6922 + a432619 commit 191bfbf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Doctest {
pub target: Target,
/// Extern dependencies needed by `rustdoc`. The path is the location of
/// the compiled lib.
pub deps: Vec<(Target, PathBuf)>,
pub deps: Vec<(String, PathBuf)>,
}

/// A structure returning the result of a compilation.
Expand Down
19 changes: 10 additions & 9 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,16 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
for dep in self.dep_targets(unit) {
if dep.target.is_lib() && dep.mode == CompileMode::Build {
let outputs = self.outputs(&dep)?;
doctest_deps.extend(
outputs
.iter()
.filter(|output| {
output.path.extension() == Some(OsStr::new("rlib"))
|| dep.target.for_host()
})
.map(|output| (dep.target.clone(), output.path.clone())),
);
let outputs = outputs.iter().filter(|output| {
output.path.extension() == Some(OsStr::new("rlib"))
|| dep.target.for_host()
});
for output in outputs {
doctest_deps.push((
self.bcx.extern_crate_name(unit, &dep)?,
output.path.clone(),
));
}
}
}
self.compilation.to_doc_test.push(compilation::Doctest {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ fn run_doc_tests(
}
}

for &(ref target, ref lib) in deps.iter() {
let mut arg = OsString::from(target.crate_name());
for &(ref extern_crate_name, ref lib) in deps.iter() {
let mut arg = OsString::from(extern_crate_name);
arg.push("=");
arg.push(lib);
p.arg("--extern").arg(&arg);
Expand Down
45 changes: 45 additions & 0 deletions tests/testsuite/rename_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,48 @@ fn rename_affects_fingerprint() {
execs().with_status(101),
);
}

#[test]
fn can_run_doc_tests() {
Package::new("bar", "0.1.0").publish();
Package::new("bar", "0.2.0").publish();

let foo = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["rename-dependency"]
[project]
name = "foo"
version = "0.0.1"
[dependencies]
bar = { version = "0.1.0" }
baz = { version = "0.2.0", package = "bar" }
"#,
)
.file(
"src/lib.rs",
"
extern crate bar;
extern crate baz;
",
)
.build();

assert_that(
foo.cargo("test").arg("-v").masquerade_as_nightly_cargo(),
execs().with_status(0).with_stderr_contains(format!(
"\
[DOCTEST] foo
[RUNNING] `rustdoc --test {dir}[/]src[/]lib.rs \
[..] \
--extern baz={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
--extern bar={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
[..]`
",
dir = foo.root().display(),
)),
);
}

0 comments on commit 191bfbf

Please sign in to comment.