diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2022-01-12 13:17:22 +0300 |
---|---|---|
committer | Sebastian Dröge <slomo@coaxion.net> | 2022-01-12 13:39:54 +0300 |
commit | a07edc7cf457b0245798464f34abc8a61a8d6666 (patch) | |
tree | c48c56920dbf6686a881fa4a9a867ebc9ea41f57 /version-helper | |
parent | 4576bea10c2838b1ea47bd525ae77efe7fb4f9ea (diff) |
gst-plugin-version-helper: Work around broken file times in crates from crates.io
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/177
Diffstat (limited to 'version-helper')
-rw-r--r-- | version-helper/Cargo.toml | 2 | ||||
-rw-r--r-- | version-helper/src/lib.rs | 16 |
2 files changed, 12 insertions, 6 deletions
diff --git a/version-helper/Cargo.toml b/version-helper/Cargo.toml index 6ab41bf1..a6fd362a 100644 --- a/version-helper/Cargo.toml +++ b/version-helper/Cargo.toml @@ -13,4 +13,4 @@ edition = "2021" rust-version = "1.56" [dependencies] -chrono = { version = "0.4.19", default-features = false, features = ["std"] } +chrono = { version = "0.4.19", default-features = false, features = ["std", "clock"] } diff --git a/version-helper/src/lib.rs b/version-helper/src/lib.rs index a9abe1bb..6698f6a8 100644 --- a/version-helper/src/lib.rs +++ b/version-helper/src/lib.rs @@ -32,7 +32,8 @@ mod git; -use chrono::TimeZone; +use chrono::{Datelike, TimeZone}; +use std::convert::TryInto; use std::time::SystemTime; use std::{env, fs, path}; @@ -67,15 +68,15 @@ pub fn info() { // If there is a git repository, extract the version information from there. // Otherwise assume this is a release and use Cargo.toml mtime as date. let (commit_id, commit_date) = git_info.unwrap_or_else(|| { - let date = cargo_mtime_date(crate_dir).expect("Failed to get Cargo.toml mtime"); - ("RELEASE".into(), date) + let date = cargo_mtime_date(crate_dir).unwrap_or_else(chrono::Utc::now); + ("RELEASE".into(), date.format("%Y-%m-%d").to_string()) }); println!("cargo:rustc-env=COMMIT_ID={}", commit_id); println!("cargo:rustc-env=BUILD_REL_DATE={}", commit_date); } -fn cargo_mtime_date(crate_dir: path::PathBuf) -> Option<String> { +fn cargo_mtime_date(crate_dir: path::PathBuf) -> Option<chrono::DateTime<chrono::Utc>> { let mut cargo_toml = crate_dir; cargo_toml.push("Cargo.toml"); @@ -84,5 +85,10 @@ fn cargo_mtime_date(crate_dir: path::PathBuf) -> Option<String> { let unix_time = mtime.duration_since(SystemTime::UNIX_EPOCH).ok()?; let dt = chrono::Utc.timestamp(unix_time.as_secs().try_into().ok()?, 0); - Some(dt.format("%Y-%m-%d").to_string()) + // FIXME: Work around https://github.com/rust-lang/cargo/issues/10285 + if dt.date().year() < 2015 { + return None; + } + + Some(dt) } |