Source: gmt
Version: 5.2.1+dfsg-5
Severity: wishlist
Tags: patch upstream
User: reproducible-builds@lists.alioth.debian.org
Usertags: timestamps
X-Debbugs-Cc: reproducible-builds@lists.alioth.debian.org

Dear Maintainer,

While working on the `€œreproducible builds'€ effort [1], we have noticed
that 'gmt' could not be built reproducibly.

The attached patch honours the SOURCE_DATE_EPOCH environment
variable [2] to get a reproducible build date from the last
debian changelog entry.
Once applied, gmt can be built reproducibly in our current
experimental framework.

Regards,
Alexis Bienvenüe.

 [1]: https://wiki.debian.org/ReproducibleBuilds
 [2]: https://reproducible-builds.org/specs/source-date-epoch/

Description: Honour SOURCE_DATE_EPOCH
 Honour the SOURCE_DATE_EPOCH environment variable to set the sources
 last modification date.
 See https://reproducible-builds.org/specs/source-date-epoch/
Author: Alexis Bienvenüe <p...@passoire.fr>

Index: gmt-5.2.1+dfsg/cmake/modules/today.c
===================================================================
--- gmt-5.2.1+dfsg.orig/cmake/modules/today.c
+++ gmt-5.2.1+dfsg/cmake/modules/today.c
@@ -5,18 +5,32 @@
 
 #include <stdio.h>
 #include <time.h>
+#include <stdlib.h>
 
 #define BUFSIZE 32
 
 int main () {
 	char today_string[BUFSIZE];
 
-	/* obtain current time as time since epoch */
-	time_t clock = time (NULL);
-
-	/* convert time since epoch to calendar time expressed as local time */
-	struct tm *p_time = localtime (&clock);
+	time_t clock;
+        struct tm *p_time;
 
+        /* See https://reproducible-builds.org/specs/source-date-epoch/ */
+        char* source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+        if(source_date_epoch) {
+          /* get sources last modification date from environment */
+          clock = strtoull(source_date_epoch, NULL, 10);
+
+          /* Use UTC for reproducibility */
+          p_time = gmtime (&clock);
+        } else {
+          /* obtain current time as time since epoch */
+          clock = time (NULL);
+
+          /* convert time since epoch to calendar time expressed as local time */
+          p_time = localtime (&clock);
+        }
+        
 	/* convert tm object to custom textual representation YYYY;mm;dd;Mmm*/
 	size_t result = strftime(today_string, BUFSIZE, "%Y;%m;%d;%B", p_time);
 
_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to