Skip to content

Commit d70308e

Browse files
committed
Auto merge of #9332 - ehuss:beta-revert-rustdoc, r=alexcrichton
beta: revert #8640 - rustdoc versioning checks #8640 has been causing some problems with rustbuild (see rust-lang/rust#83914 and rust-lang/rust#83530 (comment)). In order to give more time to figure out a solution, this reverts the change on beta. Will need to take some time to figure out what to do on master. Also cherry picked the following to get tests passing: * #9316 — Fix semver docs for 1.51. * #9307 — tests: Tolerate "exit status" in error messages
2 parents 69b5bbc + 6ce927a commit d70308e

File tree

8 files changed

+12
-283
lines changed

8 files changed

+12
-283
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use std::collections::{HashMap, HashSet};
1111
use std::path::PathBuf;
1212

1313
mod target_info;
14-
pub use self::target_info::{
15-
FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo,
16-
};
14+
pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo};
1715

1816
/// The build context, containing all information about a build task.
1917
///

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

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
use crate::core::compiler::{
2-
BuildOutput, CompileKind, CompileMode, CompileTarget, Context, CrateType,
3-
};
1+
use crate::core::compiler::{BuildOutput, CompileKind, CompileMode, CompileTarget, CrateType};
42
use crate::core::{Dependency, Target, TargetKind, Workspace};
53
use crate::util::config::{Config, StringList, TargetConfig};
6-
use crate::util::{paths, CargoResult, CargoResultExt, ProcessBuilder, Rustc};
4+
use crate::util::{CargoResult, CargoResultExt, ProcessBuilder, Rustc};
75
use cargo_platform::{Cfg, CfgExpr};
8-
use serde::{Deserialize, Serialize};
96
use std::cell::RefCell;
107
use std::collections::hash_map::{Entry, HashMap};
118
use std::env;
12-
use std::path::{Path, PathBuf};
9+
use std::path::PathBuf;
1310
use std::str::{self, FromStr};
1411

1512
/// Information about the platform target gleaned from querying rustc.
@@ -761,77 +758,3 @@ impl RustcTargetData {
761758
self.target_config(kind).links_overrides.get(lib_name)
762759
}
763760
}
764-
765-
/// Structure used to deal with Rustdoc fingerprinting
766-
#[derive(Debug, Serialize, Deserialize)]
767-
pub struct RustDocFingerprint {
768-
pub rustc_vv: String,
769-
}
770-
771-
impl RustDocFingerprint {
772-
/// Read the `RustDocFingerprint` info from the fingerprint file.
773-
fn read(cx: &Context<'_, '_>) -> CargoResult<Self> {
774-
let rustdoc_data = paths::read(&cx.files().host_root().join(".rustdoc_fingerprint.json"))?;
775-
serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e))
776-
}
777-
778-
/// Write the `RustDocFingerprint` info into the fingerprint file.
779-
fn write<'a, 'cfg>(&self, cx: &Context<'a, 'cfg>) -> CargoResult<()> {
780-
paths::write(
781-
&cx.files().host_root().join(".rustdoc_fingerprint.json"),
782-
serde_json::to_string(&self)?.as_bytes(),
783-
)
784-
}
785-
786-
fn remove_doc_dirs(doc_dirs: &[&Path]) -> CargoResult<()> {
787-
doc_dirs
788-
.iter()
789-
.filter(|path| path.exists())
790-
.map(|path| paths::remove_dir_all(&path))
791-
.collect::<CargoResult<()>>()
792-
}
793-
794-
/// This function checks whether the latest version of `Rustc` used to compile this
795-
/// `Workspace`'s docs was the same as the one is currently being used in this `cargo doc`
796-
/// call.
797-
///
798-
/// In case it's not, it takes care of removing the `doc/` folder as well as overwriting
799-
/// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed
800-
/// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have
801-
/// any versioning.
802-
pub fn check_rustdoc_fingerprint(cx: &Context<'_, '_>) -> CargoResult<()> {
803-
let actual_rustdoc_target_data = RustDocFingerprint {
804-
rustc_vv: cx.bcx.rustc().verbose_version.clone(),
805-
};
806-
807-
// Collect all of the target doc paths for which the docs need to be compiled for.
808-
let doc_dirs: Vec<&Path> = cx
809-
.bcx
810-
.all_kinds
811-
.iter()
812-
.map(|kind| cx.files().layout(*kind).doc())
813-
.collect();
814-
815-
// Check wether `.rustdoc_fingerprint.json` exists
816-
match Self::read(cx) {
817-
Ok(fingerprint) => {
818-
// Check if rustc_version matches the one we just used. Otherways,
819-
// remove the `doc` folder to trigger a re-compilation of the docs.
820-
if fingerprint.rustc_vv != actual_rustdoc_target_data.rustc_vv {
821-
Self::remove_doc_dirs(&doc_dirs)?;
822-
actual_rustdoc_target_data.write(cx)?
823-
}
824-
}
825-
// If the file does not exist, then we cannot assume that the docs were compiled
826-
// with the actual Rustc instance version. Therefore, we try to remove the
827-
// `doc` directory forcing the recompilation of the docs. If the directory doesn't
828-
// exists neither, we simply do nothing and continue.
829-
Err(_) => {
830-
// We don't care if this succeeds as explained above.
831-
let _ = Self::remove_doc_dirs(&doc_dirs);
832-
actual_rustdoc_target_data.write(cx)?
833-
}
834-
}
835-
Ok(())
836-
}
837-
}

