aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-19 02:03:14 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-19 02:03:14 -0600
commit7bc53080e8c2d185dd7e0289ec2829e65643f6b9 (patch)
tree374d7a687207fb377284f248d31653e0246f908c
parentabbd08d6de602d0d66457509a1c1714e5a529dd2 (diff)
downloadnimterop-7bc53080e8c2d185dd7e0289ec2829e65643f6b9.tar.gz
nimterop-7bc53080e8c2d185dd7e0289ec2829e65643f6b9.zip
Caching cImport content
-rw-r--r--README.md2
-rw-r--r--nimterop/cimport.nim16
2 files changed, 16 insertions, 2 deletions
diff --git a/README.md b/README.md
index a4d3098..147daf1 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim
index 2ff6251..ce21af2 100644
--- a/nimterop/cimport.nim
+++ b/nimterop/cimport.nim
@@ -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