mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-06-05 23:18:55 +00:00
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
This commit is contained in:
parent
b75ee8d705
commit
1330763b36
2 changed files with 11 additions and 6 deletions
|
@ -12,4 +12,4 @@ keywords = ["gstreamer", "multimedia", "cargo"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4.19", default-features = false, features = ["std"] }
|
chrono = { version = "0.4.19", default-features = false, features = ["std", "clock"] }
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
mod git;
|
mod git;
|
||||||
|
|
||||||
use chrono::TimeZone;
|
use chrono::{Datelike, TimeZone};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{env, fs, path};
|
use std::{env, fs, path};
|
||||||
|
@ -68,15 +68,15 @@ pub fn info() {
|
||||||
// If there is a git repository, extract the version information from there.
|
// 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.
|
// Otherwise assume this is a release and use Cargo.toml mtime as date.
|
||||||
let (commit_id, commit_date) = git_info.unwrap_or_else(|| {
|
let (commit_id, commit_date) = git_info.unwrap_or_else(|| {
|
||||||
let date = cargo_mtime_date(crate_dir).expect("Failed to get Cargo.toml mtime");
|
let date = cargo_mtime_date(crate_dir).unwrap_or_else(chrono::Utc::now);
|
||||||
("RELEASE".into(), date)
|
("RELEASE".into(), date.format("%Y-%m-%d").to_string())
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("cargo:rustc-env=COMMIT_ID={}", commit_id);
|
println!("cargo:rustc-env=COMMIT_ID={}", commit_id);
|
||||||
println!("cargo:rustc-env=BUILD_REL_DATE={}", commit_date);
|
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;
|
let mut cargo_toml = crate_dir;
|
||||||
cargo_toml.push("Cargo.toml");
|
cargo_toml.push("Cargo.toml");
|
||||||
|
|
||||||
|
@ -85,5 +85,10 @@ fn cargo_mtime_date(crate_dir: path::PathBuf) -> Option<String> {
|
||||||
let unix_time = mtime.duration_since(SystemTime::UNIX_EPOCH).ok()?;
|
let unix_time = mtime.duration_since(SystemTime::UNIX_EPOCH).ok()?;
|
||||||
let dt = chrono::Utc.timestamp(unix_time.as_secs().try_into().ok()?, 0);
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue