From 77855f36362df3e1697ae4b9e39262c9d271d230 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 26 Apr 2021 21:02:29 -0700 Subject: [PATCH 1/2] Use consolidated fingerprint directory for rustdoc. --- .../compiler/context/compilation_files.rs | 2 +- tests/testsuite/doc.rs | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 37b11da8471..026b95e8d04 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -598,7 +598,7 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher) { /// Returns whether or not this unit should use a metadata hash. fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool { - if unit.mode.is_doc_test() { + if unit.mode.is_doc_test() || unit.mode.is_doc() { // Doc tests do not have metadata. return false; } diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index e03b5a18513..7cd3d0d0381 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -863,10 +863,44 @@ fn features() { r#"#[cfg(feature = "bar")] pub fn bar() {}"#, ) .build(); - p.cargo("doc --features foo").run(); + p.cargo("doc --features foo") + .with_stderr( + "\ +[COMPILING] bar v0.0.1 [..] +[DOCUMENTING] bar v0.0.1 [..] +[DOCUMENTING] foo v0.0.1 [..] +[FINISHED] [..] +", + ) + .run(); assert!(p.root().join("target/doc").is_dir()); assert!(p.root().join("target/doc/foo/fn.foo.html").is_file()); assert!(p.root().join("target/doc/bar/fn.bar.html").is_file()); + // Check that turning the feature off will remove the files. + p.cargo("doc") + .with_stderr( + "\ +[COMPILING] bar v0.0.1 [..] +[DOCUMENTING] bar v0.0.1 [..] +[DOCUMENTING] foo v0.0.1 [..] +[FINISHED] [..] +", + ) + .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()); + // And switching back will rebuild and bring them back. + p.cargo("doc --features foo") + .with_stderr( + "\ +[DOCUMENTING] bar v0.0.1 [..] +[DOCUMENTING] foo v0.0.1 [..] +[FINISHED] [..] +", + ) + .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()); } #[cargo_test] From 44c549e6505c418a0c41360a5edd6edf008fda40 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 26 Apr 2021 21:04:01 -0700 Subject: [PATCH 2/2] Clear rustdoc output just before running rustdoc. --- src/cargo/core/compiler/mod.rs | 12 ++++++++++-- tests/testsuite/doc.rs | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 0551f7ce5ed..eadfb83db2a 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -594,7 +594,8 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { // 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); @@ -608,7 +609,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { // 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)); @@ -648,6 +649,13 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } } } + 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 diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 7cd3d0d0381..01b25612e5b 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -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(