Move all artifacts to nimcache
This commit is contained in:
parent
f2a0d4b0c9
commit
6db698ea7a
14 changed files with 80 additions and 54 deletions
|
|
@ -21,10 +21,13 @@ proc execCmd(cmd: string) =
|
|||
exec cmd
|
||||
|
||||
proc execTest(test: string) =
|
||||
execCmd "nim c -r " & test
|
||||
execCmd "nim c -f -r " & test
|
||||
execCmd "nim cpp -r " & test
|
||||
|
||||
task buildToast, "build toast":
|
||||
execCmd("nim c -f -d:danger nimterop/toast.nim")
|
||||
|
||||
task bt, "build toast":
|
||||
execCmd("nim c -d:danger nimterop/toast.nim")
|
||||
|
||||
task docs, "Generate docs":
|
||||
|
|
@ -34,7 +37,7 @@ task test, "Test":
|
|||
buildToastTask()
|
||||
|
||||
execTest "tests/tnimterop_c.nim"
|
||||
execCmd "nim cpp -r tests/tnimterop_cpp.nim"
|
||||
execCmd "nim cpp -f -r tests/tnimterop_cpp.nim"
|
||||
execTest "tests/tpcre.nim"
|
||||
|
||||
# Platform specific tests
|
||||
|
|
|
|||
|
|
@ -110,9 +110,45 @@ proc rmFile*(source: string, dir = false) =
|
|||
|
||||
discard execAction(&"{cmd} {source.sanitizePath}", retry = 2)
|
||||
|
||||
proc rmDir*(source: string) =
|
||||
proc rmDir*(dir: string) =
|
||||
## Remove a directory or pattern at compile time
|
||||
rmFile(source, dir = true)
|
||||
rmFile(dir, dir = true)
|
||||
|
||||
proc getOsCacheDir(): string =
|
||||
when defined(posix):
|
||||
result = getEnv("XDG_CACHE_HOME", getHomeDir() / ".cache") / "nim"
|
||||
else:
|
||||
result = getHomeDir() / "nimcache"
|
||||
|
||||
proc getNimteropCacheDir(): string =
|
||||
result = getOsCacheDir() / "nimterop"
|
||||
|
||||
proc getProjectCacheDir*(name: string, forceClean = true): string =
|
||||
## Get a cache directory where all nimterop artifacts can be stored
|
||||
##
|
||||
## Projects can use this location to download source code and build binaries
|
||||
## that can be then accessed by multiple apps. This is created under the
|
||||
## per-user Nim cache directory.
|
||||
##
|
||||
## Use `name` to specify the subdirectory name for a project.
|
||||
##
|
||||
## `forceClean` is enabled by default and effectively deletes the folder
|
||||
## if Nim is compiled with the `-f` or `--forceBuild` flag. This allows
|
||||
## any project to start out with a clean cache dir on a forced build.
|
||||
##
|
||||
## NOTE: avoid calling `getProjectCacheDir()` multiple times on the same
|
||||
## `name` when `forceClean = true` else checked out source might get deleted
|
||||
## at the wrong time during build.
|
||||
##
|
||||
## E.g.
|
||||
## `nimgit2` downloads `libgit2` source so `name = "libgit2"`
|
||||
##
|
||||
## `nimarchive` downloads `libarchive`, `bzlib`, `liblzma` and `zlib` so
|
||||
## `name = "nimarchive" / "libarchive"` for `libarchive`, etc.
|
||||
result = getNimteropCacheDir() / name
|
||||
|
||||
if forceClean and compileOption("forceBuild"):
|
||||
rmDir(result)
|
||||
|
||||
proc extractZip*(zipfile, outdir: string) =
|
||||
## Extract a zip file using `powershell` on Windows and `unzip` on other
|
||||
|
|
|
|||
|
|
@ -107,12 +107,12 @@ proc getNimCheckError(output: string): tuple[tmpFile, errors: string] =
|
|||
let
|
||||
hash = output.hash().abs()
|
||||
|
||||
result.tmpFile = getTempDir() / "nimterop_" & $hash & ".nim"
|
||||
result.tmpFile = getProjectCacheDir("cPlugins", forceClean = false) / "nimterop_" & $hash & ".nim"
|
||||
|
||||
if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
|
||||
writeFile(result.tmpFile, output)
|
||||
|
||||
doAssert fileExists(result.tmpFile), "Bad codegen - unable to write to TEMP: " & result.tmpFile
|
||||
doAssert fileExists(result.tmpFile), "Failed to write to cache dir: " & result.tmpFile
|
||||
|
||||
let
|
||||
nim =
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
import os
|
||||
|
||||
import "."/build
|
||||
|
||||
const
|
||||
cacheDir* = getProjectCacheDir("nimterop")
|
||||
|
||||
proc nimteropRoot*(): string =
|
||||
currentSourcePath.parentDir.parentDir
|
||||
|
||||
proc nimteropBuildDir*(): string =
|
||||
## all nimterop generated files go under here (gitignored)
|
||||
nimteropRoot() / "build"
|
||||
|
||||
proc nimteropSrcDir*(): string =
|
||||
nimteropRoot() / "nimterop"
|
||||
|
||||
proc toastExePath*(): string =
|
||||
nimteropSrcDir() / ("toast".addFileExt ExeExt)
|
||||
|
||||
proc incDir*(): string =
|
||||
nimteropBuildDir() / "inc"
|
||||
|
||||
proc testsIncludeDir*(): string =
|
||||
nimteropRoot() / "tests" / "include"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,24 +3,24 @@ import os, strutils
|
|||
import "."/[build, paths]
|
||||
|
||||
proc treesitterSetup*() =
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter", incDir() / "treesitter", """
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter", cacheDir / "treesitter", """
|
||||
lib/include/*
|
||||
lib/src/*
|
||||
""", "0.15.5")
|
||||
|
||||
gitPull("https://github.com/JuliaStrings/utf8proc", incDir() / "utf8proc", """
|
||||
gitPull("https://github.com/JuliaStrings/utf8proc", cacheDir / "utf8proc", """
|
||||
*.c
|
||||
*.h
|
||||
""")
|
||||
|
||||
let
|
||||
tbase = incDir() / "treesitter/lib"
|
||||
stack = tbase / "src/stack.c"
|
||||
parser = tbase / "include/tree_sitter/parser.h"
|
||||
tbase = cacheDir / "treesitter" / "lib"
|
||||
stack = tbase / "src" / "stack.c"
|
||||
parser = tbase / "include" / "tree_sitter" / "parser.h"
|
||||
tparser = parser.replace("parser", "tparser")
|
||||
language = tbase / "src/language.h"
|
||||
lexer = tbase / "src/lexer.h"
|
||||
subtree = tbase / "src/subtree.h"
|
||||
language = tbase / "src" / "language.h"
|
||||
lexer = tbase / "src" / "lexer.h"
|
||||
subtree = tbase / "src" / "subtree.h"
|
||||
|
||||
stack.writeFile(stack.readFile().replace("inline Stack", "Stack"))
|
||||
|
||||
|
|
@ -31,31 +31,25 @@ lib/src/*
|
|||
subtree.writeFile(subtree.readFile().replace("parser.h", "tparser.h"))
|
||||
|
||||
proc treesitterCSetup*() =
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter-c", incDir() / "treesitter_c", """
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter-c", cacheDir / "treesitter_c", """
|
||||
src/*.h
|
||||
src/*.c
|
||||
src/*.cc
|
||||
src/tree_sitter/parser.h
|
||||
""", "v0.15.0")
|
||||
|
||||
let
|
||||
headerc = incDir() / "treesitter_c/src/api.h"
|
||||
|
||||
headerc.writeFile("""
|
||||
writeFile(cacheDir / "treesitter_c" / "src" / "api.h", """
|
||||
const TSLanguage *tree_sitter_c();
|
||||
""")
|
||||
|
||||
proc treesitterCppSetup*() =
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter-cpp", incDir() / "treesitter_cpp", """
|
||||
gitPull("https://github.com/tree-sitter/tree-sitter-cpp", cacheDir / "treesitter_cpp", """
|
||||
src/*.h
|
||||
src/*.c
|
||||
src/*.cc
|
||||
src/tree_sitter/parser.h
|
||||
""", "v0.15.0")
|
||||
|
||||
let
|
||||
headercpp = incDir() / "treesitter_cpp/src/api.h"
|
||||
|
||||
headercpp.writeFile("""
|
||||
writeFile(cacheDir / "treesitter_cpp" / "src" / "api.h", """
|
||||
const TSLanguage *tree_sitter_cpp();
|
||||
""")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import ".."/[setup, paths, types]
|
|||
static:
|
||||
treesitterSetup()
|
||||
|
||||
const sourcePath = incDir() / "treesitter" / "lib"
|
||||
const sourcePath = cacheDir / "treesitter" / "lib"
|
||||
|
||||
when defined(Linux):
|
||||
{.passC: "-std=c11".}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import ".."/[setup, paths]
|
|||
static:
|
||||
treesitterCSetup()
|
||||
|
||||
const srcDir = incDir() / "treesitter_c" / "src"
|
||||
const srcDir = cacheDir / "treesitter_c" / "src"
|
||||
|
||||
import "."/api
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,20 @@
|
|||
import strutils, os
|
||||
|
||||
import ".."/[setup, paths]
|
||||
import ".."/[build, setup, paths]
|
||||
|
||||
static:
|
||||
treesitterCppSetup()
|
||||
|
||||
const srcDir = incDir() / "treesitter_cpp" / "src"
|
||||
const srcDir = cacheDir / "treesitter_cpp" / "src"
|
||||
|
||||
{.passC: "-I$1" % srcDir.}
|
||||
|
||||
import "."/api
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
|
||||
const srcDirRel = "../../build/inc/treesitter_cpp/src"
|
||||
else:
|
||||
const srcDirRel = srcDir.relativePath(currentSourcePath.parentDir)
|
||||
static:
|
||||
cpFile(srcDir / "parser.c", srcDir / "parser_cpp.c")
|
||||
|
||||
# pending https://github.com/nim-lang/Nim/issues/9370 we need srcDirRel instead
|
||||
# of srcDir
|
||||
{.compile: (srcDirRel / "parser.c", "nimtero_cpp_parser.c.o").}
|
||||
{.compile: srcDir / "parser_cpp.c".}
|
||||
{.compile: srcDir / "scanner.cc".}
|
||||
|
||||
proc treeSitterCpp*(): ptr TSLanguage {.importc: "tree_sitter_cpp", header: srcDir / "api.h".}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,4 @@ cPlugin:
|
|||
static:
|
||||
cDebug()
|
||||
|
||||
cImport(incDir()/"treesitter/lib/include/tree_sitter/api.h")
|
||||
cImport(cacheDir / "treesitter" /"lib" / "include" / "tree_sitter" / "api.h")
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
import strutils
|
||||
|
||||
proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
||||
if delete:
|
||||
rmDir("build/liblzma")
|
||||
rmDir("build/zlib")
|
||||
echo cmd
|
||||
var
|
||||
ccmd =
|
||||
when defined(windows):
|
||||
"cmd /c " & cmd
|
||||
else:
|
||||
cmd
|
||||
|
||||
if not delete:
|
||||
ccmd = ccmd.replace(" -f ", " ")
|
||||
|
||||
var
|
||||
(outp, exitC) = gorgeEx(ccmd)
|
||||
echo outp
|
||||
doAssert exitC == exitCode, $exitC
|
||||
|
|
@ -41,7 +42,6 @@ when defined(posix):
|
|||
# git tag
|
||||
testCall(cmd & " -d:lzmaGit -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0)
|
||||
testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0, delete = false)
|
||||
testCall("cd build/liblzma && git branch", "v5.2.0", 0, delete = false)
|
||||
|
||||
# git
|
||||
testCall(cmd & " -d:envTest" & zrcmd, zexp, 0)
|
||||
|
|
@ -50,7 +50,6 @@ testCall(cmd & " -d:envTestStatic" & zrcmd, zexp, 0, delete = false)
|
|||
# git tag
|
||||
testCall(cmd & " -d:zlibGit -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0)
|
||||
testCall(cmd & " -d:zlibGit -d:zlibStatic -d:zlibSetVer=v1.2.10" & zrcmd, zexp & "1.2.10", 0, delete = false)
|
||||
testCall("cd build/zlib && git branch", "v1.2.10", 0, delete = false)
|
||||
|
||||
# dl
|
||||
testCall(cmd & " -d:lzmaDL" & lrcmd, "Need version", 1)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os, strutils
|
|||
import nimterop/[build, cimport]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir()/"build"/"liblzma"
|
||||
baseDir = getProjectCacheDir("nimterop" / "tests" / "liblzma")
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os
|
|||
import nimterop/[cimport, build, paths]
|
||||
|
||||
const
|
||||
baseDir = nimteropBuildDir()/"pcre"
|
||||
baseDir = getProjectCacheDir("nimterop" / "tests" / "pcre")
|
||||
pcreH = baseDir/"pcre.h.in"
|
||||
|
||||
static:
|
||||
|
|
@ -32,4 +32,4 @@ cPlugin:
|
|||
|
||||
cImport(pcreH, dynlib="dynpcre")
|
||||
|
||||
echo version()
|
||||
echo version()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import os, nimterop/[cimport, build, paths]
|
||||
|
||||
const
|
||||
baseDir = nimteropBuildDir()/"soloud"
|
||||
baseDir = getProjectCacheDir("nimterop" / "tests" / "soloud")
|
||||
incl = baseDir/"include"
|
||||
src = baseDir/"src"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os, strutils
|
|||
import nimterop/[build, cimport]
|
||||
|
||||
const
|
||||
baseDir = currentSourcePath.parentDir()/"build"/"zlib"
|
||||
baseDir = getProjectCacheDir("nimterop" / "tests" / "zlib")
|
||||
|
||||
static:
|
||||
cDebug()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue