Skip to content

Commit 94519f2

Browse files
committed
Create dirs if needed before f_p write call
Once `RustDocFingerprint::check_rustdoc_fingerprint()` is executed it might happen that the `doc/` dir is removed. This means that when we call `fingerprint.write()` we need to create the `doc` directory again.
1 parent 33a5248 commit 94519f2

File tree

3 files changed

+9
-85
lines changed

3 files changed

+9
-85
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ impl RustDocFingerprint {
776776

777777
/// Write the `RustDocFingerprint` info into the fingerprint file.
778778
pub fn write(&self, doc_dir: &Path) -> std::io::Result<()> {
779+
crate::util::paths::create_dir_all(doc_dir)
780+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{:?}", e)))?;
779781
let rustdoc_fingerprint_file =
780782
File::create(RustDocFingerprint::path_to_fingerprint(doc_dir))?;
781783
// We write the actual `Rustc` version to it so that we just need to compile it straight

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ use lazycell::LazyCell;
3232
use log::debug;
3333

3434
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
35-
pub use self::build_context::{
36-
BuildContext, FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo,
37-
};
35+
pub use self::build_context::{BuildContext, FileFlavor, FileType, TargetInfo};
3836
use self::build_plan::BuildPlan;
3937
pub use self::compilation::{Compilation, Doctest};
4038
pub use self::compile_kind::{CompileKind, CompileTarget};
@@ -598,7 +596,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
598596
// it doesn't already exist.
599597
paths::create_dir_all(&doc_dir)?;
600598

601-
rustdoc.arg("-o").arg(doc_dir.clone());
599+
rustdoc.arg("-o").arg(doc_dir);
602600

603601
for feat in &unit.features {
604602
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
@@ -651,7 +649,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
651649
false,
652650
)
653651
.chain_err(|| format!("could not document `{}`", name))?;
654-
655652
Ok(())
656653
}))
657654
}

tests/testsuite/doc.rs

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,11 +1607,6 @@ fn crate_versions() {
16071607

16081608
#[cargo_test]
16091609
fn crate_versions_flag_is_overridden() {
1610-
#[derive(Debug, Serialize, Deserialize)]
1611-
pub struct RustDocFingerprint {
1612-
rustc_verbose_version: String,
1613-
}
1614-
16151610
let p = project()
16161611
.file(
16171612
"Cargo.toml",
@@ -1674,11 +1669,11 @@ LLVM version: 9.0
16741669
.file(
16751670
"Cargo.toml",
16761671
r#"
1677-
[package]
1678-
name = "foo"
1679-
version = "1.2.4"
1680-
authors = []
1681-
"#,
1672+
[package]
1673+
name = "foo"
1674+
version = "1.2.4"
1675+
authors = []
1676+
"#,
16821677
)
16831678
.file("src/lib.rs", "//! These are the docs!")
16841679
.build();
@@ -1786,73 +1781,3 @@ LLVM version: 9.0
17861781
(String::from_utf8_lossy(&output.stdout).as_ref())
17871782
);
17881783
}
1789-
1790-
#[cargo_test]
1791-
fn doc_test_in_workspace() {
1792-
let p = project()
1793-
.file(
1794-
"Cargo.toml",
1795-
r#"
1796-
[workspace]
1797-
members = [
1798-
"crate-a",
1799-
"crate-b",
1800-
]
1801-
"#,
1802-
)
1803-
.file(
1804-
"crate-a/Cargo.toml",
1805-
r#"
1806-
[project]
1807-
name = "crate-a"
1808-
version = "0.1.0"
1809-
"#,
1810-
)
1811-
.file(
1812-
"crate-a/src/lib.rs",
1813-
"\
1814-
//! ```
1815-
//! assert_eq!(1, 1);
1816-
//! ```
1817-
",
1818-
)
1819-
.file(
1820-
"crate-b/Cargo.toml",
1821-
r#"
1822-
[project]
1823-
name = "crate-b"
1824-
version = "0.1.0"
1825-
"#,
1826-
)
1827-
.file(
1828-
"crate-b/src/lib.rs",
1829-
"\
1830-
//! ```
1831-
//! assert_eq!(1, 1);
1832-
//! ```
1833-
",
1834-
)
1835-
.build();
1836-
p.cargo("test --doc -vv")
1837-
.with_stderr_contains("[DOCTEST] crate-a")
1838-
.with_stdout_contains(
1839-
"
1840-
running 1 test
1841-
test crate-a/src/lib.rs - (line 1) ... ok
1842-
1843-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
1844-
1845-
",
1846-
)
1847-
.with_stderr_contains("[DOCTEST] crate-b")
1848-
.with_stdout_contains(
1849-
"
1850-
running 1 test
1851-
test crate-b/src/lib.rs - (line 1) ... ok
1852-
1853-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
1854-
1855-
",
1856-
)
1857-
.run();
1858-
}

0 commit comments

Comments
 (0)