From 31fdc2ec09880d6bb3b495415a15e45137ce2922 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 18 Jul 2024 11:08:43 +0200 Subject: [PATCH] Lintcheck: Remove `rust-toolchain` from downloaded crates --- lintcheck/src/input.rs | 16 +++++++++++++++- lintcheck/src/main.rs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lintcheck/src/input.rs b/lintcheck/src/input.rs index 5aa261d7f6d..7a0cf26ca32 100644 --- a/lintcheck/src/input.rs +++ b/lintcheck/src/input.rs @@ -159,11 +159,25 @@ pub fn read_crates(toml_path: &Path) -> (Vec, RecursiveOptions) } impl CrateWithSource { + pub fn download_and_prepare(&self) -> Crate { + let krate = self.download_and_extract(); + + // Downloaded crates might contain a `rust-toolchain` file. This file + // seems to be accessed when `build.rs` files are present. This access + // results in build errors since lintcheck and clippy will most certainly + // use a different toolchain. + // Lintcheck simply removes these files and assumes that our toolchain + // is more up to date. + let _ = fs::remove_file(krate.path.join("rust-toolchain")); + let _ = fs::remove_file(krate.path.join("rust-toolchain.toml")); + + krate + } /// Makes the sources available on the disk for clippy to check. /// Clones a git repo and checks out the specified commit or downloads a crate from crates.io or /// copies a local folder #[expect(clippy::too_many_lines)] - pub fn download_and_extract(&self) -> Crate { + fn download_and_extract(&self) -> Crate { #[allow(clippy::result_large_err)] fn get(path: &str) -> Result { const MAX_RETRIES: u8 = 4; diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index ba4ced4e469..d00b2fc7bc8 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -298,7 +298,7 @@ fn lintcheck(config: LintcheckConfig) { true } }) - .map(|krate| krate.download_and_extract()) + .map(|krate| krate.download_and_prepare()) .collect(); if crates.is_empty() {