From f56844501e12b11a112a986dda9ab06c39cf60a3 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Thu, 16 May 2024 17:17:58 +0200 Subject: [PATCH] Allow to override build date with SOURCE_DATE_EPOCH (#2202) to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. This patch was done while working on reproducible builds for openSUSE. --------- Co-authored-by: extrawurst --- CHANGELOG.md | 3 +++ build.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b124b554..a5f887c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * respect configuration for remote when fetching (also applies to pulling) [[@cruessler](https://github.com/cruessler)] ([#1093](https://github.com/extrawurst/gitui/issues/1093)) * add `:` character to sign-off trailer to comply with Conventinoal Commits standard [@semioticrobotic](https://github.com/semioticrobotic) ([#2196](https://github.com/extrawurst/gitui/issues/2196)) +### Added +* support overriding `build_date` for [reproducible builds](https://reproducible-builds.org/) [[@bmwiedemann](https://github.com/bmwiedemann)] ([#2202](https://github.com/extrawurst/gitui/pull/2202)) + ## [0.26.0+1] - 2024-04-14 **0.26.1** diff --git a/build.rs b/build.rs index 64470c19..e217973c 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +use chrono::TimeZone; + fn get_git_hash() -> String { use std::process::Command; @@ -18,7 +20,13 @@ fn get_git_hash() -> String { } fn main() { - let build_date = chrono::Local::now().date_naive(); + let now = match std::env::var("SOURCE_DATE_EPOCH") { + Ok(val) => chrono::Local + .timestamp_opt(val.parse::().unwrap(), 0) + .unwrap(), + Err(_) => chrono::Local::now(), + }; + let build_date = now.date_naive(); let build_name = if std::env::var("GITUI_RELEASE").is_ok() { format!(