Nimcache fixes, Std + fallback
This commit is contained in:
parent
6db698ea7a
commit
ff8c7330cd
2 changed files with 33 additions and 21 deletions
|
|
@ -824,6 +824,10 @@ macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: sta
|
|||
## This allows a single wrapper to be used in different ways depending on the user's needs.
|
||||
## If no `-d:xxx` defines are specified, `outdir` will be searched for the header as is.
|
||||
##
|
||||
## If multiple `-d:xxx` defines are specified, precedence is `Std` and then `Git` or `DL`.
|
||||
## This allows using a system installed library if available before falling back to manual
|
||||
## building.
|
||||
##
|
||||
## `-d:xxxSetVer=x.y.z` can be used to specify which version to use. It is used as a tag
|
||||
## name for Git whereas for DL, it replaces `$1` in the URL defined.
|
||||
##
|
||||
|
|
@ -912,26 +916,31 @@ macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: sta
|
|||
else:
|
||||
`lre` & getDynlibExt()
|
||||
|
||||
when `nameStd`:
|
||||
const
|
||||
`path`* = getStdPath(`header`)
|
||||
`lpath`* = getStdLibPath(`lname`)
|
||||
else:
|
||||
const
|
||||
`path`* =
|
||||
when `nameGit`:
|
||||
getGitPath(`header`, `giturl`, `outdir`, `version`)
|
||||
elif `nameDL`:
|
||||
getDlPath(`header`, `dlurl`, `outdir`, `version`)
|
||||
else:
|
||||
getLocalPath(`header`, `outdir`)
|
||||
stdPath =
|
||||
when `nameStd`: getStdPath(`header`) else: ""
|
||||
stdLPath =
|
||||
when `nameStd`: getStdLibPath(`lname`) else: ""
|
||||
|
||||
when declared(`preBuild`):
|
||||
static:
|
||||
`preBuild`(`outdir`, `path`)
|
||||
`path`* =
|
||||
when stdPath.len != 0:
|
||||
stdPath
|
||||
elif `nameGit`:
|
||||
getGitPath(`header`, `giturl`, `outdir`, `version`)
|
||||
elif `nameDL`:
|
||||
getDlPath(`header`, `dlurl`, `outdir`, `version`)
|
||||
else:
|
||||
getLocalPath(`header`, `outdir`)
|
||||
|
||||
const
|
||||
`lpath`* = buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`)
|
||||
when stdPath.len == 0 and declared(`preBuild`):
|
||||
static:
|
||||
`preBuild`(`outdir`, `path`)
|
||||
|
||||
const
|
||||
`lpath`* =
|
||||
when stdPath.len != 0 and stdLPath.len != 0:
|
||||
stdLPath
|
||||
else:
|
||||
buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`)
|
||||
|
||||
static:
|
||||
doAssert `path`.len != 0, "\nHeader " & `header` & " not found - " & "missing/empty outdir or -d:$1Std -d:$1Git or -d:$1DL not specified" % `name`
|
||||
|
|
|
|||
|
|
@ -107,9 +107,10 @@ proc getNimCheckError(output: string): tuple[tmpFile, errors: string] =
|
|||
let
|
||||
hash = output.hash().abs()
|
||||
|
||||
result.tmpFile = getProjectCacheDir("cPlugins", forceClean = false) / "nimterop_" & $hash & ".nim"
|
||||
result.tmpFile = getProjectCacheDir("failed", forceClean = false) / "nimterop_" & $hash & ".nim"
|
||||
|
||||
if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
|
||||
mkDir(result.tmpFile.parentDir())
|
||||
writeFile(result.tmpFile, output)
|
||||
|
||||
doAssert fileExists(result.tmpFile), "Failed to write to cache dir: " & result.tmpFile
|
||||
|
|
@ -278,9 +279,10 @@ macro cPlugin*(body): untyped =
|
|||
let
|
||||
data = "import macros, nimterop/plugin\n\n" & body.repr
|
||||
hash = data.hash().abs()
|
||||
path = getTempDir() / "nimterop_" & $hash & ".nim"
|
||||
path = getProjectCacheDir("cPlugins", forceClean = false) / "nimterop_" & $hash & ".nim"
|
||||
|
||||
if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
|
||||
mkDir(path.parentDir())
|
||||
writeFile(path, data)
|
||||
|
||||
doAssert fileExists(path), "Unable to write plugin file: " & path
|
||||
|
|
@ -575,11 +577,12 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
|
|||
let
|
||||
output = getToast(fullpath, recurse, dynlib, noNimout = true)
|
||||
hash = output.hash().abs()
|
||||
hpath = getTempDir() / "nimterop_" & $hash & ".h"
|
||||
hpath = getProjectCacheDir("c2nimCache", forceClean = false) / "nimterop_" & $hash & ".h"
|
||||
npath = hpath[0 .. hpath.rfind('.')] & "nim"
|
||||
header = ("header" & fullpath.splitFile().name.replace(re"[-.]+", ""))
|
||||
|
||||
if not fileExists(hpath) or gStateCT.nocache or compileOption("forceBuild"):
|
||||
mkDir(hpath.parentDir())
|
||||
writeFile(hpath, output)
|
||||
|
||||
doAssert fileExists(hpath), "Unable to write temporary header file: " & hpath
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue