Caching cImport content

This commit is contained in:
Ganesh Viswanathan 2019-01-19 02:03:14 -06:00
commit 7bc53080e8
2 changed files with 16 additions and 2 deletions

View file

@ -59,7 +59,7 @@ Detailed documentation is still forthcoming.
`cIncludeDir("XXX")` - add an include directory that is forwarded to the compiler using `{.passC: "-IXXX".}`
`cImport("header.h")` - import all supported definitions from header file
`cImport("header.h")` - import all supported definitions from header file. Output is cached in nimcache unless header.h changes or by using `nim -f`
`cImport("header.h", recurse=true)` - import all supported definitions from header file and #includes

View file

@ -53,6 +53,20 @@ proc walkDirImpl(indir, inext: string, file=true): seq[string] =
if ret == 0:
result = output.splitLines()
proc getFileDate(fullpath: string): string =
var
ret = 0
cmd =
when defined(Windows):
&"cmd /c for %a in ({fullpath.quoteShell}) do echo %~ta"
else:
&"stat -c %y {fullpath.quoteShell}"
(result, ret) = gorgeEx(cmd)
if ret != 0:
doAssert false, "File date error: " & fullpath & "\n" & result
proc getToast(fullpath: string, recurse: bool = false): string =
var
cmd = when defined(Windows): "cmd /c " else: ""
@ -70,7 +84,7 @@ proc getToast(fullpath: string, recurse: bool = false): string =
cmd.add &"{fullpath.quoteShell}"
echo cmd
var (output, exitCode) = gorgeEx(cmd)
var (output, exitCode) = gorgeEx(cmd, cache=getFileDate(fullpath))
doAssert exitCode == 0, $exitCode
result = output