src/cargo/core/compiler/context/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use super::job_queue::JobQueue;
1818
use super::layout::Layout;
1919
use super::lto::Lto;
2020
use super::unit_graph::UnitDep;
21-
use super::{
22-
BuildContext, Compilation, CompileKind, CompileMode, Executor, FileFlavor, RustDocFingerprint,
23-
};
21+
use super::{BuildContext, Compilation, CompileKind, CompileMode, Executor, FileFlavor};
2422

2523
mod compilation_files;
2624
use self::compilation_files::CompilationFiles;
@@ -135,18 +133,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
135133
custom_build::build_map(&mut self)?;
136134
self.check_collisions()?;
137135

138-
// We need to make sure that if there were any previous docs
139-
// already compiled, they were compiled with the same Rustc version that we're currently
140-
// using. Otherways we must remove the `doc/` folder and compile again forcing a rebuild.
141-
//
142-
// This is important because the `.js`/`.html` & `.css` files that are generated by Rustc don't have
143-
// any versioning (See https://github.com/rust-lang/cargo/issues/8461).
144-
// Therefore, we can end up with weird bugs and behaviours if we mix different
145-
// versions of these files.
146-
if self.bcx.build_config.mode.is_doc() {
147-
RustDocFingerprint::check_rustdoc_fingerprint(&self)?
148-
}
149-
150136
for unit in &self.bcx.roots {
151137
// Build up a list of pending jobs, each of which represent
152138
// compiling a particular package. No actual work is executed as

src/cargo/core/compiler/mod.rs

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

3535
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
36-
pub use self::build_context::{
37-
BuildContext, FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo,
38-
};
36+
pub use self::build_context::{BuildContext, FileFlavor, FileType, RustcTargetData, TargetInfo};
3937
use self::build_plan::BuildPlan;
4038
pub use self::compilation::{Compilation, Doctest, UnitOutput};
4139
pub use self::compile_kind::{CompileKind, CompileTarget};
@@ -601,6 +599,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
601599
if let CompileKind::Target(target) = unit.kind {
602600
rustdoc.arg("--target").arg(target.rustc_target());
603601
}
602+
604603
let doc_dir = cx.files().out_dir(unit);
605604

606605
// Create the documentation directory ahead of time as rustdoc currently has

src/doc/src/reference/semver.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub trait Trait<T> {}
634634
use updated_crate::Trait;
635635
struct Foo;
636636
637-
impl Trait for Foo {} // Error: wrong number of type arguments
637+
impl Trait for Foo {} // Error: missing generics
638638
```
639639

640640
Mitigating strategies:
@@ -943,7 +943,7 @@ pub fn foo<T, U>() {}
943943
use updated_crate::foo;
944944
945945
fn main() {
946-
foo::<u8>(); // Error: wrong number of type arguments
946+
foo::<u8>(); // Error: this function takes 2 type arguments but only 1 type argument was supplied
947947
}
948948
```
949949

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn custom_build_script_failed() {
3838
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
3939
4040
Caused by:
41-
process didn't exit successfully: `[..]/build-script-build` (exit code: 101)",
41+
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",
4242
)
4343
.run();
4444
}

tests/testsuite/doc.rs

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Tests for the `cargo doc` command.
22
3-
use cargo::core::compiler::RustDocFingerprint;
43
use cargo_test_support::paths::CargoPathExt;
54
use cargo_test_support::registry::Package;
65
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
@@ -1716,179 +1715,3 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
17161715
)
17171716
.run();
17181717
}
1719-
1720-
#[cargo_test]
1721-
fn doc_fingerprint_is_versioning_consistent() {
1722-
// Random rustc verbose version
1723-
let old_rustc_verbose_version = format!(
1724-
"\
1725-
rustc 1.41.1 (f3e1a954d 2020-02-24)
1726-
binary: rustc
1727-
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
1728-
commit-date: 2020-02-24
1729-
host: {}
1730-
release: 1.41.1
1731-
LLVM version: 9.0
1732-
",
1733-
rustc_host()
1734-
);
1735-
1736-
// Create the dummy project.
1737-
let dummy_project = project()
1738-
.file(
1739-
"Cargo.toml",
1740-
r#"
1741-
[package]
1742-
name = "foo"
1743-
version = "1.2.4"
1744-
authors = []
1745-
"#,
1746-
)
1747-
.file("src/lib.rs", "//! These are the docs!")
1748-
.build();
1749-
1750-
dummy_project.cargo("doc").run();
1751-
1752-
let fingerprint: RustDocFingerprint =
1753-
serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json"))
1754-
.expect("JSON Serde fail");
1755-
1756-
// Check that the fingerprint contains the actual rustc version
1757-
// which has been used to compile the docs.
1758-
let output = std::process::Command::new("rustc")
1759-
.arg("-vV")
1760-
.output()
1761-
.expect("Failed to get actual rustc verbose version");
1762-
assert_eq!(
1763-
fingerprint.rustc_vv,
1764-
(String::from_utf8_lossy(&output.stdout).as_ref())
1765-
);
1766-
1767-
// As the test shows above. Now we have generated the `doc/` folder and inside
1768-
// the rustdoc fingerprint file is located with the correct rustc version.
1769-
// So we will remove it and create a new fingerprint with an old rustc version
1770-
// inside it. We will also place a bogus file inside of the `doc/` folder to ensure
1771-
// it gets removed as we expect on the next doc compilation.
1772-
dummy_project.change_file(
1773-
"target/.rustdoc_fingerprint.json",
1774-
&old_rustc_verbose_version,
1775-
);
1776-
1777-
fs::write(
1778-
dummy_project.build_dir().join("doc/bogus_file"),
1779-
String::from("This is a bogus file and should be removed!"),
1780-
)
1781-
.expect("Error writing test bogus file");
1782-
1783-
// Now if we trigger another compilation, since the fingerprint contains an old version
1784-
// of rustc, cargo should remove the entire `/doc` folder (including the fingerprint)
1785-
// and generating another one with the actual version.
1786-
// It should also remove the bogus file we created above.
1787-
dummy_project.cargo("doc").run();
1788-
1789-
assert!(!dummy_project.build_dir().join("doc/bogus_file").exists());
1790-
1791-
let fingerprint: RustDocFingerprint =
1792-
serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json"))
1793-
.expect("JSON Serde fail");
1794-
1795-
// Check that the fingerprint contains the actual rustc version
1796-
// which has been used to compile the docs.
1797-
assert_eq!(
1798-
fingerprint.rustc_vv,
1799-
(String::from_utf8_lossy(&output.stdout).as_ref())
1800-
);
1801-
}
1802-
1803-
#[cfg(target_os = "linux")]
1804-
#[cargo_test]
1805-
fn doc_fingerprint_respects_target_paths() {
1806-
// Random rustc verbose version
1807-
let old_rustc_verbose_version = format!(
1808-
"\
1809-
rustc 1.41.1 (f3e1a954d 2020-02-24)
1810-
binary: rustc
1811-
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
1812-
commit-date: 2020-02-24
1813-
host: {}
1814-
release: 1.41.1
1815-
LLVM version: 9.0
1816-
",
1817-
rustc_host()
1818-
);
1819-
1820-
// Create the dummy project.
1821-
let dummy_project = project()
1822-
.file(
1823-
"Cargo.toml",
1824-
r#"
1825-
[package]
1826-
name = "foo"
1827-
version = "1.2.4"
1828-
authors = []
1829-
"#,
1830-
)
1831-
.file("src/lib.rs", "//! These are the docs!")
1832-
.build();
1833-
1834-
dummy_project
1835-
.cargo("doc --target x86_64-unknown-linux-gnu")
1836-
.run();
1837-
1838-
let fingerprint: RustDocFingerprint =
1839-
serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json"))
1840-
.expect("JSON Serde fail");
1841-
1842-
// Check that the fingerprint contains the actual rustc version
1843-
// which has been used to compile the docs.
1844-
let output = std::process::Command::new("rustc")
1845-
.arg("-vV")
1846-
.output()
1847-
.expect("Failed to get actual rustc verbose version");
1848-
assert_eq!(
1849-
fingerprint.rustc_vv,
1850-
(String::from_utf8_lossy(&output.stdout).as_ref())
1851-
);
1852-
1853-
// As the test shows above. Now we have generated the `doc/` folder and inside
1854-
// the rustdoc fingerprint file is located with the correct rustc version.
1855-
// So we will remove it and create a new fingerprint with an old rustc version
1856-
// inside it. We will also place a bogus file inside of the `doc/` folder to ensure
1857-
// it gets removed as we expect on the next doc compilation.
1858-
dummy_project.change_file(
1859-
"target/.rustdoc_fingerprint.json",
1860-
&old_rustc_verbose_version,
1861-
);
1862-
1863-
fs::write(
1864-
dummy_project
1865-
.build_dir()
1866-
.join("x86_64-unknown-linux-gnu/doc/bogus_file"),
1867-
String::from("This is a bogus file and should be removed!"),
1868-
)
1869-
.expect("Error writing test bogus file");
1870-
1871-
// Now if we trigger another compilation, since the fingerprint contains an old version
1872-
// of rustc, cargo should remove the entire `/doc` folder (including the fingerprint)
1873-
// and generating another one with the actual version.
1874-
// It should also remove the bogus file we created above.
1875-
dummy_project
1876-
.cargo("doc --target x86_64-unknown-linux-gnu")
1877-
.run();
1878-
1879-
assert!(!dummy_project
1880-
.build_dir()
1881-
.join("x86_64-unknown-linux-gnu/doc/bogus_file")
1882-
.exists());
1883-
1884-
let fingerprint: RustDocFingerprint =
1885-
serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json"))
1886-
.expect("JSON Serde fail");
1887-
1888-
// Check that the fingerprint contains the actual rustc version
1889-
// which has been used to compile the docs.
1890-
assert_eq!(
1891-
fingerprint.rustc_vv,
1892-
(String::from_utf8_lossy(&output.stdout).as_ref())
1893-
);
1894-
}

tests/testsuite/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn exit_code() {
118118
);
119119
if !cfg!(unix) {
120120
output.push_str(
121-
"[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)",
121+
"[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)",
122122
);
123123
}
124124
p.cargo("run").with_status(2).with_stderr(output).run();
@@ -140,7 +140,7 @@ fn exit_code_verbose() {
140140
);
141141
if !cfg!(unix) {
142142
output.push_str(
143-
"[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)",
143+
"[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)",
144144
);
145145
}
146146

0 commit comments

Comments
 (0)