aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-05-10 20:08:07 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-05-10 20:08:07 -0500
commitf693c3e30af162c2a2f377d8b540fe9c34e248fb (patch)
tree787af1c34a9c0515ea19918f4959e1ce8d45bab6
parent3719607355d7041d8f258280395b4830c9765f54 (diff)
downloadnimterop-f693c3e30af162c2a2f377d8b540fe9c34e248fb.tar.gz
nimterop-f693c3e30af162c2a2f377d8b540fe9c34e248fb.zip
Fix #209 - cache return val, fix nimcache dirv0.5.0issue209
-rw-r--r--nimterop/build.nim11
-rw-r--r--nimterop/nimconf.nim21
2 files changed, 22 insertions, 10 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim
index 48557f3..b02132d 100644
--- a/nimterop/build.nim
+++ b/nimterop/build.nim
@@ -91,18 +91,22 @@ proc execAction*(cmd: string, retry = 0, die = true, cache = false,
# Else cache for preserving functionality in nimsuggest and nimcheck
let
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):
# Load results from cache file if generated in previous run
- if fileExists(cacheFile):
+ if fileExists(cacheFile) and fileExists(retFile):
result.output = cacheFile.readFile()
+ result.ret = retFile.readFile().parseInt()
elif die:
doAssert false, "Results not cached - run nim c/cpp at least once\n" & ccmd
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
result.output = cacheFile.readFile()
+ result.ret = retFile.readFile().parseInt()
else:
# Execute command and store results in cache
(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: ""
discard execAction(&"mkdir {flag} {dir.sanitizePath}")
cacheFile.writeFile(result.output)
+ retFile.writeFile($result.ret)
else:
# Used by toast
(result.output, result.ret) = execCmdEx(ccmd)
diff --git a/nimterop/nimconf.nim b/nimterop/nimconf.nim
index dca68a8..2a54d7e 100644
--- a/nimterop/nimconf.nim
+++ b/nimterop/nimconf.nim
@@ -58,12 +58,24 @@ proc getProjectDir*(): string =
else:
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 =
## Get nimcache directory for current compilation or specified `projectDir`
when nimvm:
when (NimMajor, NimMinor, NimPatch) >= (1, 2, 0):
# Get value at compile time from `std/compilesettings`
- result = querySetting(SingleValueSetting.nimcacheDir)
+ result = stripName(
+ querySetting(SingleValueSetting.nimcacheDir),
+ querySetting(SingleValueSetting.projectName)
+ )
else:
discard
@@ -78,12 +90,7 @@ proc getNimcacheDir*(projectDir = ""): string =
dumpJson = getJson(projectDir)
if dumpJson != nil and dumpJson.hasKey("nimcache"):
- result = dumpJson["nimcache"].getStr()
- let
- (head, tail) = result.splitPath()
- if "dummy" in tail:
- # Remove `dummy_d` subdir when default nimcache
- result = head
+ result = stripName(dumpJson["nimcache"].getStr(), "dummy")
# Set to OS defaults if not detectable
if result.len == 0: