Source: gettext
Version: 0.19.4-1
Severity: wishlist
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: toolchain timestamps
X-Debbugs-Cc: reproducible-bui...@lists.alioth.debian.org

Hi,

While working on the "reproducible builds" effort [1], we have noticed
that the xgettext tool from gettext embeds timestamps on the creation of
PO files.

For the Reproducible Builds effort we are proposing an environment
variable (SOURCE_DATE_EPOCH) [2] that will contain a deterministic epoch
timestamp (based on the latest debian/changelog entry) that could be
used, which should be automatically exported by debhelper in the future [3].

The attached patch proposes a way to use this variable to get
reproducible timestamps in the PO files generated by xgettext, if the
variable has been set (if not, it falls back to the old behavior).
With the attached patch packages using xgettext would then automatically
generate reproducible translation files.


[1]: https://wiki.debian.org/ReproducibleBuilds
[2]: https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal
[3]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=791815

Regards,
-- 
Dhole
diff -Nru gettext-0.19.4/debian/changelog gettext-0.19.4/debian/changelog
--- gettext-0.19.4/debian/changelog     2015-05-15 18:01:14.000000000 +0200
+++ gettext-0.19.4/debian/changelog     2015-07-17 15:47:54.000000000 +0200
@@ -1,3 +1,11 @@
+gettext (0.19.4-1.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * Add support for reproducible builds by using $SOURCE_DATE_EPOCH as the
+    date on creation of PO files with xgettext.
+
+ -- Dhole <dh...@openmailbox.org>  Fri, 17 Jul 2015 15:47:41 +0200
+
 gettext (0.19.4-1) unstable; urgency=low
 
   * New upstream release.
diff -Nru 
gettext-0.19.4/debian/patches/03-Replace-timestamp-with-SOURCE_DATE_EPOCH 
gettext-0.19.4/debian/patches/03-Replace-timestamp-with-SOURCE_DATE_EPOCH
--- gettext-0.19.4/debian/patches/03-Replace-timestamp-with-SOURCE_DATE_EPOCH   
1970-01-01 01:00:00.000000000 +0100
+++ gettext-0.19.4/debian/patches/03-Replace-timestamp-with-SOURCE_DATE_EPOCH   
2015-07-17 15:56:22.000000000 +0200
@@ -0,0 +1,47 @@
+Description: Replace date timestamp by SOURCE_DATE_EPOCH env var in xgettext
+ .
+ gettext (0.19.4-1.1) UNRELEASED; urgency=medium
+ .
+   * Non-maintainer upload.
+   * Add support for reproducible builds by using $SOURCE_DATE_EPOCH as the
+     date on creation of PO files with xgettext.
+Author: Dhole <dh...@openmailbox.org>
+
+---
+
+--- gettext-0.19.4.orig/gettext-tools/src/xgettext.c
++++ gettext-0.19.4/gettext-tools/src/xgettext.c
+@@ -3410,6 +3410,7 @@ construct_header ()
+   message_ty *mp;
+   char *msgstr;
+   char *comment;
++  char *source_date_epoch;
+   static lex_pos_ty pos = { __FILE__, __LINE__ };
+ 
+   if (package_name != NULL)
+@@ -3431,7 +3432,24 @@ the MSGID_BUGS_ADDRESS variable there; o
+ specify an --msgid-bugs-address command line option.\n\
+ ")));
+ 
+-  time (&now);
++  /* Allow the date and time to be set externally by an exported
++     environment variable to enable reproducible builds. */
++  source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
++  if (source_date_epoch)
++    {
++      errno = 0;
++      now = (time_t) strtol (source_date_epoch, NULL, 10);
++      if (errno != 0)
++        error (EXIT_FAILURE, errno, _("\
++SOURCE_DATE_EPOCH=\"%s\" is not a valid number"), source_date_epoch);
++
++      /* The function po_strftime uses localtime() to parse the timestamp, so 
++         we need to fix the environment timezone to get reproducible results 
*/
++      setenv("TZ", "UTC", 1);
++    }
++  else
++    time (&now);
++
+   timestring = po_strftime (&now);
+ 
+   msgstr = xasprintf ("\
diff -Nru gettext-0.19.4/debian/patches/series 
gettext-0.19.4/debian/patches/series
--- gettext-0.19.4/debian/patches/series        2015-05-15 17:19:58.000000000 
+0200
+++ gettext-0.19.4/debian/patches/series        2015-07-17 15:55:50.000000000 
+0200
@@ -1,2 +1,3 @@
 01-do-not-use-java-in-urlget
 02-msgfmt-default-little-endian
+03-Replace-timestamp-with-SOURCE_DATE_EPOCH

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to