diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-19 02:03:14 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-19 02:03:14 -0600 |
| commit | 7bc53080e8c2d185dd7e0289ec2829e65643f6b9 (patch) | |
| tree | 374d7a687207fb377284f248d31653e0246f908c | |
| parent | abbd08d6de602d0d66457509a1c1714e5a529dd2 (diff) | |
| download | nimterop-7bc53080e8c2d185dd7e0289ec2829e65643f6b9.tar.gz nimterop-7bc53080e8c2d185dd7e0289ec2829e65643f6b9.zip | |
Caching cImport content
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | nimterop/cimport.nim | 16 |
2 files changed, 16 insertions, 2 deletions
@@ -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 |
