system.compileDate and compileTime are in UTC; fixes #7305; docgen supports SOURCE_DATE_EPOCH, fixes #3113

This commit is contained in:
Andreas Rumpf 2018-09-03 22:23:10 +02:00
commit e4be1cb814
3 changed files with 23 additions and 19 deletions

View file

@ -14,7 +14,7 @@
import import
ast, strutils, strtabs, options, msgs, os, ropes, idents, ast, strutils, strtabs, options, msgs, os, ropes, idents,
wordrecg, syntaxes, renderer, lexer, packages/docutils/rstast, wordrecg, syntaxes, renderer, lexer, packages/docutils/rstast,
packages/docutils/rst, packages/docutils/rstgen, times, packages/docutils/rst, packages/docutils/rstgen,
packages/docutils/highlite, sempass2, json, xmltree, cgi, packages/docutils/highlite, sempass2, json, xmltree, cgi,
typesrenderer, astalgo, modulepaths, lineinfos, sequtils typesrenderer, astalgo, modulepaths, lineinfos, sequtils

View file

@ -12,6 +12,7 @@ import
prefixmatches prefixmatches
from terminal import isatty from terminal import isatty
from times import utc, fromUnix, local, getTime, format, DateTime
const const
hasTinyCBackend* = defined(tinyc) hasTinyCBackend* = defined(tinyc)
@ -259,6 +260,24 @@ const
optPatterns, optNilCheck, optMoveCheck} optPatterns, optNilCheck, optMoveCheck}
DefaultGlobalOptions* = {optThreadAnalysis} DefaultGlobalOptions* = {optThreadAnalysis}
proc getSrcTimestamp(): DateTime =
try:
result = utc(fromUnix(parseInt(getEnv("SOURCE_DATE_EPOCH",
"not a number"))))
except ValueError:
# Environment variable malformed.
# https://reproducible-builds.org/specs/source-date-epoch/: "If the
# value is malformed, the build process SHOULD exit with a non-zero
# error code", which this doesn't do. This uses local time, because
# that maintains compatibility with existing usage.
result = utc getTime()
proc getDateStr*(): string =
result = format(getSrcTimestamp(), "yyyy-MM-dd")
proc getClockStr*(): string =
result = format(getSrcTimestamp(), "HH:mm:ss")
template newPackageCache*(): untyped = template newPackageCache*(): untyped =
newStringTable(when FileSystemCaseSensitive: newStringTable(when FileSystemCaseSensitive:
modeCaseInsensitive modeCaseInsensitive

View file

@ -11,7 +11,7 @@
# and evaluation phase # and evaluation phase
import import
strutils, options, ast, astalgo, trees, treetab, nimsets, times, strutils, options, ast, astalgo, trees, treetab, nimsets,
nversion, platform, math, msgs, os, condsyms, idents, renderer, types, nversion, platform, math, msgs, os, condsyms, idents, renderer, types,
commands, magicsys, modulegraphs, strtabs, lineinfos commands, magicsys, modulegraphs, strtabs, lineinfos
@ -566,19 +566,6 @@ proc newSymNodeTypeDesc*(s: PSym; info: TLineInfo): PNode =
proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
result = nil result = nil
proc getSrcTimestamp(): DateTime =
try:
result = utc(fromUnix(parseInt(getEnv("SOURCE_DATE_EPOCH",
"not a number"))))
except ValueError:
# Environment variable malformed.
# https://reproducible-builds.org/specs/source-date-epoch/: "If the
# value is malformed, the build process SHOULD exit with a non-zero
# error code", which this doesn't do. This uses local time, because
# that maintains compatibility with existing usage.
result = local(getTime())
case n.kind case n.kind
of nkSym: of nkSym:
var s = n.sym var s = n.sym
@ -588,10 +575,8 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
of skConst: of skConst:
case s.magic case s.magic
of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n, g) of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n, g)
of mCompileDate: result = newStrNodeT(format(getSrcTimestamp(), of mCompileDate: result = newStrNodeT(getDateStr(), n, g)
"yyyy-MM-dd"), n, g) of mCompileTime: result = newStrNodeT(getClockStr(), n, g)
of mCompileTime: result = newStrNodeT(format(getSrcTimestamp(),
"HH:mm:ss"), n, g)
of mCpuEndian: result = newIntNodeT(ord(CPU[g.config.target.targetCPU].endian), 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 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) of mHostCPU: result = newStrNodeT(platform.CPU[g.config.target.targetCPU].name.toLowerAscii, n, g)