Skip to content

Commit

Permalink
Put the zip in OUT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jun 7, 2024
1 parent f6c451c commit 6c7a33c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,3 @@ cython_debug/
!crates/ruff_python_resolver/resources/test/airflow/venv/lib
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/_watchdog_fsevents.cpython-311-darwin.so
!crates/ruff_python_resolver/resources/test/airflow/venv/lib/python3.11/site-packages/orjson/orjson.cpython-311-darwin.so

# Ignore the zipped version of typeshed that we create at build time
crates/red_knot/vendor/zipped_typeshed.zip
17 changes: 12 additions & 5 deletions crates/red_knot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use zip::write::{FileOptions, ZipWriter};
use zip::CompressionMethod;

const TYPESHED_SOURCE_DIR: &str = "vendor/typeshed";

// NB: This is .gitignored; make sure to change the .gitignore entry
// if you change this location
const TYPESHED_ZIP_LOCATION: &str = "vendor/zipped_typeshed.zip";
const TYPESHED_ZIP_LOCATION: &str = "zipped_typeshed.zip";

/// Recursively zip the contents of an entire directory.
///
Expand Down Expand Up @@ -61,6 +58,16 @@ fn main() {
Path::new(TYPESHED_SOURCE_DIR).is_dir(),
"Where is typeshed?"
);
let zipped_typeshed = File::create(Path::new(TYPESHED_ZIP_LOCATION)).unwrap();
let out_dir = std::env::var("OUT_DIR").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_ZIP_LOCATION}");

let zipped_typeshed = File::create(zipped_typeshed_location).unwrap();
zip_dir(TYPESHED_SOURCE_DIR, zipped_typeshed).unwrap();
}
3 changes: 2 additions & 1 deletion crates/red_knot/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,8 @@ mod tests {
fn typeshed_zip_created_at_build_time() -> anyhow::Result<()> {
// 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!("../vendor/zipped_typeshed.zip");
const TYPESHED_ZIP_BYTES: &[u8] =
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))?;

Expand Down

0 comments on commit 6c7a33c

Please sign in to comment.