-
-
Notifications
You must be signed in to change notification settings - Fork 398
Calculate file options for WheelWriter once and cache the result #2865
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ use std::io; | |
| use std::path::{Path, PathBuf}; | ||
| use std::str::FromStr; | ||
| use tracing::instrument; | ||
| use zip::DateTime; | ||
|
|
||
| /// Insert wasm launcher scripts as entrypoints and the wasmtime dependency | ||
| fn bin_wasi_helper( | ||
|
|
@@ -752,14 +753,18 @@ impl BuildContext { | |
| let platform = self.get_platform_tag(platform_tags)?; | ||
| let tag = format!("cp{major}{min_minor}-abi3-{platform}"); | ||
|
|
||
| let file_options = self | ||
| .compression | ||
| .get_file_options() | ||
| .last_modified_time(zip_mtime()); | ||
| let mut writer = WheelWriter::new( | ||
| &tag, | ||
| &self.out, | ||
| &self.project_layout.project_root, | ||
| &self.metadata24, | ||
| std::slice::from_ref(&tag), | ||
| self.excludes(Format::Wheel)?, | ||
| self.compression, | ||
| file_options, | ||
| )?; | ||
| self.add_external_libs(&mut writer, &[&artifact], &[ext_libs])?; | ||
|
|
||
|
|
@@ -831,14 +836,18 @@ impl BuildContext { | |
| ) -> Result<BuiltWheelMetadata> { | ||
| let tag = python_interpreter.get_tag(self, platform_tags)?; | ||
|
|
||
| let file_options = self | ||
| .compression | ||
| .get_file_options() | ||
| .last_modified_time(zip_mtime()); | ||
| let mut writer = WheelWriter::new( | ||
| &tag, | ||
| &self.out, | ||
| &self.project_layout.project_root, | ||
| &self.metadata24, | ||
| std::slice::from_ref(&tag), | ||
| self.excludes(Format::Wheel)?, | ||
| self.compression, | ||
| file_options, | ||
| )?; | ||
| self.add_external_libs(&mut writer, &[&artifact], &[ext_libs])?; | ||
|
|
||
|
|
@@ -955,14 +964,18 @@ impl BuildContext { | |
| ) -> Result<BuiltWheelMetadata> { | ||
| let (tag, tags) = self.get_universal_tags(platform_tags)?; | ||
|
|
||
| let file_options = self | ||
| .compression | ||
| .get_file_options() | ||
| .last_modified_time(zip_mtime()); | ||
| let mut writer = WheelWriter::new( | ||
| &tag, | ||
| &self.out, | ||
| &self.project_layout.project_root, | ||
| &self.metadata24, | ||
| &tags, | ||
| self.excludes(Format::Wheel)?, | ||
| self.compression, | ||
| file_options, | ||
| )?; | ||
| self.add_external_libs(&mut writer, &[&artifact], &[ext_libs])?; | ||
|
|
||
|
|
@@ -1028,14 +1041,18 @@ impl BuildContext { | |
| ) -> Result<BuiltWheelMetadata> { | ||
| let (tag, tags) = self.get_universal_tags(platform_tags)?; | ||
|
|
||
| let file_options = self | ||
| .compression | ||
| .get_file_options() | ||
| .last_modified_time(zip_mtime()); | ||
| let mut writer = WheelWriter::new( | ||
| &tag, | ||
| &self.out, | ||
| &self.project_layout.project_root, | ||
| &self.metadata24, | ||
| &tags, | ||
| self.excludes(Format::Wheel)?, | ||
| self.compression, | ||
| file_options, | ||
| )?; | ||
| self.add_external_libs(&mut writer, &[&artifact], &[ext_libs])?; | ||
|
|
||
|
|
@@ -1128,14 +1145,18 @@ impl BuildContext { | |
| self.metadata24.clone() | ||
| }; | ||
|
|
||
| let file_options = self | ||
| .compression | ||
| .get_file_options() | ||
| .last_modified_time(zip_mtime()); | ||
| let mut writer = WheelWriter::new( | ||
| &tag, | ||
| &self.out, | ||
| &self.project_layout.project_root, | ||
| &metadata24, | ||
| &tags, | ||
| self.excludes(Format::Wheel)?, | ||
| self.compression, | ||
| file_options, | ||
| )?; | ||
|
|
||
| if self.project_layout.python_module.is_some() && self.target.is_wasi() { | ||
|
|
@@ -1396,6 +1417,21 @@ fn emcc_version() -> Result<String> { | |
| Ok(trimmed.into()) | ||
| } | ||
|
|
||
| /// Returns a DateTime representing the value SOURCE_DATE_EPOCH environment variable | ||
| /// Note that the earliest timestamp a zip file can represent is 1980-01-01 | ||
| fn zip_mtime() -> DateTime { | ||
| let res = env::var("SOURCE_DATE_EPOCH") | ||
| .context("") // Only using context() to unify the error types | ||
| .and_then(|epoch| { | ||
| let epoch: i64 = epoch.parse()?; | ||
| let dt = time::OffsetDateTime::from_unix_timestamp(epoch)?; | ||
| let dt = DateTime::try_from(dt)?; | ||
| Ok(dt) | ||
| }); | ||
|
|
||
| res.unwrap_or_default() | ||
| } | ||
|
Comment on lines
+1422
to
+1433
|
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{iphoneos_deployment_target, macosx_deployment_target}; | ||
|
|
||
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.
[nitpick] The empty context string
context("")is unusual and appears to be used solely to unify error types. Consider using a more descriptive error message or using.ok()followed by.and_then()to avoid needing a context at all.For example:
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.
I'm not convinced that writing
.ok()?everywhere is better than just?but the code does the same thing either way so 🤷