From ce437e9e7d0ec96dc64f1f2abc24f340a2ca74d0 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Fri, 15 Jul 2022 10:53:31 +0800 Subject: [PATCH 1/2] fix #100 --- Cargo.toml | 2 +- src/lib.rs | 4 +--- src/time.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 629e1b5..0dc0489 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadow-rs" -version = "0.13.0" +version = "0.13.1" authors = ["baoyachi "] edition = "2021" description = "A build-time information stored in your rust project" diff --git a/src/lib.rs b/src/lib.rs index c3d2f7a..8350b46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -371,9 +371,7 @@ impl Shadow { // Author by:https://www.github.com/baoyachi // The build script repository:https://github.com/baoyachi/shadow-rs // Create time by:{}"#, - BuildTime::local_now() - .map_err(|err| format!("get local DateTime error:{}", err))? - .human_format() + BuildTime::new().human_format() ); writeln!(&self.f, "{}\n\n", desc)?; Ok(()) diff --git a/src/time.rs b/src/time.rs index 427212f..05de6fc 100644 --- a/src/time.rs +++ b/src/time.rs @@ -18,7 +18,7 @@ pub fn now_data_time() -> BuildTime { // https://reproducible-builds.org/docs/source-date-epoch/ println!("cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH"); match std::env::var_os("SOURCE_DATE_EPOCH") { - None => BuildTime::local_now().unwrap(), + None => BuildTime::new(), Some(timestamp) => { let epoch = timestamp .into_string() @@ -32,7 +32,11 @@ pub fn now_data_time() -> BuildTime { } impl BuildTime { - pub fn local_now() -> Result> { + pub fn new() -> Self { + Self::local_now().unwrap_or_else(|_| BuildTime::Utc(OffsetDateTime::now_utc())) + } + + fn local_now() -> Result> { let time_zone_local = TimeZone::local()?; // expensive call, should be cached let duration_since_epoch = SystemTime::now().duration_since(UNIX_EPOCH)?; @@ -89,6 +93,9 @@ mod tests { #[test] fn test_local_now_human_format() { let time = BuildTime::local_now().unwrap().human_format(); + #[cfg(unix)] + assert!(!std::fs::read("/etc/localtime").unwrap().is_empty()); + println!("{}", time); // 2022-07-14 00:40:05 +08:00 assert_eq!(time.len(), 26); } From 3e49e593a2026ae0ea37e11c32934ae3fad896b5 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Fri, 15 Jul 2022 11:00:19 +0800 Subject: [PATCH 2/2] fix --- .github/workflows/check.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1297c05..0f5942d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -63,17 +63,18 @@ jobs: working-directory: ./example_shadow # build on nightly - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - - name: Build on nightly - run: cargo build --release +# - uses: actions-rs/toolchain@v1 +# with: +# toolchain: nightly +# override: true +# - name: Build on nightly +# run: cargo build --release test: strategy: matrix: - rust: [stable, beta, nightly] +# rust: [stable, beta, nightly] + rust: [stable, beta] runs-on: ubuntu-latest steps: - name: Setup Rust