[libgda: 1/2] Allow to override build date with SOURCE_DATE_EPOCH




commit c9837a3438622d49fe6a727d2512e0f0bb3827d7
Author: Bernhard M. Wiedemann <bwiedemann suse de>
Date:   Wed Feb 2 14:25:57 2022 +0100

    Allow to override build date with SOURCE_DATE_EPOCH
    
    in order 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.
    
    Also use UTC to be independent of timezone.

 meson.build | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 62b465941..bc4cecace 100644
--- a/meson.build
+++ b/meson.build
@@ -321,10 +321,18 @@ found_jdbc = false
 dates = compiler.run('''
 #include<glib.h>
 #include <glib/gprintf.h>
+#include <stdlib.h>
 
 void main (void) {
   GDateTime *dt;
-  dt = g_date_time_new_now_local ();
+  char *source_date_epoch;
+  gint64 epoch;
+  /* This assumes that the SOURCE_DATE_EPOCH environment variable will contain
+     a correct, positive integer */
+  if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
+    (epoch = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0 ||
+    (dt = g_date_time_new_from_unix_utc(epoch)) == NULL)
+       dt = g_date_time_new_now_utc ();
   g_print (g_date_time_format(dt, "%F"));
 }
 ''',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]