scdoc: Use $SOURCE_DATE_EPOCH to produce reproducible man pages

Use this patch until something like it is in the upstream repository.
Without it, the current date is used for the man pages, which makes them
non-reproducible.
This commit is contained in:
Michael Weiss 2018-11-05 20:27:31 +01:00
parent a35dae70c3
commit 7eaba9af5e
2 changed files with 77 additions and 0 deletions

View File

@ -9,6 +9,8 @@ stdenv.mkDerivation rec {
sha256 = "0a9sxifzsbj24kjnpc0525i91ni2vkwizhgvwx1m9shvfkiisnc6";
};
patches = [ ./use-source-date-epoch.patch ];
postPatch = ''
substituteInPlace Makefile \
--replace "-static" "" \

View File

@ -0,0 +1,75 @@
diff --git a/src/main.c b/src/main.c
index 14b08d2..e2cc33e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#define __USE_XOPEN
#include <time.h>
#include <unistd.h>
#include "string.h"
@@ -66,10 +67,17 @@ static void parse_preamble(struct parser *p) {
int section = -1;
uint32_t ch;
char date[256];
- time_t now;
- time(&now);
- struct tm *now_tm = localtime(&now);
- strftime(date, sizeof(date), "%F", now_tm);
+ char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
+ if (source_date_epoch != NULL) {
+ struct tm source_date_epoch_tm;
+ strptime(source_date_epoch, "%s", &source_date_epoch_tm);
+ strftime(date, sizeof(date), "%F", &source_date_epoch_tm);
+ } else {
+ time_t now;
+ time(&now);
+ struct tm *now_tm = localtime(&now);
+ strftime(date, sizeof(date), "%F", now_tm);
+ }
while ((ch = parser_getch(p)) != UTF8_INVALID) {
if ((ch < 0x80 && isalnum(ch)) || ch == '_' || ch == '-' || ch == '.') {
assert(str_append_ch(name, ch) != -1);
diff --git a/test/preamble b/test/preamble
index 03e2d0c..eeb734b 100755
--- a/test/preamble
+++ b/test/preamble
@@ -38,31 +38,31 @@ EOF
end 0
begin "Writes the appropriate header"
-scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F')"'"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
test(8)
EOF
end 0
begin "Preserves dashes"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'"' >/dev/null
test-manual(8)
EOF
end 0
begin "Handles extra footer field"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer"' >/dev/null
test-manual(8) "Footer"
EOF
end 0
begin "Handles both extra fields"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "Footer" "Header"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "Footer" "Header"' >/dev/null
test-manual(8) "Footer" "Header"
EOF
end 0
begin "Emits empty footer correctly"
-scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F')"'" "" "Header"' >/dev/null
+scdoc <<EOF | grep '^\.TH "test-manual" "8" "'"$(date +'%F' --date=@${SOURCE_DATE_EPOCH:-$(date +'%s')})"'" "" "Header"' >/dev/null
test-manual(8) "" "Header"
EOF
end 0