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
|
`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".}`
|
`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".}`
|
`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
|
`cImport("header.h", recurse=true)` - import all supported definitions from header file and #includes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@ proc execCmd(cmd: string) =
|
||||||
exec cmd
|
exec cmd
|
||||||
|
|
||||||
proc tsoloud() =
|
proc tsoloud() =
|
||||||
execCmd "nim c --forceBuild -r tests/tsoloud.nim"
|
execCmd "nim c -r tests/tsoloud.nim"
|
||||||
execCmd "nim cpp -r tests/tsoloud.nim"
|
execCmd "nim cpp -r tests/tsoloud.nim"
|
||||||
|
|
||||||
task test, "Test":
|
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 -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):
|
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"
|
execCmd "nim cpp -r tests/tmath.nim"
|
||||||
when not defined(OSX):
|
when not defined(OSX):
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,10 @@ proc getFileDate(fullpath: string): string =
|
||||||
|
|
||||||
doAssert ret == 0, "File date error: " & fullpath & "\n" & result
|
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 =
|
proc getToastError(output: string): string =
|
||||||
# Filter out preprocessor errors
|
# Filter out preprocessor errors
|
||||||
for line in output.splitLines():
|
for line in output.splitLines():
|
||||||
|
|
@ -97,7 +101,7 @@ proc getToast(fullpath: string, recurse: bool = false): string =
|
||||||
|
|
||||||
cmd.add &"{fullpath.quoteShell}"
|
cmd.add &"{fullpath.quoteShell}"
|
||||||
echo cmd
|
echo cmd
|
||||||
(result, ret) = gorgeEx(cmd, cache=getFileDate(fullpath))
|
(result, ret) = gorgeEx(cmd, cache=getCacheValue(fullpath))
|
||||||
doAssert ret == 0, getToastError(result)
|
doAssert ret == 0, getToastError(result)
|
||||||
|
|
||||||
proc getGccPaths(mode = "c"): string =
|
proc getGccPaths(mode = "c"): string =
|
||||||
|
|
@ -131,6 +135,17 @@ macro cDebug*(): untyped =
|
||||||
|
|
||||||
gStateCT.debug = true
|
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 =
|
macro cDefine*(name: static string, val: static string = ""): untyped =
|
||||||
## ``#define`` an identifer that is forwarded to the C/C++ compiler
|
## ``#define`` an identifer that is forwarded to the C/C++ compiler
|
||||||
## using ``{.passC: "-DXXX".}``
|
## 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 =
|
macro cImport*(filename: static string, recurse: static bool = false): untyped =
|
||||||
## Import all supported definitions from specified header file. Generated
|
## Import all supported definitions from specified header file. Generated
|
||||||
## content is cached in ``nimcache`` until ``filename`` changes. If files
|
## content is cached in ``nimcache`` until ``filename`` changes unless
|
||||||
## imported by ``filename`` change and affect the generated content, use
|
## ``cDisableCaching()`` is set.
|
||||||
## ``nim -f`` to force regeneration of Nim code.
|
|
||||||
##
|
##
|
||||||
## ``recurse`` can be used to generate Nim wrappers from ``#include`` files
|
## ``recurse`` can be used to generate Nim wrappers from ``#include`` files
|
||||||
## referenced in ``filename``. This is only done for files in the same
|
## referenced in ``filename``. This is only done for files in the same
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ type
|
||||||
State = object
|
State = object
|
||||||
compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string]
|
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]
|
consts*, enums*, procs*, types*: HashSet[string]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type
|
||||||
mingw_dbl_type_t = object
|
mingw_dbl_type_t = object
|
||||||
|
|
||||||
cDebug()
|
cDebug()
|
||||||
|
cDisableCaching()
|
||||||
|
|
||||||
cAddStdDir()
|
cAddStdDir()
|
||||||
cImport cSearchPath("math.h")
|
cImport cSearchPath("math.h")
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import std/unittest
|
||||||
import nimterop/cimport
|
import nimterop/cimport
|
||||||
|
|
||||||
cDebug()
|
cDebug()
|
||||||
|
cDisableCaching()
|
||||||
|
|
||||||
cDefine("FORCE")
|
cDefine("FORCE")
|
||||||
cIncludeDir "$projpath/include"
|
cIncludeDir "$projpath/include"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import nimterop/cimport
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
cDebug()
|
cDebug()
|
||||||
|
cDisableCaching()
|
||||||
|
|
||||||
cIncludeDir "$projpath/include"
|
cIncludeDir "$projpath/include"
|
||||||
cAddSearchDir "$projpath/include"
|
cAddSearchDir "$projpath/include"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import os, nimterop/[cimport, git]
|
||||||
gitPull("https://github.com/jarikomppa/soloud", "soloud", "include/*\nsrc/*\n")
|
gitPull("https://github.com/jarikomppa/soloud", "soloud", "include/*\nsrc/*\n")
|
||||||
|
|
||||||
cDebug()
|
cDebug()
|
||||||
|
cDisableCaching()
|
||||||
|
|
||||||
const
|
const
|
||||||
inc = "soloud/include"
|
inc = "soloud/include"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue