Skip to content

Commit 27fceca

Browse files
committed
Caching fixes, wchar_t
1 parent d7c94bb commit 27fceca

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

nimterop/cimport.nim

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,35 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
142142
for fullpath in fullpaths:
143143
cmd.add &" {fullpath.sanitizePath}"
144144
145-
result = if outFile.nBl: fixRelFile(outFile) else:
146-
# Generate filename for toast output if not specified
147-
getNimteropCacheDir() / "toastCache" / "nimterop_" &
145+
let
146+
cacheFile = getNimteropCacheDir() / "toastCache" / "nimterop_" &
148147
($(cmd & cacheKey).hash().abs()).addFileExt(ext)
149148
149+
if outFile.nBl:
150+
result = fixRelFile(outFile)
151+
else:
152+
result = cacheFile
153+
150154
when defined(Windows):
151155
result = result.replace(DirSep, '/')
152156
153-
if not fileExists(result) or gStateCT.nocache or compileOption("forceBuild"):
157+
let
158+
# When to regenerate the wrapper
159+
regen =
160+
if gStateCT.nocache or compileOption("forceBuild"):
161+
# No caching or forced
162+
true
163+
elif not fileExists(result):
164+
# Cache or outfile doesn't exist
165+
true
166+
elif outFile.nBl and (not fileExists(cacheFile) or
167+
result.getFileDate() > cacheFile.getFileDate()):
168+
# Outfile exists but cache doesn't or outdated
169+
true
170+
else:
171+
false
172+
173+
if regen:
154174
let
155175
dir = result.parentDir()
156176
if not dirExists(dir):
@@ -160,7 +180,19 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
160180
161181
var
162182
(output, ret) = execAction(cmd, die = false)
163-
doAssert ret == 0, "\n\n" & (if result.fileExists(): result.readFile() else: "") & output
183+
if ret != 0:
184+
# If toast fails, print failure to output and delete any generated files
185+
let errout = if result.fileExists(): result.readFile() & output else: output
186+
rmFile(result)
187+
doAssert false, "\n\n" & errout & "\n"
188+
189+
# Write empty cache file to track changes when outFile specified
190+
if outFile.nBl:
191+
let dir = cacheFile.parentDir()
192+
if not dirExists(dir):
193+
mkdir(dir)
194+
195+
writeFile(cacheFile, "")
164196
165197
macro cOverride*(body): untyped =
166198
## When the wrapper code generated by nimterop is missing certain symbols or not

nimterop/toastlib/getters.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ when defined(cpp):
139139
# not defined in <cwchar> nor any other header).
140140
type wchar_t* {.importc.} = object
141141
else:
142-
type wchar_t* {.importc, header:"<cwchar>".} = object
142+
type wchar_t* {.importc, header:"stddef.h".} = object
143143
""",
144144

145145
"va_list": """
@@ -417,4 +417,4 @@ proc expandSymlinkAbs*(path: string): string =
417417
result = path.expandFilename().normalizedPath()
418418
except:
419419
result = path
420-
result = result.sanitizePath(noQuote = true)
420+
result = result.sanitizePath(noQuote = true)

0 commit comments

Comments
 (0)