Skip to content

Commit 191bfbf

Browse files
committed
Auto merge of #5794 - Nemo157:rustdoc-rename-extern, r=alexcrichton
Apply dependency renamings when running rustdoc Fixes #5792
2 parents 80f6922 + a432619 commit 191bfbf

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct Doctest {
1717
pub target: Target,
1818
/// Extern dependencies needed by `rustdoc`. The path is the location of
1919
/// the compiled lib.
20-
pub deps: Vec<(Target, PathBuf)>,
20+
pub deps: Vec<(String, PathBuf)>,
2121
}
2222

2323
/// A structure returning the result of a compilation.

src/cargo/core/compiler/context/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,16 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
244244
for dep in self.dep_targets(unit) {
245245
if dep.target.is_lib() && dep.mode == CompileMode::Build {
246246
let outputs = self.outputs(&dep)?;
247-
doctest_deps.extend(
248-
outputs
249-
.iter()
250-
.filter(|output| {
251-
output.path.extension() == Some(OsStr::new("rlib"))
252-
|| dep.target.for_host()
253-
})
254-
.map(|output| (dep.target.clone(), output.path.clone())),
255-
);
247+
let outputs = outputs.iter().filter(|output| {
248+
output.path.extension() == Some(OsStr::new("rlib"))
249+
|| dep.target.for_host()
250+
});
251+
for output in outputs {
252+
doctest_deps.push((
253+
self.bcx.extern_crate_name(unit, &dep)?,
254+
output.path.clone(),
255+
));
256+
}
256257
}
257258
}
258259
self.compilation.to_doc_test.push(compilation::Doctest {

src/cargo/ops/cargo_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ fn run_doc_tests(
193193
}
194194
}
195195

196-
for &(ref target, ref lib) in deps.iter() {
197-
let mut arg = OsString::from(target.crate_name());
196+
for &(ref extern_crate_name, ref lib) in deps.iter() {
197+
let mut arg = OsString::from(extern_crate_name);
198198
arg.push("=");
199199
arg.push(lib);
200200
p.arg("--extern").arg(&arg);

tests/testsuite/rename_deps.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,48 @@ fn rename_affects_fingerprint() {
319319
execs().with_status(101),
320320
);
321321
}
322+
323+
#[test]
324+
fn can_run_doc_tests() {
325+
Package::new("bar", "0.1.0").publish();
326+
Package::new("bar", "0.2.0").publish();
327+
328+
let foo = project()
329+
.file(
330+
"Cargo.toml",
331+
r#"
332+
cargo-features = ["rename-dependency"]
333+
334+
[project]
335+
name = "foo"
336+
version = "0.0.1"
337+
338+
[dependencies]
339+
bar = { version = "0.1.0" }
340+
baz = { version = "0.2.0", package = "bar" }
341+
"#,
342+
)
343+
.file(
344+
"src/lib.rs",
345+
"
346+
extern crate bar;
347+
extern crate baz;
348+
",
349+
)
350+
.build();
351+
352+
assert_that(
353+
foo.cargo("test").arg("-v").masquerade_as_nightly_cargo(),
354+
execs().with_status(0).with_stderr_contains(format!(
355+
"\
356+
[DOCTEST] foo
357+
[RUNNING] `rustdoc --test {dir}[/]src[/]lib.rs \
358+
[..] \
359+
--extern baz={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
360+
--extern bar={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
361+
[..]`
362+
",
363+
dir = foo.root().display(),
364+
)),
365+
);
366+
}

0 commit comments

Comments
 (0)