From 25ff699d2b600fc9a3730ca5c777f122379be1b8 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Thu, 24 Nov 2022 23:52:26 +0800 Subject: [PATCH 1/2] * fix file name * add test check --- Cargo.toml | 3 +++ src/{data_time.rs => date_time.rs} | 13 ++++++++++--- src/env.rs | 4 ++-- src/git.rs | 2 +- src/lib.rs | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) rename src/{data_time.rs => date_time.rs} (92%) diff --git a/Cargo.toml b/Cargo.toml index 60db506..27b6aa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,5 +36,8 @@ document-features = { version = "0.2", optional = true } [features] default = ["git2", "tzdb"] +[dev-dependencies] +regex = "1.7.0" + [workspace] members = ["example_shadow", "example_shadow_hook"] diff --git a/src/data_time.rs b/src/date_time.rs similarity index 92% rename from src/data_time.rs rename to src/date_time.rs index c3fc046..d8a55cc 100644 --- a/src/data_time.rs +++ b/src/date_time.rs @@ -12,8 +12,8 @@ pub enum DateTime { Utc(OffsetDateTime), } -pub fn now_data_time() -> DateTime { - // Enable reproducibility for uses of `now_data_time` by respecting the +pub fn now_date_time() -> DateTime { + // Enable reproducibility for uses of `now_date_time` by respecting the // `SOURCE_DATE_EPOCH` env variable. // // https://reproducible-builds.org/docs/source-date-epoch/ @@ -114,11 +114,12 @@ impl Format for OffsetDateTime { #[cfg(test)] mod tests { use super::*; + use regex::Regex; #[test] fn test_source_date_epoch() { std::env::set_var("SOURCE_DATE_EPOCH", "1628080443"); - let time = now_data_time(); + let time = now_date_time(); assert_eq!(time.human_format(), "2021-08-04 12:34:03 +00:00"); } @@ -128,6 +129,12 @@ mod tests { #[cfg(unix)] assert!(!std::fs::read("/etc/localtime").unwrap().is_empty()); + let regex = Regex::new( + r#"^[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\s[+][0-9]{2}:[0-9]{2}"#, + ) + .unwrap(); + assert!(regex.is_match(&time)); + println!("local now:{}", time); // 2022-07-14 00:40:05 +08:00 assert_eq!(time.len(), 26); } diff --git a/src/env.rs b/src/env.rs index c4a5e4d..675253c 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,5 +1,5 @@ use crate::build::*; -use crate::data_time::now_data_time; +use crate::date_time::now_date_time; use crate::env::dep_source_replace::filter_cargo_tree; use crate::err::SdResult; use crate::Format; @@ -282,7 +282,7 @@ const BUILD_RUST_CHANNEL: ShadowConst = "BUILD_RUST_CHANNEL"; pub fn build_time(project: &mut Project) { // Enable reproducible builds: https://reproducible-builds.org/docs/source-date-epoch/ - let time = now_data_time(); + let time = now_date_time(); project.map.insert( BUILD_TIME, ConstVal { diff --git a/src/git.rs b/src/git.rs index bd9273c..7ce1e5d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,6 +1,6 @@ use crate::build::{ConstType, ConstVal, ShadowConst}; use crate::ci::CiType; -use crate::data_time::DateTime; +use crate::date_time::DateTime; use crate::err::*; use crate::Format; use std::collections::BTreeMap; diff --git a/src/lib.rs b/src/lib.rs index dae9bd7..f895348 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,7 @@ mod build; mod ci; -mod data_time; +mod date_time; mod env; mod err; mod gen_const; @@ -167,7 +167,7 @@ use env::*; use git::*; use crate::ci::CiType; -pub use crate::data_time::DateTime; +pub use crate::date_time::DateTime; pub use const_format::*; use std::collections::BTreeMap; use std::env as std_env; From 5c4eae9a115fb8b398828312c27b7a959eb520b5 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Thu, 24 Nov 2022 23:57:50 +0800 Subject: [PATCH 2/2] bump shadow-rs version #0.18.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0c2243d..66390cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadow-rs" -version = "0.17.1" +version = "0.18.0" authors = ["baoyachi "] edition = "2021" description = "A build-time information stored in your rust project"