Skip to content

Commit a432619

Browse files
committed
Apply dependency renamings when running rustdoc
Fixes #5792
1 parent 4e53ce4 commit a432619

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
@@ -363,3 +363,48 @@ fn rename_affects_fingerprint() {
363363
execs().with_status(101),
364364
);
365365
}
366+
367+
#[test]
368+
fn can_run_doc_tests() {
369+
Package::new("bar", "0.1.0").publish();
370+
Package::new("bar", "0.2.0").publish();
371+
372+
let foo = project()
373+
.file(
374+
"Cargo.toml",
375+
r#"
376+
cargo-features = ["rename-dependency"]
377+
378+
[project]
379+
name = "foo"
380+
version = "0.0.1"
381+
382+
[dependencies]
383+
bar = { version = "0.1.0" }
384+
baz = { version = "0.2.0", package = "bar" }
385+
"#,
386+
)
387+
.file(
388+
"src/lib.rs",
389+
"
390+
extern crate bar;
391+
extern crate baz;
392+
",
393+
)
394+
.build();
395+
396+
assert_that(
397+
foo.cargo("test").arg("-v").masquerade_as_nightly_cargo(),
398+
execs().with_status(0).with_stderr_contains(format!(
399+
"\
400+
[DOCTEST] foo
401+
[RUNNING] `rustdoc --test {dir}[/]src[/]lib.rs \
402+
[..] \
403+
--extern baz={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
404+
--extern bar={dir}[/]target[/]debug[/]deps[/]libbar-[..].rlib \
405+
[..]`
406+
",
407+
dir = foo.root().display(),
408+
)),
409+
);
410+
}

0 commit comments

Comments
 (0)