package: honor SOURCE_DATE_EPOCH

For projects supporting reproducible builds, it's possible to set the
timestamp used in artifacts by setting SOURCE_DATE_EPOCH to a decimal
Unix timestamp.  This is helpful because it allows users to produce the
exact same artifact, regardless of when the project was built, and it
also means that services which generate crates from source can generate
a consistent crate without having store previously built artifacts.

For all these reasons, let's honor the SOURCE_DATE_EPOCH environment
variable if it's set and use the current timestamp if it's not.
This commit is contained in:
brian m. carlson 2020-11-15 21:38:26 +00:00
parent 9cc7ac618b
commit 436b9eb85d
No known key found for this signature in database
GPG Key ID: 7C0C49628887A281

View File

@ -473,6 +473,11 @@ fn check_repo_state(
}
fn timestamp() -> u64 {
if let Ok(var) = std::env::var("SOURCE_DATE_EPOCH") {
if let Ok(stamp) = var.parse() {
return stamp;
}
}
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()