aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/groff-source-date-epoch.patch
blob: 53c590b04924262e2614a2830203d22d23a237b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
Adds support for the environment variable SOURCE_DATE_EPOCH.

See: https://sources.debian.net/patches/groff/1.22.3-9/source-date-epoch.patch/

From abc23bc9245e18468817f2838361c3a08f7521e2 Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@debian.org>
Date: Thu, 5 Nov 2015 11:47:34 +0000
Subject: Implement `SOURCE_DATE_EPOCH' for reproducible builds.

Author: Colin Watson <cjwatson@debian.org>
Forwarded: yes
Last-Update: 2015-11-05

Patch-Name: source-date-epoch.patch
---
 doc/groff.texinfo                 |  6 +++++
 src/devices/grohtml/grohtml.man   |  7 ++++++
 src/devices/grohtml/post-html.cpp |  5 ++--
 src/devices/gropdf/gropdf.man     |  7 ++++++
 src/devices/gropdf/gropdf.pl      |  3 ++-
 src/devices/grops/grops.man       |  7 ++++++
 src/devices/grops/ps.cpp          |  3 ++-
 src/include/curtime.h             | 23 ++++++++++++++++++
 src/libs/libgroff/Makefile.sub    |  2 ++
 src/libs/libgroff/curtime.cpp     | 51 +++++++++++++++++++++++++++++++++++++++
 src/roff/troff/input.cpp          |  3 ++-
 11 files changed, 112 insertions(+), 5 deletions(-)
 create mode 100644 src/include/curtime.h
 create mode 100644 src/libs/libgroff/curtime.cpp

diff --git a/doc/groff.texinfo b/doc/groff.texinfo
index 066b5274..1d3c7a9f 100644
--- a/doc/groff.texinfo
+++ b/doc/groff.texinfo
@@ -1453,6 +1453,12 @@ default directory (on Unix and GNU/Linux systems, this is usually
 @item GROFF_TYPESETTER
 @tindex GROFF_TYPESETTER@r{, environment variable}
 The default output device.
+
+@item SOURCE_DATE_EPOCH
+@tindex SOURCE_DATE_EPOCH@r{, environment variable}
+A timestamp (expressed as seconds since the Unix epoch) to use in place of
+the current time when initializing time-based built-in registers such as
+@code{\n[seconds]}.
 @end table
 
 Note that MS-DOS and MS-Windows ports of @code{groff} use semi-colons,
diff --git a/src/devices/grohtml/grohtml.man b/src/devices/grohtml/grohtml.man
index 51eae224..4be4abbc 100644
--- a/src/devices/grohtml/grohtml.man
+++ b/src/devices/grohtml/grohtml.man
@@ -419,6 +419,13 @@ and
 for more details.
 .
 .
+.TP
+.SM
+.B SOURCE_DATE_EPOCH
+A timestamp (expressed as seconds since the Unix epoch) to use as the
+creation timestamp in place of the current time.
+.
+.
 .\" --------------------------------------------------------------------
 .SH BUGS
 .\" --------------------------------------------------------------------
diff --git a/src/devices/grohtml/post-html.cpp b/src/devices/grohtml/post-html.cpp
index fefbf014..b5fc5167 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
 #include "html.h"
 #include "html-text.h"
 #include "html-table.h"
+#include "curtime.h"
 
 #include <time.h>
 
@@ -5013,7 +5014,7 @@ void html_printer::do_file_components (void)
 	.put_string(Version_string)
 	.end_comment();
 
-      t = time(0);
+      t = current_time();
       html.begin_comment("CreationDate: ")
 	.put_string(ctime(&t), strlen(ctime(&t))-1)
 	.end_comment();
@@ -5126,7 +5127,7 @@ html_printer::~html_printer()
     .put_string(Version_string)
     .end_comment();
 
-  t = time(0);
+  t = current_time();
   html.begin_comment("CreationDate: ")
     .put_string(ctime(&t), strlen(ctime(&t))-1)
     .end_comment();
diff --git a/src/devices/gropdf/gropdf.man b/src/devices/gropdf/gropdf.man
index 3bbace6a..cc0c82f1 100644
--- a/src/devices/gropdf/gropdf.man
+++ b/src/devices/gropdf/gropdf.man
@@ -1029,6 +1029,13 @@ and
 for more details.
 .
 .
+.TP
+.SM
+.B SOURCE_DATE_EPOCH
+A timestamp (expressed as seconds since the Unix epoch) to use as the
+creation timestamp in place of the current time.
+.
+.
 .\" --------------------------------------------------------------------
 .SH FILES
 .\" --------------------------------------------------------------------
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 035d1238..c25c4c67 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -239,13 +239,14 @@ elsif (exists($ppsz{$papersz}))
     @defaultmb=@mediabox=(0,0,$ppsz{$papersz}->[0],$ppsz{$papersz}->[1]);
 }
 
-my (@dt)=localtime(time);
+my (@dt)=localtime($ENV{SOURCE_DATE_EPOCH} || time);
 my $dt=PDFDate(\@dt);
 
 my %info=('Creator' => "(groff version $cfg{GROFF_VERSION})",
 				'Producer' => "(gropdf version $cfg{GROFF_VERSION})",
 				'ModDate' => "($dt)",
 				'CreationDate' => "($dt)");
+
 while (<>)
 {
     chomp;
diff --git a/src/devices/grops/grops.man b/src/devices/grops/grops.man
index 99fb7486..272c2d18 100644
--- a/src/devices/grops/grops.man
+++ b/src/devices/grops/grops.man
@@ -1419,6 +1419,13 @@ and
 for more details.
 .
 .
+.TP
+.SM
+.B SOURCE_DATE_EPOCH
+A timestamp (expressed as seconds since the Unix epoch) to use as the
+creation timestamp in place of the current time.
+.
+.
 .\" --------------------------------------------------------------------
 .SH FILES
 .\" --------------------------------------------------------------------
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 745a503b..03e65372 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
 #include "cset.h"
 #include "nonposix.h"
 #include "paper.h"
+#include "curtime.h"
 
 #include "ps.h"
 #include <time.h>
@@ -1390,7 +1391,7 @@ ps_printer::~ps_printer()
 #else
     time_t
 #endif
-    t = time(0);
+    t = current_time();
     fputs(ctime(&t), out.get_file());
   }
   for (font_pointer_list *f = font_list; f; f = f->next) {
diff --git a/src/include/curtime.h b/src/include/curtime.h
new file mode 100644
index 00000000..a4105196
--- /dev/null
+++ b/src/include/curtime.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 2015  Free Software Foundation, Inc.
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+The GNU General Public License version 2 (GPL2) is available in the
+internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
+
+#ifdef LONG_FOR_TIME_T
+long
+#else
+time_t
+#endif
+current_time();
diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub
index 840d9934..4cb4937a 100644
--- a/src/libs/libgroff/Makefile.sub
+++ b/src/libs/libgroff/Makefile.sub
@@ -32,6 +32,7 @@ OBJS=\
   cmap.$(OBJEXT) \
   color.$(OBJEXT) \
   cset.$(OBJEXT) \
+  curtime.$(OBJEXT) \
   device.$(OBJEXT) \
   errarg.$(OBJEXT) \
   error.$(OBJEXT) \
@@ -82,6 +83,7 @@ CCSRCS=\
   $(srcdir)/cmap.cpp \
   $(srcdir)/color.cpp \
   $(srcdir)/cset.cpp \
+  $(srcdir)/curtime.cpp \
   $(srcdir)/device.cpp \
   $(srcdir)/errarg.cpp \
   $(srcdir)/error.cpp \
diff --git a/src/libs/libgroff/curtime.cpp b/src/libs/libgroff/curtime.cpp
new file mode 100644
index 00000000..00821b7f
--- /dev/null
+++ b/src/libs/libgroff/curtime.cpp
@@ -0,0 +1,51 @@
+/* Copyright (C) 2015  Free Software Foundation, Inc.
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+The GNU General Public License version 2 (GPL2) is available in the
+internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "errarg.h"
+#include "error.h"
+
+#ifdef LONG_FOR_TIME_T
+long
+#else
+time_t
+#endif
+current_time()
+{
+  char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+
+  if (source_date_epoch) {
+    errno = 0;
+    char *endptr;
+    long epoch = strtol(source_date_epoch, &endptr, 10);
+
+    if ((errno == ERANGE && (epoch == LONG_MAX || epoch == LONG_MIN)) ||
+	(errno != 0 && epoch == 0))
+      fatal("$SOURCE_DATE_EPOCH: strtol: %1", strerror(errno));
+    if (endptr == source_date_epoch)
+      fatal("$SOURCE_DATE_EPOCH: no digits found: %1", endptr);
+    if (*endptr != '\0')
+      fatal("$SOURCE_DATE_EPOCH: trailing garbage: %1", endptr);
+    return epoch;
+  } else
+    return time(0);
+}
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 9594f074..f7d2c18a 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
 #include "input.h"
 #include "defs.h"
 #include "unicode.h"
+#include "curtime.h"
 
 // Needed for getpid() and isatty()
 #include "posix.h"
@@ -8138,7 +8139,7 @@ static void init_registers()
 #else /* not LONG_FOR_TIME_T */
   time_t
 #endif /* not LONG_FOR_TIME_T */
-    t = time(0);
+    t = current_time();
   // Use struct here to work around misfeature in old versions of g++.
   struct tm *tt = localtime(&t);
   set_number_reg("seconds", int(tt->tm_sec));