https://reproducible-builds.org/ support via SOURCE_DATE_EPOCH (#7644) (#7661)
This commit is contained in:
parent
7d034d7b6a
commit
262aafa0a9
1 changed files with 17 additions and 2 deletions
|
|
@ -483,6 +483,19 @@ proc newSymNodeTypeDesc*(s: PSym; info: TLineInfo): PNode =
|
||||||
|
|
||||||
proc getConstExpr(m: PSym, n: PNode): PNode =
|
proc getConstExpr(m: PSym, n: PNode): 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
|
||||||
|
|
@ -492,8 +505,10 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
of skConst:
|
of skConst:
|
||||||
case s.magic
|
case s.magic
|
||||||
of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n)
|
of mIsMainModule: result = newIntNodeT(ord(sfMainModule in m.flags), n)
|
||||||
of mCompileDate: result = newStrNodeT(times.getDateStr(), n)
|
of mCompileDate: result = newStrNodeT(format(getSrcTimestamp(),
|
||||||
of mCompileTime: result = newStrNodeT(times.getClockStr(), n)
|
"yyyy-MM-dd"), n)
|
||||||
|
of mCompileTime: result = newStrNodeT(format(getSrcTimestamp(),
|
||||||
|
"HH:mm:ss"), n)
|
||||||
of mCpuEndian: result = newIntNodeT(ord(CPU[targetCPU].endian), n)
|
of mCpuEndian: result = newIntNodeT(ord(CPU[targetCPU].endian), n)
|
||||||
of mHostOS: result = newStrNodeT(toLowerAscii(platform.OS[targetOS].name), n)
|
of mHostOS: result = newStrNodeT(toLowerAscii(platform.OS[targetOS].name), n)
|
||||||
of mHostCPU: result = newStrNodeT(platform.CPU[targetCPU].name.toLowerAscii, n)
|
of mHostCPU: result = newStrNodeT(platform.CPU[targetCPU].name.toLowerAscii, n)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue