gnu: gnucash: Disable the stress-options-test using a phase.
[jackhill/guix/guix.git] / gnu / packages / patches / groff-source-date-epoch.patch
CommitLineData
9146543f
DM
1Adds support for the environment variable SOURCE_DATE_EPOCH.
2
3See: https://sources.debian.net/patches/groff/1.22.3-9/source-date-epoch.patch/
4
5From abc23bc9245e18468817f2838361c3a08f7521e2 Mon Sep 17 00:00:00 2001
6From: Colin Watson <cjwatson@debian.org>
7Date: Thu, 5 Nov 2015 11:47:34 +0000
8Subject: Implement `SOURCE_DATE_EPOCH' for reproducible builds.
9
10Author: Colin Watson <cjwatson@debian.org>
11Forwarded: yes
12Last-Update: 2015-11-05
13
14Patch-Name: source-date-epoch.patch
15---
16 doc/groff.texinfo | 6 +++++
17 src/devices/grohtml/grohtml.man | 7 ++++++
18 src/devices/grohtml/post-html.cpp | 5 ++--
19 src/devices/gropdf/gropdf.man | 7 ++++++
20 src/devices/gropdf/gropdf.pl | 3 ++-
21 src/devices/grops/grops.man | 7 ++++++
22 src/devices/grops/ps.cpp | 3 ++-
23 src/include/curtime.h | 23 ++++++++++++++++++
24 src/libs/libgroff/Makefile.sub | 2 ++
25 src/libs/libgroff/curtime.cpp | 51 +++++++++++++++++++++++++++++++++++++++
26 src/roff/troff/input.cpp | 3 ++-
27 11 files changed, 112 insertions(+), 5 deletions(-)
28 create mode 100644 src/include/curtime.h
29 create mode 100644 src/libs/libgroff/curtime.cpp
30
31diff --git a/doc/groff.texinfo b/doc/groff.texinfo
32index 066b5274..1d3c7a9f 100644
33--- a/doc/groff.texinfo
34+++ b/doc/groff.texinfo
35@@ -1453,6 +1453,12 @@ default directory (on Unix and GNU/Linux systems, this is usually
36 @item GROFF_TYPESETTER
37 @tindex GROFF_TYPESETTER@r{, environment variable}
38 The default output device.
39+
40+@item SOURCE_DATE_EPOCH
41+@tindex SOURCE_DATE_EPOCH@r{, environment variable}
42+A timestamp (expressed as seconds since the Unix epoch) to use in place of
43+the current time when initializing time-based built-in registers such as
44+@code{\n[seconds]}.
45 @end table
46
47 Note that MS-DOS and MS-Windows ports of @code{groff} use semi-colons,
48diff --git a/src/devices/grohtml/grohtml.man b/src/devices/grohtml/grohtml.man
49index 51eae224..4be4abbc 100644
50--- a/src/devices/grohtml/grohtml.man
51+++ b/src/devices/grohtml/grohtml.man
52@@ -419,6 +419,13 @@ and
53 for more details.
54 .
55 .
56+.TP
57+.SM
58+.B SOURCE_DATE_EPOCH
59+A timestamp (expressed as seconds since the Unix epoch) to use as the
60+creation timestamp in place of the current time.
61+.
62+.
63 .\" --------------------------------------------------------------------
64 .SH BUGS
65 .\" --------------------------------------------------------------------
66diff --git a/src/devices/grohtml/post-html.cpp b/src/devices/grohtml/post-html.cpp
67index fefbf014..b5fc5167 100644
68--- a/src/devices/grohtml/post-html.cpp
69+++ b/src/devices/grohtml/post-html.cpp
70@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
71 #include "html.h"
72 #include "html-text.h"
73 #include "html-table.h"
74+#include "curtime.h"
75
76 #include <time.h>
77
78@@ -5013,7 +5014,7 @@ void html_printer::do_file_components (void)
79 .put_string(Version_string)
80 .end_comment();
81
82- t = time(0);
83+ t = current_time();
84 html.begin_comment("CreationDate: ")
85 .put_string(ctime(&t), strlen(ctime(&t))-1)
86 .end_comment();
87@@ -5126,7 +5127,7 @@ html_printer::~html_printer()
88 .put_string(Version_string)
89 .end_comment();
90
91- t = time(0);
92+ t = current_time();
93 html.begin_comment("CreationDate: ")
94 .put_string(ctime(&t), strlen(ctime(&t))-1)
95 .end_comment();
96diff --git a/src/devices/gropdf/gropdf.man b/src/devices/gropdf/gropdf.man
97index 3bbace6a..cc0c82f1 100644
98--- a/src/devices/gropdf/gropdf.man
99+++ b/src/devices/gropdf/gropdf.man
100@@ -1029,6 +1029,13 @@ and
101 for more details.
102 .
103 .
104+.TP
105+.SM
106+.B SOURCE_DATE_EPOCH
107+A timestamp (expressed as seconds since the Unix epoch) to use as the
108+creation timestamp in place of the current time.
109+.
110+.
111 .\" --------------------------------------------------------------------
112 .SH FILES
113 .\" --------------------------------------------------------------------
114diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
115index 035d1238..c25c4c67 100644
116--- a/src/devices/gropdf/gropdf.pl
117+++ b/src/devices/gropdf/gropdf.pl
118@@ -239,13 +239,14 @@ elsif (exists($ppsz{$papersz}))
119 @defaultmb=@mediabox=(0,0,$ppsz{$papersz}->[0],$ppsz{$papersz}->[1]);
120 }
121
122-my (@dt)=localtime(time);
123+my (@dt)=localtime($ENV{SOURCE_DATE_EPOCH} || time);
124 my $dt=PDFDate(\@dt);
125
126 my %info=('Creator' => "(groff version $cfg{GROFF_VERSION})",
127 'Producer' => "(gropdf version $cfg{GROFF_VERSION})",
128 'ModDate' => "($dt)",
129 'CreationDate' => "($dt)");
130+
131 while (<>)
132 {
133 chomp;
134diff --git a/src/devices/grops/grops.man b/src/devices/grops/grops.man
135index 99fb7486..272c2d18 100644
136--- a/src/devices/grops/grops.man
137+++ b/src/devices/grops/grops.man
138@@ -1419,6 +1419,13 @@ and
139 for more details.
140 .
141 .
142+.TP
143+.SM
144+.B SOURCE_DATE_EPOCH
145+A timestamp (expressed as seconds since the Unix epoch) to use as the
146+creation timestamp in place of the current time.
147+.
148+.
149 .\" --------------------------------------------------------------------
150 .SH FILES
151 .\" --------------------------------------------------------------------
152diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
153index 745a503b..03e65372 100644
154--- a/src/devices/grops/ps.cpp
155+++ b/src/devices/grops/ps.cpp
156@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
157 #include "cset.h"
158 #include "nonposix.h"
159 #include "paper.h"
160+#include "curtime.h"
161
162 #include "ps.h"
163 #include <time.h>
164@@ -1390,7 +1391,7 @@ ps_printer::~ps_printer()
165 #else
166 time_t
167 #endif
168- t = time(0);
169+ t = current_time();
170 fputs(ctime(&t), out.get_file());
171 }
172 for (font_pointer_list *f = font_list; f; f = f->next) {
173diff --git a/src/include/curtime.h b/src/include/curtime.h
174new file mode 100644
175index 00000000..a4105196
176--- /dev/null
177+++ b/src/include/curtime.h
178@@ -0,0 +1,23 @@
179+/* Copyright (C) 2015 Free Software Foundation, Inc.
180+
181+This file is part of groff.
182+
183+groff is free software; you can redistribute it and/or modify it under
184+the terms of the GNU General Public License as published by the Free
185+Software Foundation, either version 2 of the License, or
186+(at your option) any later version.
187+
188+groff is distributed in the hope that it will be useful, but WITHOUT ANY
189+WARRANTY; without even the implied warranty of MERCHANTABILITY or
190+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
191+for more details.
192+
193+The GNU General Public License version 2 (GPL2) is available in the
194+internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
195+
196+#ifdef LONG_FOR_TIME_T
197+long
198+#else
199+time_t
200+#endif
201+current_time();
202diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub
203index 840d9934..4cb4937a 100644
204--- a/src/libs/libgroff/Makefile.sub
205+++ b/src/libs/libgroff/Makefile.sub
206@@ -32,6 +32,7 @@ OBJS=\
207 cmap.$(OBJEXT) \
208 color.$(OBJEXT) \
209 cset.$(OBJEXT) \
210+ curtime.$(OBJEXT) \
211 device.$(OBJEXT) \
212 errarg.$(OBJEXT) \
213 error.$(OBJEXT) \
214@@ -82,6 +83,7 @@ CCSRCS=\
215 $(srcdir)/cmap.cpp \
216 $(srcdir)/color.cpp \
217 $(srcdir)/cset.cpp \
218+ $(srcdir)/curtime.cpp \
219 $(srcdir)/device.cpp \
220 $(srcdir)/errarg.cpp \
221 $(srcdir)/error.cpp \
222diff --git a/src/libs/libgroff/curtime.cpp b/src/libs/libgroff/curtime.cpp
223new file mode 100644
224index 00000000..00821b7f
225--- /dev/null
226+++ b/src/libs/libgroff/curtime.cpp
227@@ -0,0 +1,51 @@
228+/* Copyright (C) 2015 Free Software Foundation, Inc.
229+
230+This file is part of groff.
231+
232+groff is free software; you can redistribute it and/or modify it under
233+the terms of the GNU General Public License as published by the Free
234+Software Foundation, either version 2 of the License, or
235+(at your option) any later version.
236+
237+groff is distributed in the hope that it will be useful, but WITHOUT ANY
238+WARRANTY; without even the implied warranty of MERCHANTABILITY or
239+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
240+for more details.
241+
242+The GNU General Public License version 2 (GPL2) is available in the
243+internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
244+
245+#include <errno.h>
246+#include <limits.h>
247+#include <stdlib.h>
248+#include <string.h>
249+#include <time.h>
250+
251+#include "errarg.h"
252+#include "error.h"
253+
254+#ifdef LONG_FOR_TIME_T
255+long
256+#else
257+time_t
258+#endif
259+current_time()
260+{
261+ char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
262+
263+ if (source_date_epoch) {
264+ errno = 0;
265+ char *endptr;
266+ long epoch = strtol(source_date_epoch, &endptr, 10);
267+
268+ if ((errno == ERANGE && (epoch == LONG_MAX || epoch == LONG_MIN)) ||
269+ (errno != 0 && epoch == 0))
270+ fatal("$SOURCE_DATE_EPOCH: strtol: %1", strerror(errno));
271+ if (endptr == source_date_epoch)
272+ fatal("$SOURCE_DATE_EPOCH: no digits found: %1", endptr);
273+ if (*endptr != '\0')
274+ fatal("$SOURCE_DATE_EPOCH: trailing garbage: %1", endptr);
275+ return epoch;
276+ } else
277+ return time(0);
278+}
279diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
280index 9594f074..f7d2c18a 100644
281--- a/src/roff/troff/input.cpp
282+++ b/src/roff/troff/input.cpp
283@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
284 #include "input.h"
285 #include "defs.h"
286 #include "unicode.h"
287+#include "curtime.h"
288
289 // Needed for getpid() and isatty()
290 #include "posix.h"
291@@ -8138,7 +8139,7 @@ static void init_registers()
292 #else /* not LONG_FOR_TIME_T */
293 time_t
294 #endif /* not LONG_FOR_TIME_T */
295- t = time(0);
296+ t = current_time();
297 // Use struct here to work around misfeature in old versions of g++.
298 struct tm *tt = localtime(&t);
299 set_number_reg("seconds", int(tt->tm_sec));