Nimcache fixes, Std + fallback

This commit is contained in:
Ganesh Viswanathan 2019-10-10 09:33:09 -05:00
commit ff8c7330cd
2 changed files with 33 additions and 21 deletions

View file

@ -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. ## 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 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 ## `-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. ## 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: else:
`lre` & getDynlibExt() `lre` & getDynlibExt()
when `nameStd`: stdPath =
const when `nameStd`: getStdPath(`header`) else: ""
`path`* = getStdPath(`header`) stdLPath =
`lpath`* = getStdLibPath(`lname`) when `nameStd`: getStdLibPath(`lname`) else: ""
else:
const
`path`* =
when `nameGit`:
getGitPath(`header`, `giturl`, `outdir`, `version`)
elif `nameDL`:
getDlPath(`header`, `dlurl`, `outdir`, `version`)
else:
getLocalPath(`header`, `outdir`)
when declared(`preBuild`): `path`* =
static: when stdPath.len != 0:
`preBuild`(`outdir`, `path`) stdPath
elif `nameGit`:
getGitPath(`header`, `giturl`, `outdir`, `version`)
elif `nameDL`:
getDlPath(`header`, `dlurl`, `outdir`, `version`)
else:
getLocalPath(`header`, `outdir`)
const when stdPath.len == 0 and declared(`preBuild`):
`lpath`* = buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`) static:
`preBuild`(`outdir`, `path`)
const
`lpath`* =
when stdPath.len != 0 and stdLPath.len != 0:
stdLPath
else:
buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`)
static: static:
doAssert `path`.len != 0, "\nHeader " & `header` & " not found - " & "missing/empty outdir or -d:$1Std -d:$1Git or -d:$1DL not specified" % `name` doAssert `path`.len != 0, "\nHeader " & `header` & " not found - " & "missing/empty outdir or -d:$1Std -d:$1Git or -d:$1DL not specified" % `name`

View file

@ -107,9 +107,10 @@ proc getNimCheckError(output: string): tuple[tmpFile, errors: string] =
let let
hash = output.hash().abs() 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"): if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
mkDir(result.tmpFile.parentDir())
writeFile(result.tmpFile, output) writeFile(result.tmpFile, output)
doAssert fileExists(result.tmpFile), "Failed to write to cache dir: " & result.tmpFile doAssert fileExists(result.tmpFile), "Failed to write to cache dir: " & result.tmpFile
@ -278,9 +279,10 @@ macro cPlugin*(body): untyped =
let let
data = "import macros, nimterop/plugin\n\n" & body.repr data = "import macros, nimterop/plugin\n\n" & body.repr
hash = data.hash().abs() 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"): if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
mkDir(path.parentDir())
writeFile(path, data) writeFile(path, data)
doAssert fileExists(path), "Unable to write plugin file: " & path doAssert fileExists(path), "Unable to write plugin file: " & path
@ -575,11 +577,12 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
let let
output = getToast(fullpath, recurse, dynlib, noNimout = true) output = getToast(fullpath, recurse, dynlib, noNimout = true)
hash = output.hash().abs() hash = output.hash().abs()
hpath = getTempDir() / "nimterop_" & $hash & ".h" hpath = getProjectCacheDir("c2nimCache", forceClean = false) / "nimterop_" & $hash & ".h"
npath = hpath[0 .. hpath.rfind('.')] & "nim" npath = hpath[0 .. hpath.rfind('.')] & "nim"
header = ("header" & fullpath.splitFile().name.replace(re"[-.]+", "")) header = ("header" & fullpath.splitFile().name.replace(re"[-.]+", ""))
if not fileExists(hpath) or gStateCT.nocache or compileOption("forceBuild"): if not fileExists(hpath) or gStateCT.nocache or compileOption("forceBuild"):
mkDir(hpath.parentDir())
writeFile(hpath, output) writeFile(hpath, output)
doAssert fileExists(hpath), "Unable to write temporary header file: " & hpath doAssert fileExists(hpath), "Unable to write temporary header file: " & hpath