summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard M. Wiedemann <bwiedemann@suse.de>2024-07-24 16:28:43 +0200
committerMarge Bot <emma+marge@anholt.net>2024-08-06 01:17:01 +0000
commit2a6a5574001d7a9959ba4d924522b96f8cc57b43 (patch)
tree7c7606eabc6aae2df604be50d9aea92d978b3c27
parent5fb8b61537b832561f074a6d400956c8cb6b31a5 (diff)
Allow to override build date with SOURCE_DATE_EPOCH
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, sponsored by the NLnet NGI0 fund. Part-of: <https://gitlab.freedesktop.org/xorg/app/fonttosfnt/-/merge_requests/22>
-rw-r--r--util.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/util.c b/util.c
index a810c87..a7207f8 100644
--- a/util.c
+++ b/util.c
@@ -182,6 +182,7 @@ int
macTime(int *hi, unsigned *lo)
{
unsigned long long diff; /* Not time_t */
+ char *source_date_epoch;
time_t macEpoch, current;
struct tm tm;
tm.tm_sec = 0;
@@ -195,7 +196,11 @@ macTime(int *hi, unsigned *lo)
macEpoch = mktime_gmt(&tm);
if(macEpoch == -1) return -1;
- current = time(NULL);
+ /* This assumes that the SOURCE_DATE_EPOCH environment variable will contain
+ a correct, positive integer in the time_t range */
+ if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
+ (current = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0)
+ current = time(NULL);
if(current == -1)
return -1;