Subject: [PATCH core-updates] gnu: ghostscript: Improve reproducibility of PDF document generation

From: Guillaume Le Vaillant <[email-masked]>
Date: Mon, 19 Jul 2021 11:45:07 +0000

Hi,

When trying to solve a reproducibility issue when generating the
PDF documentation of the txr software (see [1]), Paul Patience noticed
that ghostscript writes a creation date in the PDF even when the
GS_GENERATE_UUIDS environment variable is set to "0".

The attached patch updates 'ghostscript-no-header-creationdate.patch' to
fix this issue.

Given the amount of rebuilds caused by modifying ghostscript, this
should go to core-updates, but is core-updates in freeze state already,
or can I push this patch right now?

Note: Even with this patch, there are still some cases where PDF
generation by ghostscript is not reproducible (for reasons not related
to creation date), like groff-doc.

[1]: https://bugs.gnu.org/49517
From db5962c68099f835350c24c8a3f889b9fa1f8a8e Mon Sep 17 00:00:00 2001
From: Guillaume Le Vaillant <[email-masked]>
Date: Mon, 19 Jul 2021 11:48:12 +0200
Subject: [PATCH] gnu: ghostscript: Improve reproducibility of PDF document
 generation

* gnu/packages/patches/ghostscript-no-header-creationdate.patch: Disable
  writing "xmp:ModifyDate" and "xmp:CreateDate" if GS_GENERATE_UUIDS is set to
  "0" or "no".
---
 .../ghostscript-no-header-creationdate.patch  | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/gnu/packages/patches/ghostscript-no-header-creationdate.patch b/gnu/packages/patches/ghostscript-no-header-creationdate.patch
index 92ddbdade0..b19f3ab5d9 100644
--- a/gnu/packages/patches/ghostscript-no-header-creationdate.patch
+++ b/gnu/packages/patches/ghostscript-no-header-creationdate.patch
@@ -20,3 +20,25 @@ index 0fb067e..b342e2c 100644
      {
          struct tm tms;
          time_t t;
+--- orig/gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c
++++ gnu-ghostscript-9.14.0/devices/vector/gdevpdfe.c
+@@ -692,6 +692,9 @@
+             pdf_xml_attribute_name(s, "xmlns:xmp");
+             pdf_xml_attribute_value(s, "http://ns.adobe.com/xap/1.0/");
+             pdf_xml_tag_end(s);
++            if (!getenv("GS_GENERATE_UUIDS") ||
++                (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 &&
++                 strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))
+             {
+                 pdf_xml_tag_open_beg(s, "xmp:ModifyDate");
+                 pdf_xml_tag_end(s);
+@@ -700,6 +701,9 @@
+                 pdf_xml_tag_close(s, "xmp:ModifyDate");
+                 pdf_xml_newline(s);
+             }
++            if (!getenv("GS_GENERATE_UUIDS") ||
++                (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 &&
++                 strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))
+             {
+                 pdf_xml_tag_open_beg(s, "xmp:CreateDate");
+                 pdf_xml_tag_end(s);
-- 
2.32.0