* fix #12663 staticRead * address comments
This commit is contained in:
parent
04614a30bd
commit
dfe5d115fb
2 changed files with 15 additions and 12 deletions
|
|
@ -1037,15 +1037,16 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
|
||||||
pastStart = true
|
pastStart = true
|
||||||
lit "\L"
|
lit "\L"
|
||||||
|
|
||||||
proc nimfiles(conf: ConfigRef; f: File) =
|
proc depfiles(conf: ConfigRef; f: File) =
|
||||||
var i = 0
|
var i = 0
|
||||||
for it in conf.m.fileInfos:
|
for it in conf.m.fileInfos:
|
||||||
if isAbsolute(it.fullPath.string):
|
let path = it.fullPath.string
|
||||||
|
if isAbsolute(path): # TODO: else?
|
||||||
if i > 0: lit "],\L"
|
if i > 0: lit "],\L"
|
||||||
lit "["
|
lit "["
|
||||||
str it.fullPath.string
|
str path
|
||||||
lit ", "
|
lit ", "
|
||||||
str $secureHashFile(it.fullPath.string)
|
str $secureHashFile(path)
|
||||||
inc i
|
inc i
|
||||||
lit "]\L"
|
lit "]\L"
|
||||||
|
|
||||||
|
|
@ -1069,8 +1070,8 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
|
||||||
if optRun in conf.globalOptions or isDefined(conf, "nimBetterRun"):
|
if optRun in conf.globalOptions or isDefined(conf, "nimBetterRun"):
|
||||||
lit ",\L\"cmdline\": "
|
lit ",\L\"cmdline\": "
|
||||||
str conf.commandLine
|
str conf.commandLine
|
||||||
lit ",\L\"nimfiles\":[\L"
|
lit ",\L\"depfiles\":[\L"
|
||||||
nimfiles(conf, f)
|
depfiles(conf, f)
|
||||||
lit "],\L\"nimexe\": \L"
|
lit "],\L\"nimexe\": \L"
|
||||||
str hashNimExe()
|
str hashNimExe()
|
||||||
lit "\L"
|
lit "\L"
|
||||||
|
|
@ -1085,22 +1086,22 @@ proc changeDetectedViaJsonBuildInstructions*(conf: ConfigRef; projectfile: Absol
|
||||||
result = false
|
result = false
|
||||||
try:
|
try:
|
||||||
let data = json.parseFile(jsonFile.string)
|
let data = json.parseFile(jsonFile.string)
|
||||||
if not data.hasKey("nimfiles") or not data.hasKey("cmdline"):
|
if not data.hasKey("depfiles") or not data.hasKey("cmdline"):
|
||||||
return true
|
return true
|
||||||
let oldCmdLine = data["cmdline"].getStr
|
let oldCmdLine = data["cmdline"].getStr
|
||||||
if conf.commandLine != oldCmdLine:
|
if conf.commandLine != oldCmdLine:
|
||||||
return true
|
return true
|
||||||
if hashNimExe() != data["nimexe"].getStr:
|
if hashNimExe() != data["nimexe"].getStr:
|
||||||
return true
|
return true
|
||||||
let nimfilesPairs = data["nimfiles"]
|
let depfilesPairs = data["depfiles"]
|
||||||
doAssert nimfilesPairs.kind == JArray
|
doAssert depfilesPairs.kind == JArray
|
||||||
for p in nimfilesPairs:
|
for p in depfilesPairs:
|
||||||
doAssert p.kind == JArray
|
doAssert p.kind == JArray
|
||||||
# >= 2 for forwards compatibility with potential later .json files:
|
# >= 2 for forwards compatibility with potential later .json files:
|
||||||
doAssert p.len >= 2
|
doAssert p.len >= 2
|
||||||
let nimFilename = p[0].getStr
|
let depFilename = p[0].getStr
|
||||||
let oldHashValue = p[1].getStr
|
let oldHashValue = p[1].getStr
|
||||||
let newHashValue = $secureHashFile(nimFilename)
|
let newHashValue = $secureHashFile(depFilename)
|
||||||
if oldHashValue != newHashValue:
|
if oldHashValue != newHashValue:
|
||||||
return true
|
return true
|
||||||
except IOError, OSError, ValueError:
|
except IOError, OSError, ValueError:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import ast, types, msgs, os, options, idents, lineinfos
|
import ast, types, msgs, os, options, idents, lineinfos
|
||||||
|
from pathutils import AbsoluteFile
|
||||||
|
|
||||||
proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string =
|
proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string =
|
||||||
try:
|
try:
|
||||||
|
|
@ -17,6 +18,7 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): str
|
||||||
result = readFile(filename)
|
result = readFile(filename)
|
||||||
# we produce a fake include statement for every slurped filename, so that
|
# we produce a fake include statement for every slurped filename, so that
|
||||||
# the module dependencies are accurate:
|
# the module dependencies are accurate:
|
||||||
|
discard conf.fileInfoIdx(AbsoluteFile filename)
|
||||||
appendToModule(module, newNode(nkIncludeStmt, info, @[
|
appendToModule(module, newNode(nkIncludeStmt, info, @[
|
||||||
newStrNode(nkStrLit, filename)]))
|
newStrNode(nkStrLit, filename)]))
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue