@@ -142,15 +142,35 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
142
142
for fullpath in fullpaths:
143
143
cmd.add & " { fullpath.sanitizePath} "
144
144
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_" &
148
147
($ (cmd & cacheKey).hash().abs()).addFileExt(ext)
149
148
149
+ if outFile.nBl:
150
+ result = fixRelFile(outFile)
151
+ else :
152
+ result = cacheFile
153
+
150
154
when defined(Windows):
151
155
result = result .replace(DirSep, '/' )
152
156
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:
154
174
let
155
175
dir = result .parentDir()
156
176
if not dirExists(dir):
@@ -160,7 +180,19 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
160
180
161
181
var
162
182
(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, " " )
164
196
165
197
macro cOverride* (body): untyped =
166
198
# # When the wrapper code generated by nimterop is missing certain symbols or not
0 commit comments