Support cache disabling
This commit is contained in:
parent
23a93e1d42
commit
c89a741095
8 changed files with 30 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ type
|
|||
mingw_dbl_type_t = object
|
||||
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
|
||||
cAddStdDir()
|
||||
cImport cSearchPath("math.h")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import std/unittest
|
|||
import nimterop/cimport
|
||||
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
|
||||
cDefine("FORCE")
|
||||
cIncludeDir "$projpath/include"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import nimterop/cimport
|
|||
import unittest
|
||||
|
||||
cDebug()
|
||||
cDisableCaching()
|
||||
|
||||
cIncludeDir "$projpath/include"
|
||||
cAddSearchDir "$projpath/include"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue