aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-21 01:35:42 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-21 01:35:42 -0600
commitc89a741095a4ed4858ea41eee6c412c3fea2e68e (patch)
tree003e6e31bae1b25038e5c836cbe1d47644a22b35
parent23a93e1d4266ee7982f629be00b8fa0390d79dce (diff)
downloadnimterop-c89a741095a4ed4858ea41eee6c412c3fea2e68e.tar.gz
nimterop-c89a741095a4ed4858ea41eee6c412c3fea2e68e.zip
Support cache disabling
-rw-r--r--README.md4
-rw-r--r--nimterop.nimble8
-rw-r--r--nimterop/cimport.nim22
-rw-r--r--nimterop/globals.nim2
-rw-r--r--tests/tmath.nim1
-rw-r--r--tests/tnimterop_c.nim1
-rw-r--r--tests/tnimterop_cpp.nim1
-rw-r--r--tests/tsoloud.nim1
8 files changed, 30 insertions, 10 deletions
diff --git a/README.md b/README.md
index 74b5848..07a6ec5 100644
--- a/README.md
+++ b/README.md
@@ -55,11 +55,13 @@ Documentation can be found [here](https://genotrance.github.io/nimterop/cimport.
`cDebug()` - enable debug messages
+`cDisableCaching()` - disable caching of generated Nim content from `cImport()`
+
`cDefine("XXX")` - `#define` an identifer that is forwarded to the C/C++ compiler using `{.passC: "-DXXX".}`
`cIncludeDir("XXX")` - add an include directory that is forwarded to the C/C++ compiler using `{.passC: "-IXXX".}`
-`cImport("header.h")` - Import all supported definitions from specified header file. Generated content is cached in `nimcache` until `header.h` changes. If files imported by `header.h` change and affect the generated content, use `nim -f` to force regeneration of Nim code.
+`cImport("header.h")` - Import all supported definitions from specified header file. Generated content is cached in `nimcache` until `header.h` changes
`cImport("header.h", recurse=true)` - import all supported definitions from header file and #includes
diff --git a/nimterop.nimble b/nimterop.nimble
index 16a7100..d72ab8d 100644
--- a/nimterop.nimble
+++ b/nimterop.nimble
@@ -17,15 +17,15 @@ proc execCmd(cmd: string) =
exec cmd
proc tsoloud() =
- execCmd "nim c --forceBuild -r tests/tsoloud.nim"
+ execCmd "nim c -r tests/tsoloud.nim"
execCmd "nim cpp -r tests/tsoloud.nim"
task test, "Test":
- execCmd "nim c -f -r tests/tnimterop_c.nim"
+ execCmd "nim c -r tests/tnimterop_c.nim"
execCmd "nim cpp -r tests/tnimterop_c.nim"
- execCmd "nim cpp -f -r tests/tnimterop_cpp.nim"
+ execCmd "nim cpp -r tests/tnimterop_cpp.nim"
when defined(windows):
- execCmd "nim c -f -r tests/tmath.nim"
+ execCmd "nim c -r tests/tmath.nim"
execCmd "nim cpp -r tests/tmath.nim"
when not defined(OSX):
when defined(Windows):
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim
index bb8ce03..beaaeb2 100644
--- a/nimterop/cimport.nim
+++ b/nimterop/cimport.nim
@@ -69,6 +69,10 @@ proc getFileDate(fullpath: string): string =
doAssert ret == 0, "File date error: " & fullpath & "\n" & result
+proc getCacheValue(fullpath: string): string =
+ if not gStateCT.nocache:
+ result = fullpath.getFileDate()
+
proc getToastError(output: string): string =
# Filter out preprocessor errors
for line in output.splitLines():
@@ -97,7 +101,7 @@ proc getToast(fullpath: string, recurse: bool = false): string =
cmd.add &"{fullpath.quoteShell}"
echo cmd
- (result, ret) = gorgeEx(cmd, cache=getFileDate(fullpath))
+ (result, ret) = gorgeEx(cmd, cache=getCacheValue(fullpath))
doAssert ret == 0, getToastError(result)
proc getGccPaths(mode = "c"): string =
@@ -131,6 +135,17 @@ macro cDebug*(): untyped =
gStateCT.debug = true
+macro cDisableCaching*(): untyped =
+ ## Disable caching of generated Nim code - useful during wrapper development
+ ##
+ ## If files included by header bring processed by ``cImport()`` change and affect
+ ## the generated content, ``cImport()`` won't detect the change and use the cached
+ ## value. Use ``cDisableCaching()`` to avoid this scenario.
+ ##
+ ## ``nim -f`` is currently broken but will eventually allow forcing regeneration.
+
+ gStateCT.nocache = true
+
macro cDefine*(name: static string, val: static string = ""): untyped =
## ``#define`` an identifer that is forwarded to the C/C++ compiler
## using ``{.passC: "-DXXX".}``
@@ -282,9 +297,8 @@ macro cCompile*(path: static string, mode = "c"): untyped =
macro cImport*(filename: static string, recurse: static bool = false): untyped =
## Import all supported definitions from specified header file. Generated
- ## content is cached in ``nimcache`` until ``filename`` changes. If files
- ## imported by ``filename`` change and affect the generated content, use
- ## ``nim -f`` to force regeneration of Nim code.
+ ## content is cached in ``nimcache`` until ``filename`` changes unless
+ ## ``cDisableCaching()`` is set.
##
## ``recurse`` can be used to generate Nim wrappers from ``#include`` files
## referenced in ``filename``. This is only done for files in the same
diff --git a/nimterop/globals.nim b/nimterop/globals.nim
index 11882a7..1a96aa3 100644
--- a/nimterop/globals.nim
+++ b/nimterop/globals.nim
@@ -48,7 +48,7 @@ type
State = object
compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string]
- debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool
+ nocache*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool
consts*, enums*, procs*, types*: HashSet[string]
diff --git a/tests/tmath.nim b/tests/tmath.nim
index d5a7166..f32a1f5 100644
--- a/tests/tmath.nim
+++ b/tests/tmath.nim
@@ -7,6 +7,7 @@ type
mingw_dbl_type_t = object
cDebug()
+cDisableCaching()
cAddStdDir()
cImport cSearchPath("math.h")
diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim
index 2218256..7123c80 100644
--- a/tests/tnimterop_c.nim
+++ b/tests/tnimterop_c.nim
@@ -2,6 +2,7 @@ import std/unittest
import nimterop/cimport
cDebug()
+cDisableCaching()
cDefine("FORCE")
cIncludeDir "$projpath/include"
diff --git a/tests/tnimterop_cpp.nim b/tests/tnimterop_cpp.nim
index bed052c..a556818 100644
--- a/tests/tnimterop_cpp.nim
+++ b/tests/tnimterop_cpp.nim
@@ -2,6 +2,7 @@ import nimterop/cimport
import unittest
cDebug()
+cDisableCaching()
cIncludeDir "$projpath/include"
cAddSearchDir "$projpath/include"
diff --git a/tests/tsoloud.nim b/tests/tsoloud.nim
index 544c1af..6d3028d 100644
--- a/tests/tsoloud.nim
+++ b/tests/tsoloud.nim
@@ -3,6 +3,7 @@ import os, nimterop/[cimport, git]
gitPull("https://github.com/jarikomppa/soloud", "soloud", "include/*\nsrc/*\n")
cDebug()
+cDisableCaching()
const
inc = "soloud/include"