mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 14:04:23 +00:00
Auto merge of #10324 - ehuss:fix-doc-undocumented-dep, r=alexcrichton
Fix documenting with undocumented dependencies. #10201 introduced a bug where dependencies that have `doc=false` weren't being built at all when running `cargo doc` if the project did not have any binaries. That means the rmeta file was missing, and the `--extern` flag was not being passed to rustdoc. The solution is to ensure the `rmeta` file gets generated, but only skip generating the `CompileMode::Doc` unit for undocumented dependencies. This unblocks the bootstrap bump.
This commit is contained in:
commit
9978fd72c8
|
@ -431,7 +431,7 @@ fn compute_deps_doc(
|
|||
let mut ret = Vec::new();
|
||||
for (id, _deps) in deps {
|
||||
let dep = state.get(id);
|
||||
let lib = match dep.targets().iter().find(|t| t.is_lib() && t.documented()) {
|
||||
let lib = match dep.targets().iter().find(|t| t.is_lib()) {
|
||||
Some(lib) => lib,
|
||||
None => continue,
|
||||
};
|
||||
|
@ -449,18 +449,20 @@ fn compute_deps_doc(
|
|||
mode,
|
||||
)?;
|
||||
ret.push(lib_unit_dep);
|
||||
if let CompileMode::Doc { deps: true } = unit.mode {
|
||||
// Document this lib as well.
|
||||
let doc_unit_dep = new_unit_dep(
|
||||
state,
|
||||
unit,
|
||||
dep,
|
||||
lib,
|
||||
dep_unit_for,
|
||||
unit.kind.for_target(lib),
|
||||
unit.mode,
|
||||
)?;
|
||||
ret.push(doc_unit_dep);
|
||||
if lib.documented() {
|
||||
if let CompileMode::Doc { deps: true } = unit.mode {
|
||||
// Document this lib as well.
|
||||
let doc_unit_dep = new_unit_dep(
|
||||
state,
|
||||
unit,
|
||||
dep,
|
||||
lib,
|
||||
dep_unit_for,
|
||||
unit.kind.for_target(lib),
|
||||
unit.mode,
|
||||
)?;
|
||||
ret.push(doc_unit_dep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2557,7 +2557,7 @@ fn doc_lib_false() {
|
|||
bar = {path = "bar"}
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.file("src/lib.rs", "extern crate bar;")
|
||||
.file("src/bin/some-bin.rs", "fn main() {}")
|
||||
.file(
|
||||
"bar/Cargo.toml",
|
||||
|
@ -2588,3 +2588,48 @@ fn doc_lib_false() {
|
|||
assert!(!p.build_dir().join("doc/bar").exists());
|
||||
assert!(p.build_dir().join("doc/some_bin").exists());
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn doc_lib_false_dep() {
|
||||
// doc = false for a dependency
|
||||
// Ensures that the rmeta gets produced
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
bar = { path = "bar" }
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "extern crate bar;")
|
||||
.file(
|
||||
"bar/Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "bar"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
doc = false
|
||||
"#,
|
||||
)
|
||||
.file("bar/src/lib.rs", "")
|
||||
.build();
|
||||
|
||||
p.cargo("doc")
|
||||
.with_stderr(
|
||||
"\
|
||||
[CHECKING] bar v0.1.0 [..]
|
||||
[DOCUMENTING] foo v0.1.0 [..]
|
||||
[FINISHED] [..]
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
||||
assert!(p.build_dir().join("doc/foo").exists());
|
||||
assert!(!p.build_dir().join("doc/bar").exists());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue