Caching fixes, wchar_t

This commit is contained in:
Ganesh Viswanathan 2020-07-13 17:47:17 -05:00
commit 27fcecaa26
2 changed files with 39 additions and 7 deletions

View file

@ -142,15 +142,35 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
for fullpath in fullpaths:
cmd.add &" {fullpath.sanitizePath}"
result = if outFile.nBl: fixRelFile(outFile) else:
# Generate filename for toast output if not specified
getNimteropCacheDir() / "toastCache" / "nimterop_" &
let
cacheFile = getNimteropCacheDir() / "toastCache" / "nimterop_" &
($(cmd & cacheKey).hash().abs()).addFileExt(ext)
if outFile.nBl:
result = fixRelFile(outFile)
else:
result = cacheFile
when defined(Windows):
result = result.replace(DirSep, '/')
if not fileExists(result) or gStateCT.nocache or compileOption("forceBuild"):
let
# When to regenerate the wrapper
regen =
if gStateCT.nocache or compileOption("forceBuild"):
# No caching or forced
true
elif not fileExists(result):
# Cache or outfile doesn't exist
true
elif outFile.nBl and (not fileExists(cacheFile) or
result.getFileDate() > cacheFile.getFileDate()):
# Outfile exists but cache doesn't or outdated
true
else:
false
if regen:
let
dir = result.parentDir()
if not dirExists(dir):
@ -160,7 +180,19 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
var
(output, ret) = execAction(cmd, die = false)
doAssert ret == 0, "\n\n" & (if result.fileExists(): result.readFile() else: "") & output
if ret != 0:
# If toast fails, print failure to output and delete any generated files
let errout = if result.fileExists(): result.readFile() & output else: output
rmFile(result)
doAssert false, "\n\n" & errout & "\n"
# Write empty cache file to track changes when outFile specified
if outFile.nBl:
let dir = cacheFile.parentDir()
if not dirExists(dir):
mkdir(dir)
writeFile(cacheFile, "")
macro cOverride*(body): untyped =
## When the wrapper code generated by nimterop is missing certain symbols or not

View file

@ -139,7 +139,7 @@ when defined(cpp):
# not defined in <cwchar> nor any other header).
type wchar_t* {.importc.} = object
else:
type wchar_t* {.importc, header:"<cwchar>".} = object
type wchar_t* {.importc, header:"stddef.h".} = object
""",
"va_list": """
@ -417,4 +417,4 @@ proc expandSymlinkAbs*(path: string): string =
result = path.expandFilename().normalizedPath()
except:
result = path
result = result.sanitizePath(noQuote = true)
result = result.sanitizePath(noQuote = true)