-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Windows trampolines for compatibility with Python 3.7 and earlier #8649
Open
nahco314
wants to merge
1
commit into
astral-sh:main
Choose a base branch
from
nahco314:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,11 +87,12 @@ fn push_quoted_path(path: &Path, command: &mut Vec<u8>) { | |
} | ||
|
||
/// Reads the executable binary from the back to find the path to the Python executable that is written | ||
/// after the ZIP file content. | ||
/// before the ZIP file content. | ||
/// | ||
/// The executable is expected to have the following format: | ||
/// * The file must end with the magic number 'UVUV'. | ||
/// * The last 4 bytes (little endian) are the length of the path to the Python executable. | ||
/// * The last part of the file is ZIP file content. | ||
/// * The remain part must end with the magic number 'UVUV'. | ||
/// * The last 4 bytes (little endian) before 'UVUV' are the length of the path to the Python executable. | ||
/// * The path encoded as UTF-8 comes right before the length | ||
/// | ||
/// # Panics | ||
|
@@ -112,6 +113,45 @@ fn find_python_exe(executable_name: &Path) -> PathBuf { | |
}); | ||
let file_size = metadata.len(); | ||
|
||
// Read the entire end of central directory (EOCD) of the ZIP file, which is 22 bytes long. | ||
let mut eocd_buf: Vec<u8> = vec![0; 22]; | ||
|
||
file_handle | ||
.seek(SeekFrom::Start(file_size - 22)) | ||
.unwrap_or_else(|_| { | ||
print_last_error_and_exit("Failed to set the file pointer to the start of zip EOCD"); | ||
}); | ||
|
||
let read_bytes = file_handle.read(&mut eocd_buf).unwrap_or_else(|_| { | ||
print_last_error_and_exit("Failed to read the zip EOCD"); | ||
}); | ||
|
||
if read_bytes != 22 { | ||
eprintln!( | ||
"Failed to read the EOCD. Expected 22 bytes but read {}", | ||
read_bytes | ||
); | ||
exit_with_status(1); | ||
} | ||
|
||
// Size of the central directory (in bytes) | ||
let cd_size = u32::from_le_bytes(eocd_buf[12..16].try_into().unwrap_or_else(|_| { | ||
eprintln!("Slice length is not equal to 4 bytes"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be |
||
exit_with_status(1); | ||
})); | ||
|
||
// Offset of central directory (unit is bytes). | ||
// In other words, the number of bytes in the ZIP file at which the central directory starts. | ||
let cd_offset = u32::from_le_bytes(eocd_buf[16..20].try_into().unwrap_or_else(|_| { | ||
eprintln!("Slice length is not equal to 4 bytes"); | ||
exit_with_status(1); | ||
})); | ||
|
||
// Calculate the position in the entire executable where the content of the ZIP file begins. | ||
let end_of_cd = file_size - 22; | ||
let start_of_cd = end_of_cd - cd_size as u64; | ||
let start_of_zip = start_of_cd - cd_offset as u64; | ||
|
||
// Start with a size of 1024 bytes which should be enough for most paths but avoids reading the | ||
// entire file. | ||
let mut buffer: Vec<u8> = Vec::new(); | ||
|
@@ -122,7 +162,7 @@ fn find_python_exe(executable_name: &Path) -> PathBuf { | |
buffer.resize(bytes_to_read as usize, 0); | ||
|
||
file_handle | ||
.seek(SeekFrom::Start(file_size - u64::from(bytes_to_read))) | ||
.seek(SeekFrom::Start(start_of_zip - u64::from(bytes_to_read))) | ||
.unwrap_or_else(|_| { | ||
print_last_error_and_exit("Failed to set the file pointer to the end of the file"); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+512 Bytes
(100%)
crates/uv-trampoline/trampolines/uv-trampoline-aarch64-console.exe
Binary file not shown.
Binary file modified
BIN
+512 Bytes
(100%)
crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe
Binary file not shown.
Binary file modified
BIN
+1.5 KB
(100%)
crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+1 KB
(100%)
crates/uv-trampoline/trampolines/uv-trampoline-x86_64-console.exe
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use https://doc.rust-lang.org/std/io/trait.Read.html#method.read_exact instead?