[Reproducible-commits] [ghostscript] 01/02: Add patch to allow build timestamp to be set through an environment variable

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Jan 23 11:10:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository ghostscript.

commit 4ee6f1ee500abb06a44b4aa66fb1e3a2ca075a35
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Fri Jan 23 11:55:08 2015 +0100

    Add patch to allow build timestamp to be set through an environment variable
    
    BUILD_TIMESTAMP can now be used to pass the build timestamp to Ghostscript.
    This is needed for reproducible builds.
---
 .../patches/2009_add_build_timestamp_setting.patch | 106 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 2 files changed, 107 insertions(+)

diff --git a/debian/patches/2009_add_build_timestamp_setting.patch b/debian/patches/2009_add_build_timestamp_setting.patch
new file mode 100644
index 0000000..c45769f
--- /dev/null
+++ b/debian/patches/2009_add_build_timestamp_setting.patch
@@ -0,0 +1,106 @@
+Description: Allow the build timestamp to be externally set
+ In order to make Ghostscript output reproducible, we need a way to
+ set the build timestamp to other values than the current time.
+ We now use consistently use gp_get_realtime() instead of directly calling
+ time() or gp_get_usertime() and make gp_get_realtime() use the value
+ found in the BUILD_TIMESTAMP environment variable if set.
+Author: Peter De Wachter <pdewacht at gmail.com>
+
+--- ghostscript-9.06~dfsg.orig/base/gdevpdf.c
++++ ghostscript-9.06~dfsg/base/gdevpdf.c
+@@ -285,11 +285,13 @@ pdf_initialize_ids(gx_device_pdf * pdev)
+     {
+         struct tm tms;
+         time_t t;
++        long secs_ns[2];
+         char buf[1+2+4+2+2+2+2+2+1+2+1+2+1+1+1]; /* (D:yyyymmddhhmmssZhh'mm')\0 */
+         int timeoffset;
+         char timesign;
+ 
+-        time(&t);
++        gp_get_realtime(secs_ns);
++        t = secs_ns[0];
+         tms = *gmtime(&t);
+         tms.tm_isdst = -1;
+         timeoffset = (int)difftime(t, mktime(&tms)); /* tz+dst in seconds */
+@@ -332,7 +334,7 @@ pdf_compute_fileID(gx_device_pdf * pdev)
+     if (s == NULL)
+         return_error(gs_error_VMerror);
+     pdev->KeyLength = 0; /* Disable encryption. Not so important though. */
+-    gp_get_usertime(secs_ns);
++    gp_get_realtime(secs_ns);
+     sputs(s, (byte *)secs_ns, sizeof(secs_ns), &ignore);
+     sputs(s, (const byte *)pdev->fname, strlen(pdev->fname), &ignore);
+     pdev->strm = s;
+--- ghostscript-9.06~dfsg.orig/base/gdevpdfe.c
++++ ghostscript-9.06~dfsg/base/gdevpdfe.c
+@@ -201,9 +201,11 @@ pdf_xmp_time(char *buf, int buf_length)
+     /* We don't write a day time because we don't have a time zone. */
+     struct tm tms;
+     time_t t;
++    long secs_ns[2];
+     char buf1[4+1+2+1+2+1]; /* yyyy-mm-dd\0 */
+ 
+-    time(&t);
++    gp_get_realtime(secs_ns);
++    t = secs_ns[0];
+     tms = *localtime(&t);
+     sprintf(buf1,
+             "%04d-%02d-%02d",
+--- ghostscript-9.06~dfsg.orig/base/gdevpsu.c
++++ ghostscript-9.06~dfsg/base/gdevpsu.c
+@@ -183,10 +183,12 @@ psw_begin_file_header(FILE *f, const gx_
+     fprintf(f, "%%%%Creator: %s %ld (%s)\n", gs_product, (long)gs_revision,
+             dev->dname);
+     {
++        long secs_ns[2];
+         time_t t;
+         struct tm tms;
+ 
+-        time(&t);
++        gp_get_realtime(secs_ns);
++        t = secs_ns[0];
+         tms = *localtime(&t);
+         fprintf(f, "%%%%CreationDate: %d/%02d/%02d %02d:%02d:%02d\n",
+                 tms.tm_year + 1900, tms.tm_mon + 1, tms.tm_mday,
+--- ghostscript-9.06~dfsg.orig/base/gp_unix.c
++++ ghostscript-9.06~dfsg/base/gp_unix.c
+@@ -16,6 +16,7 @@
+ 
+ /* Unix-specific routines for Ghostscript */
+ 
++#include "errno_.h"
+ #include "pipe_.h"
+ #include "string_.h"
+ #include "time_.h"
+@@ -145,6 +146,7 @@ void
+ gp_get_realtime(long *pdt)
+ {
+     struct timeval tp;
++    const char *env;
+ 
+ #if gettimeofday_no_timezone    /* older versions of SVR4 */
+     {
+@@ -164,6 +166,22 @@ gp_get_realtime(long *pdt)
+     }
+ #endif
+ 
++    env = getenv("DEB_BUILD_TIMESTAMP");
++    if (env) {
++        char *end;
++        long timestamp;
++
++        errno = 0;
++        timestamp = strtol(env, &end, 10);
++        if (env == end || *end || errno != 0) {
++            lprintf("Ghostscript: DEB_BUILD_TIMESTAMP is not a number!\n");
++            timestamp = 0;
++        }
++
++        tp.tv_sec = timestamp;
++        tp.tv_usec = 0;
++    }
++
+     /* tp.tv_sec is #secs since Jan 1, 1970 */
+     pdt[0] = tp.tv_sec;
+ 
diff --git a/debian/patches/series b/debian/patches/series
index f1a2181..7a96c29 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -12,3 +12,4 @@
 2006_suggest_install_ghostscript-doc_in_docs.patch
 2007_suggest_install_ghostscript-doc_in_code.patch
 2008_mention_ghostscript-x_in_docs.patch
+2009_add_build_timestamp_setting.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/ghostscript.git



More information about the Reproducible-commits mailing list