Fix #209 - cache return val, fix nimcache dir
This commit is contained in:
parent
3719607355
commit
f693c3e30a
2 changed files with 22 additions and 10 deletions
|
|
@ -91,18 +91,22 @@ proc execAction*(cmd: string, retry = 0, die = true, cache = false,
|
||||||
# Else cache for preserving functionality in nimsuggest and nimcheck
|
# Else cache for preserving functionality in nimsuggest and nimcheck
|
||||||
let
|
let
|
||||||
hash = (ccmd & cacheKey).hash().abs()
|
hash = (ccmd & cacheKey).hash().abs()
|
||||||
cacheFile = getNimteropCacheDir() / "execCache" / "nimterop_" & $hash & ".txt"
|
cachePath = getNimteropCacheDir() / "execCache" / "nimterop_" & $hash
|
||||||
|
cacheFile = cachePath & ".txt"
|
||||||
|
retFile = cachePath & "_ret.txt"
|
||||||
|
|
||||||
when defined(nimsuggest) or defined(nimcheck):
|
when defined(nimsuggest) or defined(nimcheck):
|
||||||
# Load results from cache file if generated in previous run
|
# Load results from cache file if generated in previous run
|
||||||
if fileExists(cacheFile):
|
if fileExists(cacheFile) and fileExists(retFile):
|
||||||
result.output = cacheFile.readFile()
|
result.output = cacheFile.readFile()
|
||||||
|
result.ret = retFile.readFile().parseInt()
|
||||||
elif die:
|
elif die:
|
||||||
doAssert false, "Results not cached - run nim c/cpp at least once\n" & ccmd
|
doAssert false, "Results not cached - run nim c/cpp at least once\n" & ccmd
|
||||||
else:
|
else:
|
||||||
if cache and fileExists(cacheFile) and not compileOption("forceBuild"):
|
if cache and fileExists(cacheFile) and fileExists(retFile) and not compileOption("forceBuild"):
|
||||||
# Return from cache when requested
|
# Return from cache when requested
|
||||||
result.output = cacheFile.readFile()
|
result.output = cacheFile.readFile()
|
||||||
|
result.ret = retFile.readFile().parseInt()
|
||||||
else:
|
else:
|
||||||
# Execute command and store results in cache
|
# Execute command and store results in cache
|
||||||
(result.output, result.ret) = gorgeEx(ccmd)
|
(result.output, result.ret) = gorgeEx(ccmd)
|
||||||
|
|
@ -113,6 +117,7 @@ proc execAction*(cmd: string, retry = 0, die = true, cache = false,
|
||||||
let flag = when not defined(Windows): "-p" else: ""
|
let flag = when not defined(Windows): "-p" else: ""
|
||||||
discard execAction(&"mkdir {flag} {dir.sanitizePath}")
|
discard execAction(&"mkdir {flag} {dir.sanitizePath}")
|
||||||
cacheFile.writeFile(result.output)
|
cacheFile.writeFile(result.output)
|
||||||
|
retFile.writeFile($result.ret)
|
||||||
else:
|
else:
|
||||||
# Used by toast
|
# Used by toast
|
||||||
(result.output, result.ret) = execCmdEx(ccmd)
|
(result.output, result.ret) = execCmdEx(ccmd)
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,24 @@ proc getProjectDir*(): string =
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc stripName(path, projectName: string): string =
|
||||||
|
# Remove `pname_d|r` tail from path
|
||||||
|
let
|
||||||
|
(head, tail) = path.splitPath()
|
||||||
|
if projectName in tail:
|
||||||
|
result = head
|
||||||
|
else:
|
||||||
|
result = path
|
||||||
|
|
||||||
proc getNimcacheDir*(projectDir = ""): string =
|
proc getNimcacheDir*(projectDir = ""): string =
|
||||||
## Get nimcache directory for current compilation or specified `projectDir`
|
## Get nimcache directory for current compilation or specified `projectDir`
|
||||||
when nimvm:
|
when nimvm:
|
||||||
when (NimMajor, NimMinor, NimPatch) >= (1, 2, 0):
|
when (NimMajor, NimMinor, NimPatch) >= (1, 2, 0):
|
||||||
# Get value at compile time from `std/compilesettings`
|
# Get value at compile time from `std/compilesettings`
|
||||||
result = querySetting(SingleValueSetting.nimcacheDir)
|
result = stripName(
|
||||||
|
querySetting(SingleValueSetting.nimcacheDir),
|
||||||
|
querySetting(SingleValueSetting.projectName)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
@ -78,12 +90,7 @@ proc getNimcacheDir*(projectDir = ""): string =
|
||||||
dumpJson = getJson(projectDir)
|
dumpJson = getJson(projectDir)
|
||||||
|
|
||||||
if dumpJson != nil and dumpJson.hasKey("nimcache"):
|
if dumpJson != nil and dumpJson.hasKey("nimcache"):
|
||||||
result = dumpJson["nimcache"].getStr()
|
result = stripName(dumpJson["nimcache"].getStr(), "dummy")
|
||||||
let
|
|
||||||
(head, tail) = result.splitPath()
|
|
||||||
if "dummy" in tail:
|
|
||||||
# Remove `dummy_d` subdir when default nimcache
|
|
||||||
result = head
|
|
||||||
|
|
||||||
# Set to OS defaults if not detectable
|
# Set to OS defaults if not detectable
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue