From de983c98c21452508cc7229e424abf3ffda8deb9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 5 Apr 2021 20:51:01 -0700 Subject: [PATCH 1/3] beta: revert #8640 - rustdoc versioning checks This reverts commit 8fa0827d27feccd956729c96c393564726c0e102, reversing changes made to b842849732f89df8675eb2d933c384d6338e4466. # Conflicts: # src/cargo/core/compiler/build_context/target_info.rs # tests/testsuite/doc.rs --- src/cargo/core/compiler/build_context/mod.rs | 4 +- .../compiler/build_context/target_info.rs | 83 +------- src/cargo/core/compiler/context/mod.rs | 16 +- src/cargo/core/compiler/mod.rs | 5 +- tests/testsuite/doc.rs | 177 ------------------ 5 files changed, 7 insertions(+), 278 deletions(-) diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index cd42c3a4ec1..303bf6a873c 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -11,9 +11,7 @@ use std::collections::{HashMap, HashSet}; use std::path::PathBuf; mod target_info; -pub use self::target_info::{ - FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo, -}; +pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo}; /// The build context, containing all information about a build task. /// diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index fd40f4f3e05..a8c47c93252 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -1,15 +1,12 @@ -use crate::core::compiler::{ - BuildOutput, CompileKind, CompileMode, CompileTarget, Context, CrateType, -}; +use crate::core::compiler::{BuildOutput, CompileKind, CompileMode, CompileTarget, CrateType}; use crate::core::{Dependency, Target, TargetKind, Workspace}; use crate::util::config::{Config, StringList, TargetConfig}; -use crate::util::{paths, CargoResult, CargoResultExt, ProcessBuilder, Rustc}; +use crate::util::{CargoResult, CargoResultExt, ProcessBuilder, Rustc}; use cargo_platform::{Cfg, CfgExpr}; -use serde::{Deserialize, Serialize}; use std::cell::RefCell; use std::collections::hash_map::{Entry, HashMap}; use std::env; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::str::{self, FromStr}; /// Information about the platform target gleaned from querying rustc. @@ -761,77 +758,3 @@ impl RustcTargetData { self.target_config(kind).links_overrides.get(lib_name) } } - -/// Structure used to deal with Rustdoc fingerprinting -#[derive(Debug, Serialize, Deserialize)] -pub struct RustDocFingerprint { - pub rustc_vv: String, -} - -impl RustDocFingerprint { - /// Read the `RustDocFingerprint` info from the fingerprint file. - fn read(cx: &Context<'_, '_>) -> CargoResult { - let rustdoc_data = paths::read(&cx.files().host_root().join(".rustdoc_fingerprint.json"))?; - serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e)) - } - - /// Write the `RustDocFingerprint` info into the fingerprint file. - fn write<'a, 'cfg>(&self, cx: &Context<'a, 'cfg>) -> CargoResult<()> { - paths::write( - &cx.files().host_root().join(".rustdoc_fingerprint.json"), - serde_json::to_string(&self)?.as_bytes(), - ) - } - - fn remove_doc_dirs(doc_dirs: &[&Path]) -> CargoResult<()> { - doc_dirs - .iter() - .filter(|path| path.exists()) - .map(|path| paths::remove_dir_all(&path)) - .collect::>() - } - - /// This function checks whether the latest version of `Rustc` used to compile this - /// `Workspace`'s docs was the same as the one is currently being used in this `cargo doc` - /// call. - /// - /// In case it's not, it takes care of removing the `doc/` folder as well as overwriting - /// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed - /// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have - /// any versioning. - pub fn check_rustdoc_fingerprint(cx: &Context<'_, '_>) -> CargoResult<()> { - let actual_rustdoc_target_data = RustDocFingerprint { - rustc_vv: cx.bcx.rustc().verbose_version.clone(), - }; - - // Collect all of the target doc paths for which the docs need to be compiled for. - let doc_dirs: Vec<&Path> = cx - .bcx - .all_kinds - .iter() - .map(|kind| cx.files().layout(*kind).doc()) - .collect(); - - // Check wether `.rustdoc_fingerprint.json` exists - match Self::read(cx) { - Ok(fingerprint) => { - // Check if rustc_version matches the one we just used. Otherways, - // remove the `doc` folder to trigger a re-compilation of the docs. - if fingerprint.rustc_vv != actual_rustdoc_target_data.rustc_vv { - Self::remove_doc_dirs(&doc_dirs)?; - actual_rustdoc_target_data.write(cx)? - } - } - // If the file does not exist, then we cannot assume that the docs were compiled - // with the actual Rustc instance version. Therefore, we try to remove the - // `doc` directory forcing the recompilation of the docs. If the directory doesn't - // exists neither, we simply do nothing and continue. - Err(_) => { - // We don't care if this succeeds as explained above. - let _ = Self::remove_doc_dirs(&doc_dirs); - actual_rustdoc_target_data.write(cx)? - } - } - Ok(()) - } -} diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index cb1dbb6240b..1429485326a 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -18,9 +18,7 @@ use super::job_queue::JobQueue; use super::layout::Layout; use super::lto::Lto; use super::unit_graph::UnitDep; -use super::{ - BuildContext, Compilation, CompileKind, CompileMode, Executor, FileFlavor, RustDocFingerprint, -}; +use super::{BuildContext, Compilation, CompileKind, CompileMode, Executor, FileFlavor}; mod compilation_files; use self::compilation_files::CompilationFiles; @@ -135,18 +133,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { custom_build::build_map(&mut self)?; self.check_collisions()?; - // We need to make sure that if there were any previous docs - // already compiled, they were compiled with the same Rustc version that we're currently - // using. Otherways we must remove the `doc/` folder and compile again forcing a rebuild. - // - // This is important because the `.js`/`.html` & `.css` files that are generated by Rustc don't have - // any versioning (See https://github.com/rust-lang/cargo/issues/8461). - // Therefore, we can end up with weird bugs and behaviours if we mix different - // versions of these files. - if self.bcx.build_config.mode.is_doc() { - RustDocFingerprint::check_rustdoc_fingerprint(&self)? - } - for unit in &self.bcx.roots { // Build up a list of pending jobs, each of which represent // compiling a particular package. No actual work is executed as diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 382e36ce6e0..ec9362e9b73 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -33,9 +33,7 @@ use lazycell::LazyCell; use log::debug; pub use self::build_config::{BuildConfig, CompileMode, MessageFormat}; -pub use self::build_context::{ - BuildContext, FileFlavor, FileType, RustDocFingerprint, RustcTargetData, TargetInfo, -}; +pub use self::build_context::{BuildContext, FileFlavor, FileType, RustcTargetData, TargetInfo}; use self::build_plan::BuildPlan; pub use self::compilation::{Compilation, Doctest, UnitOutput}; pub use self::compile_kind::{CompileKind, CompileTarget}; @@ -601,6 +599,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { if let CompileKind::Target(target) = unit.kind { rustdoc.arg("--target").arg(target.rustc_target()); } + let doc_dir = cx.files().out_dir(unit); // Create the documentation directory ahead of time as rustdoc currently has diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index c06e13a3fe6..970dc5d2d9f 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1,6 +1,5 @@ //! Tests for the `cargo doc` command. -use cargo::core::compiler::RustDocFingerprint; use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; 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[..] ) .run(); } - -#[cargo_test] -fn doc_fingerprint_is_versioning_consistent() { - // Random rustc verbose version - let old_rustc_verbose_version = format!( - "\ -rustc 1.41.1 (f3e1a954d 2020-02-24) -binary: rustc -commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196 -commit-date: 2020-02-24 -host: {} -release: 1.41.1 -LLVM version: 9.0 -", - rustc_host() - ); - - // Create the dummy project. - let dummy_project = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "1.2.4" - authors = [] - "#, - ) - .file("src/lib.rs", "//! These are the docs!") - .build(); - - dummy_project.cargo("doc").run(); - - let fingerprint: RustDocFingerprint = - serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json")) - .expect("JSON Serde fail"); - - // Check that the fingerprint contains the actual rustc version - // which has been used to compile the docs. - let output = std::process::Command::new("rustc") - .arg("-vV") - .output() - .expect("Failed to get actual rustc verbose version"); - assert_eq!( - fingerprint.rustc_vv, - (String::from_utf8_lossy(&output.stdout).as_ref()) - ); - - // As the test shows above. Now we have generated the `doc/` folder and inside - // the rustdoc fingerprint file is located with the correct rustc version. - // So we will remove it and create a new fingerprint with an old rustc version - // inside it. We will also place a bogus file inside of the `doc/` folder to ensure - // it gets removed as we expect on the next doc compilation. - dummy_project.change_file( - "target/.rustdoc_fingerprint.json", - &old_rustc_verbose_version, - ); - - fs::write( - dummy_project.build_dir().join("doc/bogus_file"), - String::from("This is a bogus file and should be removed!"), - ) - .expect("Error writing test bogus file"); - - // Now if we trigger another compilation, since the fingerprint contains an old version - // of rustc, cargo should remove the entire `/doc` folder (including the fingerprint) - // and generating another one with the actual version. - // It should also remove the bogus file we created above. - dummy_project.cargo("doc").run(); - - assert!(!dummy_project.build_dir().join("doc/bogus_file").exists()); - - let fingerprint: RustDocFingerprint = - serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json")) - .expect("JSON Serde fail"); - - // Check that the fingerprint contains the actual rustc version - // which has been used to compile the docs. - assert_eq!( - fingerprint.rustc_vv, - (String::from_utf8_lossy(&output.stdout).as_ref()) - ); -} - -#[cfg(target_os = "linux")] -#[cargo_test] -fn doc_fingerprint_respects_target_paths() { - // Random rustc verbose version - let old_rustc_verbose_version = format!( - "\ -rustc 1.41.1 (f3e1a954d 2020-02-24) -binary: rustc -commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196 -commit-date: 2020-02-24 -host: {} -release: 1.41.1 -LLVM version: 9.0 -", - rustc_host() - ); - - // Create the dummy project. - let dummy_project = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "1.2.4" - authors = [] - "#, - ) - .file("src/lib.rs", "//! These are the docs!") - .build(); - - dummy_project - .cargo("doc --target x86_64-unknown-linux-gnu") - .run(); - - let fingerprint: RustDocFingerprint = - serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json")) - .expect("JSON Serde fail"); - - // Check that the fingerprint contains the actual rustc version - // which has been used to compile the docs. - let output = std::process::Command::new("rustc") - .arg("-vV") - .output() - .expect("Failed to get actual rustc verbose version"); - assert_eq!( - fingerprint.rustc_vv, - (String::from_utf8_lossy(&output.stdout).as_ref()) - ); - - // As the test shows above. Now we have generated the `doc/` folder and inside - // the rustdoc fingerprint file is located with the correct rustc version. - // So we will remove it and create a new fingerprint with an old rustc version - // inside it. We will also place a bogus file inside of the `doc/` folder to ensure - // it gets removed as we expect on the next doc compilation. - dummy_project.change_file( - "target/.rustdoc_fingerprint.json", - &old_rustc_verbose_version, - ); - - fs::write( - dummy_project - .build_dir() - .join("x86_64-unknown-linux-gnu/doc/bogus_file"), - String::from("This is a bogus file and should be removed!"), - ) - .expect("Error writing test bogus file"); - - // Now if we trigger another compilation, since the fingerprint contains an old version - // of rustc, cargo should remove the entire `/doc` folder (including the fingerprint) - // and generating another one with the actual version. - // It should also remove the bogus file we created above. - dummy_project - .cargo("doc --target x86_64-unknown-linux-gnu") - .run(); - - assert!(!dummy_project - .build_dir() - .join("x86_64-unknown-linux-gnu/doc/bogus_file") - .exists()); - - let fingerprint: RustDocFingerprint = - serde_json::from_str(&dummy_project.read_file("target/.rustdoc_fingerprint.json")) - .expect("JSON Serde fail"); - - // Check that the fingerprint contains the actual rustc version - // which has been used to compile the docs. - assert_eq!( - fingerprint.rustc_vv, - (String::from_utf8_lossy(&output.stdout).as_ref()) - ); -} From e6685527db212824fe2b507ee774c946bd8bdf91 Mon Sep 17 00:00:00 2001 From: bors Date: Wed, 31 Mar 2021 21:21:15 +0000 Subject: [PATCH 2/3] Auto merge of #9316 - ehuss:fix-semver-1.51, r=alexcrichton Fix semver docs for 1.51. 1.51 slightly changed the text of a few error messages. This should get CI passing again. --- src/doc/src/reference/semver.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/src/reference/semver.md b/src/doc/src/reference/semver.md index 2e5009c4e89..97dbead9e62 100644 --- a/src/doc/src/reference/semver.md +++ b/src/doc/src/reference/semver.md @@ -634,7 +634,7 @@ pub trait Trait {} use updated_crate::Trait; struct Foo; -impl Trait for Foo {} // Error: wrong number of type arguments +impl Trait for Foo {} // Error: missing generics ``` Mitigating strategies: @@ -943,7 +943,7 @@ pub fn foo() {} use updated_crate::foo; fn main() { - foo::(); // Error: wrong number of type arguments + foo::(); // Error: this function takes 2 type arguments but only 1 type argument was supplied } ``` From 6ce927a0d2982366fb44987ebfe94e399748319f Mon Sep 17 00:00:00 2001 From: bors Date: Fri, 26 Mar 2021 16:59:39 +0000 Subject: [PATCH 3/3] Auto merge of #9307 - ijackson:exit-code-string, r=joshtriplett tests: Tolerate "exit status" in error messages "exit code" is wrong terminology on Unix. I am trying to fix this in Rust stdlib in https://github.com/rust-lang/rust/pull/83462 but this currently breaks the cargo test suite. See that MR for full explanation of the change. --- tests/testsuite/build_script.rs | 2 +- tests/testsuite/run.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 89b38810aeb..8d9011d53d2 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -38,7 +38,7 @@ fn custom_build_script_failed() { [ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])` Caused by: - process didn't exit successfully: `[..]/build-script-build` (exit code: 101)", + process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)", ) .run(); } diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 9d52afaf7b0..1614b2a29c5 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -118,7 +118,7 @@ fn exit_code() { ); if !cfg!(unix) { output.push_str( - "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)", + "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)", ); } p.cargo("run").with_status(2).with_stderr(output).run(); @@ -140,7 +140,7 @@ fn exit_code_verbose() { ); if !cfg!(unix) { output.push_str( - "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit code: 2)", + "[ERROR] process didn't exit successfully: `target[..]foo[..]` (exit [..]: 2)", ); }