Package: nim / 0.19.4-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
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
@@ -898,14 +898,14 @@
                  else: "doc.body_no_toc"
   content = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, bodyname), ["title",
       "tableofcontents", "moduledesc", "date", "time", "content"],
-      [title.rope, toc, d.modDesc, rope(getDateStr()),
+      [title.rope, toc, d.modDesc, rope(getSrcDateStr()),
       rope(getClockStr()), code])
   if optCompileOnly notin d.conf.globalOptions:
     # XXX what is this hack doing here? 'optCompileOnly' means raw output!?
     code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), ["title",
         "tableofcontents", "moduledesc", "date", "time",
         "content", "author", "version", "analytics"],
-        [title.rope, toc, d.modDesc, rope(getDateStr()),
+        [title.rope, toc, d.modDesc, rope(getSrcDateStr()),
                      rope(getClockStr()), content, d.meta[metaAuthor].rope,
                      d.meta[metaVersion].rope, d.analytics.rope])
   else:
@@ -1038,8 +1038,8 @@
   let code = ropeFormatNamedVars(conf, getConfigVar(conf, "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
   let filename = getOutFile(conf, RelativeFile"theindex", HtmlExt)
   if not writeRope(code, filename):
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -9,7 +9,7 @@
 
 import
   os, strutils, strtabs, osproc, sets, lineinfos, platform,
-  prefixmatches, pathutils
+  prefixmatches, pathutils, times
 
 from terminal import isatty
 from times import utc, fromUnix, local, getTime, format, DateTime
@@ -21,6 +21,22 @@
   hasFFI* = defined(useFFI)
   copyrightYear* = "2018"
 
+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)
+
 type                          # please make sure we have under 32 options
                               # (improves code efficiency a lot!)
   TOption* = enum             # **keep binary compatible**
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -594,8 +594,8 @@
     of skConst:
       case s.magic
       of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n, g)
-      of mCompileDate: result = newStrNodeT(getDateStr(), n, g)
-      of mCompileTime: result = newStrNodeT(getClockStr(), n, g)
+      of mCompileDate: result = newStrNodeT(getSrcDateStr(), n, g)
+      of mCompileTime: result = newStrNodeT(getSrcClockStr(), n, g)
       of mCpuEndian: result = newIntNodeT(ord(CPU[g.config.target.targetCPU].endian), n, g)
       of mHostOS: result = newStrNodeT(toLowerAscii(platform.OS[g.config.target.targetOS].name), n, g)
       of mHostCPU: result = newStrNodeT(platform.CPU[g.config.target.targetCPU].name.toLowerAscii, n, g)