From a5f2bcb95ff6113ac3c68466530505e2cb217971 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 7 Jun 2024 15:53:01 +0100 Subject: [PATCH] Revert "Set the location of the zip via environment variable" This reverts commit c5ad832102cc9cd16da3c8035c0fb9d413da6890. --- .cargo/config.toml | 6 ------ crates/red_knot/build.rs | 6 ++---- crates/red_knot/src/module.rs | 5 +++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 535e2bb0447d0..f7d8e616f8622 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -8,9 +8,3 @@ benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --" # See: https://github.com/astral-sh/ruff/issues/11503 [target.'cfg(all(target_env="msvc", target_os = "windows"))'] rustflags = ["-C", "target-feature=+crt-static"] - -[env] -# Location for where to put the zip containing our vendored typeshed stubs -# that the red-knot crate creates at build time. -# The location is relative to the `OUT_DIR` environment variable that cargo sets. -RUFF_VENDORED_TYPESHED_ZIP = "/vendored_typeshed.zip" diff --git a/crates/red_knot/build.rs b/crates/red_knot/build.rs index 652882d1d8888..8c2449de3ae0e 100644 --- a/crates/red_knot/build.rs +++ b/crates/red_knot/build.rs @@ -13,6 +13,7 @@ use zip::write::{FileOptions, ZipWriter}; use zip::CompressionMethod; const TYPESHED_SOURCE_DIR: &str = "vendor/typeshed"; +const TYPESHED_ZIP_LOCATION: &str = "zipped_typeshed.zip"; /// Recursively zip the contents of an entire directory. /// @@ -59,16 +60,13 @@ fn main() { ); let out_dir = std::env::var("OUT_DIR").unwrap(); - // This environment variable is set in `.cargo/config.toml` - let typeshed_destination = std::env::var("RUFF_VENDORED_TYPESHED_ZIP").unwrap(); - // N.B. Deliberately using `format!()` instead of `Path::join()` here, // so that we use `/` as a path separator on all platforms. // That enables us to load the typeshed zip at compile time in `module.rs` // (otherwise we'd have to dynamically determine the exact path to the typeshed zip // based on the default path separator for the specific platform we're on, // which can't be done at compile time.) - let zipped_typeshed_location = format!("{out_dir}{typeshed_destination}"); + let zipped_typeshed_location = format!("{out_dir}/{TYPESHED_ZIP_LOCATION}"); let zipped_typeshed = File::create(zipped_typeshed_location).unwrap(); zip_dir(TYPESHED_SOURCE_DIR, zipped_typeshed).unwrap(); diff --git a/crates/red_knot/src/module.rs b/crates/red_knot/src/module.rs index 35c3b16ab9b3f..9050aaebbf112 100644 --- a/crates/red_knot/src/module.rs +++ b/crates/red_knot/src/module.rs @@ -928,9 +928,10 @@ mod tests { #[test] fn typeshed_zip_created_at_build_time() -> anyhow::Result<()> { - // The RUFF_VENDORED_TYPESHED_ZIP environment variable is set in `.cargo/config.toml` + // The file path here is hardcoded in this crate's `build.rs` script. + // Luckily this crate will fail to build if this file isn't available at build time. const TYPESHED_ZIP_BYTES: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), env!("RUFF_VENDORED_TYPESHED_ZIP"))); + include_bytes!(concat!(env!("OUT_DIR"), "/zipped_typeshed.zip")); assert!(!TYPESHED_ZIP_BYTES.is_empty()); let mut typeshed_zip_archive = ZipArchive::new(Cursor::new(TYPESHED_ZIP_BYTES))?;