Skip to content

Commit

Permalink
Clear rustdoc output just before running rustdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Apr 27, 2021
1 parent 77855f3 commit 44c549e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
// script_metadata is not needed here, it is only for tests.
let mut rustdoc = cx.compilation.rustdoc_process(unit, None)?;
rustdoc.inherit_jobserver(&cx.jobserver);
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
let crate_name = unit.target.crate_name();
rustdoc.arg("--crate-name").arg(&crate_name);
add_path_args(bcx.ws, unit, &mut rustdoc);
add_cap_lints(bcx, unit, &mut rustdoc);

Expand All @@ -608,7 +609,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
// it doesn't already exist.
paths::create_dir_all(&doc_dir)?;

rustdoc.arg("-o").arg(doc_dir);
rustdoc.arg("-o").arg(&doc_dir);

for feat in &unit.features {
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
Expand Down Expand Up @@ -648,6 +649,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
}
}
}
let crate_dir = doc_dir.join(&crate_name);
if crate_dir.exists() {
// Remove output from a previous build. This ensures that stale
// files for removed items are removed.
log::debug!("removing pre-existing doc directory {:?}", crate_dir);
paths::remove_dir_all(crate_dir)?;
}
state.running(&rustdoc);

rustdoc
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ fn features() {
",
)
.run();
// assert!(!p.root().join("target/doc/foo/fn.foo.html").is_file());
// assert!(!p.root().join("target/doc/bar/fn.bar.html").is_file());
assert!(!p.root().join("target/doc/foo/fn.foo.html").is_file());
assert!(!p.root().join("target/doc/bar/fn.bar.html").is_file());
// And switching back will rebuild and bring them back.
p.cargo("doc --features foo")
.with_stderr(
Expand Down

0 comments on commit 44c549e

Please sign in to comment.