Package: nim / 0.16.0-1

use-source-date-epoch.patch Patch series | download
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
Description: Have docgen use SOURCE_DATE_EPOCH for reproducible documentation
Author: Ximin Luo <infinity0@debian.org>
Bug: https://github.com/nim-lang/Nim/issues/3113
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -642,15 +642,15 @@
                  else: "doc.body_no_toc"
   content = ropeFormatNamedVars(getConfigVar(bodyname), ["title",
       "tableofcontents", "moduledesc", "date", "time", "content"],
-      [title.rope, toc, d.modDesc, rope(getDateStr()),
-      rope(getClockStr()), code])
+      [title.rope, toc, d.modDesc, rope(getSrcDateStr()),
+      rope(getSrcClockStr()), code])
   if optCompileOnly notin gGlobalOptions:
     # XXX what is this hack doing here? 'optCompileOnly' means raw output!?
     code = ropeFormatNamedVars(getConfigVar("doc.file"), ["title",
         "tableofcontents", "moduledesc", "date", "time",
         "content", "author", "version", "analytics"],
-        [title.rope, toc, d.modDesc, rope(getDateStr()),
-                     rope(getClockStr()), content, d.meta[metaAuthor].rope,
+        [title.rope, toc, d.modDesc, rope(getSrcDateStr()),
+                     rope(getSrcClockStr()), content, d.meta[metaAuthor].rope,
                      d.meta[metaVersion].rope, d.analytics.rope])
   else:
     code = content
@@ -743,7 +743,7 @@
   let code = ropeFormatNamedVars(getConfigVar("doc.file"), ["title",
       "tableofcontents", "moduledesc", "date", "time",
       "content", "author", "version", "analytics"],
-      ["Index".rope, nil, nil, rope(getDateStr()),
-                   rope(getClockStr()), content, nil, nil, nil])
+      ["Index".rope, nil, nil, rope(getSrcDateStr()),
+                   rope(getSrcClockStr()), content, nil, nil, nil])
   # no analytics because context is not available
   writeRope(code, getOutFile("theindex", HtmlExt))
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -8,7 +8,7 @@
 #
 
 import
-  os, lists, strutils, strtabs, osproc, sets
+  os, lists, strutils, strtabs, osproc, sets, times
 
 const
   hasTinyCBackend* = defined(tinyc)
@@ -175,6 +175,22 @@
 
 const oKeepVariableNames* = true
 
+proc getSrcTime(): Time =
+  if existsEnv("SOURCE_DATE_EPOCH"):
+    return fromSeconds(parseInt(getEnv("SOURCE_DATE_EPOCH")))
+  else:
+    return getTime()
+
+proc getSrcDateStr*(): string =
+  var ti = getGMTime(getSrcTime())
+  result = $ti.year & '-' & intToStr(ord(ti.month)+1, 2) &
+    '-' & intToStr(ti.monthday, 2)
+
+proc getSrcClockStr*(): string =
+  var ti = getGMTime(getSrcTime())
+  result = intToStr(ti.hour, 2) & ':' & intToStr(ti.minute, 2) &
+    ':' & intToStr(ti.second, 2)
+
 proc mainCommandArg*: string =
   ## This is intended for commands like check or parse
   ## which will work on the main project file unless
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -608,8 +608,8 @@
     of skConst:
       case s.magic
       of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n)
-      of mCompileDate: result = newStrNodeT(times.getDateStr(), n)
-      of mCompileTime: result = newStrNodeT(times.getClockStr(), n)
+      of mCompileDate: result = newStrNodeT(getSrcDateStr(), n)
+      of mCompileTime: result = newStrNodeT(getSrcClockStr(), n)
       of mCpuEndian: result = newIntNodeT(ord(CPU[targetCPU].endian), n)
       of mHostOS: result = newStrNodeT(toLowerAscii(platform.OS[targetOS].name), n)
       of mHostCPU: result = newStrNodeT(platform.CPU[targetCPU].name.toLowerAscii, n)