Use g/decho in build
This commit is contained in:
parent
63a75bce4e
commit
a0413f1595
11 changed files with 135 additions and 66 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
import os, strformat, strutils, tables
|
import json, os, strformat, strutils, tables
|
||||||
|
|
||||||
|
|
||||||
|
import ".."/globals
|
||||||
import "."/[ccompiler, misc, nimconf, shell]
|
import "."/[ccompiler, misc, nimconf, shell]
|
||||||
|
|
||||||
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
|
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
|
||||||
import marshal
|
import marshal
|
||||||
else:
|
|
||||||
import json
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ConanPackage* = ref object
|
ConanPackage* = ref object
|
||||||
|
|
@ -158,7 +158,7 @@ proc searchConan*(name: string, version = "", user = "", channel = ""): ConanPac
|
||||||
if channel.len != 0:
|
if channel.len != 0:
|
||||||
query &= "/" & channel
|
query &= "/" & channel
|
||||||
|
|
||||||
echo &"# Searching Conan.io for latest version of {name}"
|
gecho &"# Searching Conan.io for latest version of {name}"
|
||||||
|
|
||||||
let
|
let
|
||||||
j1 = jsonGet(conanSearchUrl % ["query", query])
|
j1 = jsonGet(conanSearchUrl % ["query", query])
|
||||||
|
|
@ -397,7 +397,7 @@ proc downloadConan*(pkg: ConanPackage, outdir: string, main = true) =
|
||||||
|
|
||||||
doAssert pkg.recipes.len != 0, &"Failed to download {pkg.name} v{pkg.version} from Conan - check https://conan.io/center"
|
doAssert pkg.recipes.len != 0, &"Failed to download {pkg.name} v{pkg.version} from Conan - check https://conan.io/center"
|
||||||
|
|
||||||
echo &"# Downloading {pkg.name} v{pkg.version} from Conan.io"
|
gecho &"# Downloading {pkg.name} v{pkg.version} from Conan.io"
|
||||||
for recipe, builds in pkg.recipes:
|
for recipe, builds in pkg.recipes:
|
||||||
for build in builds:
|
for build in builds:
|
||||||
if pkg.bhash.len == 0 or pkg.bhash == build.bhash:
|
if pkg.bhash.len == 0 or pkg.bhash == build.bhash:
|
||||||
|
|
|
||||||
|
|
@ -476,9 +476,9 @@ macro getHeader*(
|
||||||
{.passL: `ldeps`.join(" ").}
|
{.passL: `ldeps`.join(" ").}
|
||||||
|
|
||||||
static:
|
static:
|
||||||
echo "# Including library " & lpath
|
gecho "# Including library " & lpath
|
||||||
if `ldeps`.len != 0:
|
if `ldeps`.len != 0:
|
||||||
echo "# Including dependencies " & `ldeps`.join(" ")
|
gecho "# Including dependencies " & `ldeps`.join(" ")
|
||||||
else:
|
else:
|
||||||
const
|
const
|
||||||
`lpath`* = when not useStd: `libdir` / lpath.extractFilename() else: lpath
|
`lpath`* = when not useStd: `libdir` / lpath.extractFilename() else: lpath
|
||||||
|
|
@ -498,7 +498,7 @@ macro getHeader*(
|
||||||
ldeps[i] = ldeptgt
|
ldeps[i] = ldeptgt
|
||||||
# Copy downloaded dependencies to `libdir`
|
# Copy downloaded dependencies to `libdir`
|
||||||
if copied.len != 0:
|
if copied.len != 0:
|
||||||
echo "# Copying dependencies: " & copied.join(" ") & "\n# to " & `libdir`
|
gecho "# Copying dependencies: " & copied.join(" ") & "\n# to " & `libdir`
|
||||||
ldeps
|
ldeps
|
||||||
else:
|
else:
|
||||||
ldeps
|
ldeps
|
||||||
|
|
@ -507,8 +507,8 @@ macro getHeader*(
|
||||||
when not useStd:
|
when not useStd:
|
||||||
# Copy downloaded shared libraries to `libdir`
|
# Copy downloaded shared libraries to `libdir`
|
||||||
if not fileExists(`lpath`) or getFileDate(lpath) != getFileDate(`lpath`):
|
if not fileExists(`lpath`) or getFileDate(lpath) != getFileDate(`lpath`):
|
||||||
echo "# Copying " & `lpath`.extractFilename() & " to " & `libdir`
|
gecho "# Copying " & `lpath`.extractFilename() & " to " & `libdir`
|
||||||
cpFile(lpath, `lpath`)
|
cpFile(lpath, `lpath`)
|
||||||
|
|
||||||
echo "# Including library " & `lpath`
|
gecho "# Including library " & `lpath`
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import json, os, strformat, strutils, tables
|
import json, os, strformat, strutils, tables
|
||||||
|
|
||||||
|
import ".."/globals
|
||||||
import "."/[ccompiler, nimconf, shell]
|
import "."/[ccompiler, nimconf, shell]
|
||||||
|
|
||||||
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
|
when (NimMajor, NimMinor, NimPatch) < (1, 2, 0):
|
||||||
|
|
@ -198,7 +199,7 @@ proc downloadJBB*(pkg: JBBPackage, outdir: string, main = true) =
|
||||||
else:
|
else:
|
||||||
""
|
""
|
||||||
path = outdir / pkg.name
|
path = outdir / pkg.name
|
||||||
echo &"# Downloading {pkg.name}{vstr} from BinaryBuilder.org"
|
gecho &"# Downloading {pkg.name}{vstr} from BinaryBuilder.org"
|
||||||
downloadUrl(pkg.url, path, quiet = true)
|
downloadUrl(pkg.url, path, quiet = true)
|
||||||
pkg.findJBBLibs(path)
|
pkg.findJBBLibs(path)
|
||||||
|
|
||||||
|
|
|
||||||
62
nimterop/build/misc.nim
Normal file
62
nimterop/build/misc.nim
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import os, strutils
|
||||||
|
|
||||||
|
when defined(Windows):
|
||||||
|
import strformat
|
||||||
|
|
||||||
|
import ".."/globals
|
||||||
|
|
||||||
|
proc sanitizePath*(path: string, noQuote = false, sep = $DirSep): string =
|
||||||
|
result = path.multiReplace([("\\\\", sep), ("\\", sep), ("/", sep)])
|
||||||
|
if not noQuote:
|
||||||
|
result = result.quoteShell
|
||||||
|
|
||||||
|
proc getCurrentNimCompiler*(): string =
|
||||||
|
when nimvm:
|
||||||
|
result = getCurrentCompilerExe()
|
||||||
|
when defined(nimsuggest):
|
||||||
|
result = result.replace("nimsuggest", "nim")
|
||||||
|
else:
|
||||||
|
result = gState.nim
|
||||||
|
|
||||||
|
proc compareVersions*(ver1, ver2: string): int =
|
||||||
|
## Compare two version strings x.y.z and return -1, 0, 1
|
||||||
|
##
|
||||||
|
## ver1 < ver2 = -1
|
||||||
|
## ver1 = ver2 = 0
|
||||||
|
## ver1 > ver2 = 1
|
||||||
|
let
|
||||||
|
ver1seq = ver1.replace("-", "").split('.')
|
||||||
|
ver2seq = ver2.replace("-", "").split('.')
|
||||||
|
for i in 0 ..< ver1seq.len:
|
||||||
|
let
|
||||||
|
p1 = ver1seq[i]
|
||||||
|
p2 = if i < ver2seq.len: ver2seq[i] else: "0"
|
||||||
|
|
||||||
|
try:
|
||||||
|
let
|
||||||
|
h1 = p1.parseHexInt()
|
||||||
|
h2 = p2.parseHexInt()
|
||||||
|
|
||||||
|
if h1 < h2: return -1
|
||||||
|
elif h1 > h2: return 1
|
||||||
|
except ValueError:
|
||||||
|
if p1 < p2: return -1
|
||||||
|
elif p1 > p2: return 1
|
||||||
|
|
||||||
|
proc fixCmd*(cmd: string): string =
|
||||||
|
when defined(Windows):
|
||||||
|
# Replace 'cd d:\abc' with 'd: && cd d:\abc`
|
||||||
|
var filteredCmd = cmd
|
||||||
|
if cmd.toLower().startsWith("cd"):
|
||||||
|
var
|
||||||
|
colonIndex = cmd.find(":")
|
||||||
|
driveLetter = cmd.substr(colonIndex-1, colonIndex)
|
||||||
|
if (driveLetter[0].isAlphaAscii() and
|
||||||
|
driveLetter[1] == ':' and
|
||||||
|
colonIndex == 4):
|
||||||
|
filteredCmd = &"{driveLetter} && {cmd}"
|
||||||
|
result = "cmd /c " & filteredCmd
|
||||||
|
elif defined(posix):
|
||||||
|
result = cmd
|
||||||
|
else:
|
||||||
|
doAssert false
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import json, os, osproc, sets, strformat, strutils
|
import json, os, osproc, sets, strformat, strutils
|
||||||
|
|
||||||
|
import ".."/globals
|
||||||
import "."/misc
|
import "."/misc
|
||||||
|
|
||||||
when nimvm:
|
when nimvm:
|
||||||
|
|
@ -42,7 +43,7 @@ proc getJson(projectDir: string): JsonNode =
|
||||||
try:
|
try:
|
||||||
result = parseJson(dump)
|
result = parseJson(dump)
|
||||||
except JsonParsingError as e:
|
except JsonParsingError as e:
|
||||||
echo "# Failed to parse `nim dump` output: " & e.msg
|
gecho "# Failed to parse `nim dump` output: " & e.msg
|
||||||
|
|
||||||
proc getOsCacheDir(): string =
|
proc getOsCacheDir(): string =
|
||||||
# OS default cache directory
|
# OS default cache directory
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ when not defined(TOAST):
|
||||||
else:
|
else:
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import ".."/globals
|
||||||
import "."/[misc, nimconf]
|
import "."/[misc, nimconf]
|
||||||
|
|
||||||
when not defined(TOAST):
|
when not defined(TOAST):
|
||||||
|
|
@ -228,7 +229,7 @@ proc extractZip*(zipfile, outdir: string, quiet = false) =
|
||||||
"[IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
|
"[IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Extracting " & zipfile
|
gecho "# Extracting " & zipfile
|
||||||
discard execAction(&"cd {outdir.sanitizePath} && {cmd % zipfile}")
|
discard execAction(&"cd {outdir.sanitizePath} && {cmd % zipfile}")
|
||||||
|
|
||||||
proc extractTar*(tarfile, outdir: string, quiet = false) =
|
proc extractTar*(tarfile, outdir: string, quiet = false) =
|
||||||
|
|
@ -262,7 +263,7 @@ proc extractTar*(tarfile, outdir: string, quiet = false) =
|
||||||
doAssert cmd.len != 0, "No extraction tool - tar, 7z, 7za - available for " & tarfile.sanitizePath
|
doAssert cmd.len != 0, "No extraction tool - tar, 7z, 7za - available for " & tarfile.sanitizePath
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Extracting " & tarfile
|
gecho "# Extracting " & tarfile
|
||||||
discard execAction(&"cd {outdir.sanitizePath} && {cmd}")
|
discard execAction(&"cd {outdir.sanitizePath} && {cmd}")
|
||||||
if name.len != 0:
|
if name.len != 0:
|
||||||
rmFile(outdir / name)
|
rmFile(outdir / name)
|
||||||
|
|
@ -279,7 +280,7 @@ proc downloadUrl*(url, outdir: string, quiet = false, retry = 1) =
|
||||||
|
|
||||||
if not (ext in archives and fileExists(filePath)):
|
if not (ext in archives and fileExists(filePath)):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Downloading " & file
|
gecho "# Downloading " & file
|
||||||
mkDir(outdir)
|
mkDir(outdir)
|
||||||
var cmd = findExe("curl")
|
var cmd = findExe("curl")
|
||||||
if cmd.len != 0:
|
if cmd.len != 0:
|
||||||
|
|
@ -302,12 +303,12 @@ proc downloadUrl*(url, outdir: string, quiet = false, retry = 1) =
|
||||||
|
|
||||||
proc gitReset*(outdir: string) =
|
proc gitReset*(outdir: string) =
|
||||||
## Hard reset the git repository at the specified directory
|
## Hard reset the git repository at the specified directory
|
||||||
echo "# Resetting " & outdir
|
gecho "# Resetting " & outdir
|
||||||
|
|
||||||
let cmd = &"cd {outdir.sanitizePath} && git reset --hard"
|
let cmd = &"cd {outdir.sanitizePath} && git reset --hard"
|
||||||
while execAction(cmd).output.contains("Permission denied"):
|
while execAction(cmd).output.contains("Permission denied"):
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
echo "# Retrying ..."
|
gecho "# Retrying ..."
|
||||||
|
|
||||||
proc gitCheckout*(file, outdir: string) =
|
proc gitCheckout*(file, outdir: string) =
|
||||||
## Checkout the specified `file` in the git repository at `outdir`
|
## Checkout the specified `file` in the git repository at `outdir`
|
||||||
|
|
@ -315,12 +316,12 @@ proc gitCheckout*(file, outdir: string) =
|
||||||
## This effectively resets all changes in the file and can be
|
## This effectively resets all changes in the file and can be
|
||||||
## used to undo any changes that were made to source files to enable
|
## used to undo any changes that were made to source files to enable
|
||||||
## successful wrapping with `cImport()` or `c2nImport()`.
|
## successful wrapping with `cImport()` or `c2nImport()`.
|
||||||
echo "# Resetting " & file
|
gecho "# Resetting " & file
|
||||||
let file2 = file.relativePath outdir
|
let file2 = file.relativePath outdir
|
||||||
let cmd = &"cd {outdir.sanitizePath} && git checkout {file2.sanitizePath}"
|
let cmd = &"cd {outdir.sanitizePath} && git checkout {file2.sanitizePath}"
|
||||||
while execAction(cmd).output.contains("Permission denied"):
|
while execAction(cmd).output.contains("Permission denied"):
|
||||||
sleep(500)
|
sleep(500)
|
||||||
echo "# Retrying ..."
|
gecho "# Retrying ..."
|
||||||
|
|
||||||
proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false) =
|
proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false) =
|
||||||
## Pull the specified git repository to the output directory
|
## Pull the specified git repository to the output directory
|
||||||
|
|
@ -343,7 +344,7 @@ proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false
|
||||||
mkDir(outdir)
|
mkDir(outdir)
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Setting up Git repo: " & url
|
gecho "# Setting up Git repo: " & url
|
||||||
discard execAction(&"cd {outdirQ} && git init .")
|
discard execAction(&"cd {outdirQ} && git init .")
|
||||||
discard execAction(&"cd {outdirQ} && git remote add origin {url}")
|
discard execAction(&"cd {outdirQ} && git remote add origin {url}")
|
||||||
|
|
||||||
|
|
@ -360,12 +361,12 @@ proc gitPull*(url: string, outdir = "", plist = "", checkout = "", quiet = false
|
||||||
|
|
||||||
if checkout.len != 0:
|
if checkout.len != 0:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Checking out " & checkout
|
gecho "# Checking out " & checkout
|
||||||
discard execAction(&"cd {outdirQ} && git fetch", retry = 3)
|
discard execAction(&"cd {outdirQ} && git fetch", retry = 3)
|
||||||
discard execAction(&"cd {outdirQ} && git checkout {checkout}")
|
discard execAction(&"cd {outdirQ} && git checkout {checkout}")
|
||||||
else:
|
else:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
echo "# Pulling repository"
|
gecho "# Pulling repository"
|
||||||
discard execAction(&"cd {outdirQ} && git pull --depth=1 origin master", retry = 3)
|
discard execAction(&"cd {outdirQ} && git pull --depth=1 origin master", retry = 3)
|
||||||
|
|
||||||
proc gitTags*(outdir: string): seq[string] =
|
proc gitTags*(outdir: string): seq[string] =
|
||||||
|
|
@ -504,5 +505,5 @@ proc getProjectCacheDir*(name: string, forceClean = true): string =
|
||||||
result = getNimteropCacheDir() / name
|
result = getNimteropCacheDir() / name
|
||||||
|
|
||||||
if forceClean and compileOption("forceBuild"):
|
if forceClean and compileOption("forceBuild"):
|
||||||
echo "# Removing " & result
|
gecho "# Removing " & result
|
||||||
rmDir(result)
|
rmDir(result)
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,6 @@ import os except findExe
|
||||||
import ".."/globals
|
import ".."/globals
|
||||||
import "."/[misc, shell]
|
import "."/[misc, shell]
|
||||||
|
|
||||||
proc echoDebug(str: string) =
|
|
||||||
let str = "\n# " & str.strip().replace("\n", "\n# ")
|
|
||||||
when defined(TOAST):
|
|
||||||
if gState.debug: echo str
|
|
||||||
else:
|
|
||||||
if gStateCT.debug: echo str
|
|
||||||
|
|
||||||
proc configure*(path, check: string, flags = "") =
|
proc configure*(path, check: string, flags = "") =
|
||||||
## Run the GNU `configure` command to generate all Makefiles or other
|
## Run the GNU `configure` command to generate all Makefiles or other
|
||||||
## build scripts in the specified path
|
## build scripts in the specified path
|
||||||
|
|
@ -30,18 +23,18 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if (path / check).fileExists():
|
if (path / check).fileExists():
|
||||||
return
|
return
|
||||||
|
|
||||||
echo "# Configuring " & path
|
gecho "# Configuring " & path
|
||||||
|
|
||||||
if not fileExists(path / "configure"):
|
if not fileExists(path / "configure"):
|
||||||
for i in @["autogen.sh", "build" / "autogen.sh"]:
|
for i in @["autogen.sh", "build" / "autogen.sh"]:
|
||||||
if fileExists(path / i):
|
if fileExists(path / i):
|
||||||
echo "# Running autogen.sh"
|
gecho "# Running autogen.sh"
|
||||||
|
|
||||||
when defined(unix):
|
when defined(unix):
|
||||||
echoDebug execAction(
|
decho execAction(
|
||||||
&"cd {(path / i).parentDir().sanitizePath} && ./autogen.sh").output
|
&"cd {(path / i).parentDir().sanitizePath} && ./autogen.sh").output
|
||||||
else:
|
else:
|
||||||
echoDebug execAction(
|
decho execAction(
|
||||||
&"cd {(path / i).parentDir().sanitizePath} && bash ./autogen.sh").output
|
&"cd {(path / i).parentDir().sanitizePath} && bash ./autogen.sh").output
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
@ -49,14 +42,14 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if not fileExists(path / "configure"):
|
if not fileExists(path / "configure"):
|
||||||
for i in @["configure.ac", "configure.in"]:
|
for i in @["configure.ac", "configure.in"]:
|
||||||
if fileExists(path / i):
|
if fileExists(path / i):
|
||||||
echo "# Running autoreconf"
|
gecho "# Running autoreconf"
|
||||||
|
|
||||||
echoDebug execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
|
decho execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if fileExists(path / "configure"):
|
if fileExists(path / "configure"):
|
||||||
echo "# Running configure " & flags
|
gecho "# Running configure " & flags
|
||||||
|
|
||||||
when defined(unix):
|
when defined(unix):
|
||||||
var
|
var
|
||||||
|
|
@ -67,7 +60,7 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if flags.len != 0:
|
if flags.len != 0:
|
||||||
cmd &= &" {flags}"
|
cmd &= &" {flags}"
|
||||||
|
|
||||||
echoDebug execAction(cmd).output
|
decho execAction(cmd).output
|
||||||
|
|
||||||
doAssert (path / check).fileExists(), "Configure failed"
|
doAssert (path / check).fileExists(), "Configure failed"
|
||||||
|
|
||||||
|
|
@ -156,15 +149,15 @@ proc cmake*(path, check, flags: string) =
|
||||||
if (path / check).fileExists():
|
if (path / check).fileExists():
|
||||||
return
|
return
|
||||||
|
|
||||||
echo "# Running cmake " & flags
|
gecho "# Running cmake " & flags
|
||||||
echo "# Path: " & path
|
gecho "# Path: " & path
|
||||||
|
|
||||||
mkDir(path)
|
mkDir(path)
|
||||||
|
|
||||||
let
|
let
|
||||||
cmd = &"cd {path.sanitizePath} && cmake {flags}"
|
cmd = &"cd {path.sanitizePath} && cmake {flags}"
|
||||||
|
|
||||||
echoDebug execAction(cmd).output
|
decho execAction(cmd).output
|
||||||
|
|
||||||
doAssert (path / check).fileExists(), "cmake failed"
|
doAssert (path / check).fileExists(), "cmake failed"
|
||||||
|
|
||||||
|
|
@ -184,8 +177,8 @@ proc make*(path, check: string, flags = "", regex = false) =
|
||||||
if findFile(check, path, regex = regex).len != 0:
|
if findFile(check, path, regex = regex).len != 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
echo "# Running make " & flags
|
gecho "# Running make " & flags
|
||||||
echo "# Path: " & path
|
gecho "# Path: " & path
|
||||||
|
|
||||||
var
|
var
|
||||||
cmd = findExe("make")
|
cmd = findExe("make")
|
||||||
|
|
@ -200,7 +193,7 @@ proc make*(path, check: string, flags = "", regex = false) =
|
||||||
if flags.len != 0:
|
if flags.len != 0:
|
||||||
cmd &= &" {flags}"
|
cmd &= &" {flags}"
|
||||||
|
|
||||||
echoDebug execAction(cmd).output
|
decho execAction(cmd).output
|
||||||
|
|
||||||
doAssert findFile(check, path, regex = regex).len != 0, "make failed"
|
doAssert findFile(check, path, regex = regex).len != 0, "make failed"
|
||||||
|
|
||||||
|
|
@ -219,7 +212,7 @@ proc buildWithCmake*(outdir, flags: string): BuildStatus =
|
||||||
elif uname.contains("mingw"):
|
elif uname.contains("mingw"):
|
||||||
gen = "MinGW Makefiles".quoteShell & " -DCMAKE_SH=\"CMAKE_SH-NOTFOUND\""
|
gen = "MinGW Makefiles".quoteShell & " -DCMAKE_SH=\"CMAKE_SH-NOTFOUND\""
|
||||||
else:
|
else:
|
||||||
echo "Unsupported system: " & uname
|
gecho "Unsupported system: " & uname
|
||||||
else:
|
else:
|
||||||
gen = "MinGW Makefiles".quoteShell
|
gen = "MinGW Makefiles".quoteShell
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,8 @@ proc onSymbolOverride*(sym: var Symbol) {.exportc, dynlib.} =
|
||||||
|
|
||||||
gStateCT.symOverride.add name
|
gStateCT.symOverride.add name
|
||||||
|
|
||||||
if gStateCT.debug and names.nBl:
|
if names.nBl:
|
||||||
echo "# Overriding " & names.join(" ")
|
decho "Overriding " & names.join(" ")
|
||||||
|
|
||||||
proc cSkipSymbol*(skips: seq[string]) {.compileTime.} =
|
proc cSkipSymbol*(skips: seq[string]) {.compileTime.} =
|
||||||
## Similar to `cOverride() <cimport.html#cOverride.m>`_, this macro allows
|
## Similar to `cOverride() <cimport.html#cOverride.m>`_, this macro allows
|
||||||
|
|
@ -412,7 +412,7 @@ macro cDefine*(name: static string, val: static string = ""): untyped =
|
||||||
{.passC: `str`.}
|
{.passC: `str`.}
|
||||||
|
|
||||||
if gStateCT.debug:
|
if gStateCT.debug:
|
||||||
echo result.repr & "\n"
|
gecho result.repr & "\n"
|
||||||
|
|
||||||
proc cAddSearchDir*(dir: string) {.compileTime.} =
|
proc cAddSearchDir*(dir: string) {.compileTime.} =
|
||||||
## Add directory `dir` to the search path used in calls to
|
## Add directory `dir` to the search path used in calls to
|
||||||
|
|
@ -442,7 +442,7 @@ macro cIncludeDir*(dir: static string): untyped =
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
{.passC: `str`.}
|
{.passC: `str`.}
|
||||||
if gStateCT.debug:
|
if gStateCT.debug:
|
||||||
echo result.repr
|
gecho result.repr
|
||||||
|
|
||||||
proc cAddStdDir*(mode = "c") {.compileTime.} =
|
proc cAddStdDir*(mode = "c") {.compileTime.} =
|
||||||
## Add the standard `c` [default] or `cpp` include paths to search
|
## Add the standard `c` [default] or `cpp` include paths to search
|
||||||
|
|
@ -545,7 +545,7 @@ macro cCompile*(path: static string, mode = "c", exclude = ""): untyped =
|
||||||
result.add stmt.parseStmt()
|
result.add stmt.parseStmt()
|
||||||
|
|
||||||
if gStateCT.debug:
|
if gStateCT.debug:
|
||||||
echo result.repr
|
gecho result.repr
|
||||||
|
|
||||||
macro cImport*(filenames: static seq[string], recurse: static bool = false, dynlib: static string = "",
|
macro cImport*(filenames: static seq[string], recurse: static bool = false, dynlib: static string = "",
|
||||||
mode: static string = "c", flags: static string = ""): untyped =
|
mode: static string = "c", flags: static string = ""): untyped =
|
||||||
|
|
@ -565,7 +565,7 @@ macro cImport*(filenames: static seq[string], recurse: static bool = false, dynl
|
||||||
if gStateCT.pluginSourcePath.Bl:
|
if gStateCT.pluginSourcePath.Bl:
|
||||||
cPluginHelper(gStateCT.pluginSource)
|
cPluginHelper(gStateCT.pluginSource)
|
||||||
|
|
||||||
echo "# Importing " & fullpaths.join(", ").sanitizePath
|
gecho "# Importing " & fullpaths.join(", ").sanitizePath
|
||||||
|
|
||||||
let
|
let
|
||||||
output = getToast(fullpaths, recurse, dynlib, mode, flags)
|
output = getToast(fullpaths, recurse, dynlib, mode, flags)
|
||||||
|
|
@ -576,7 +576,7 @@ macro cImport*(filenames: static seq[string], recurse: static bool = false, dynl
|
||||||
gStateCT.overrides = ""
|
gStateCT.overrides = ""
|
||||||
|
|
||||||
if gStateCT.debug:
|
if gStateCT.debug:
|
||||||
echo output
|
gecho output
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let body = parseStmt(output)
|
let body = parseStmt(output)
|
||||||
|
|
@ -661,7 +661,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
|
||||||
let
|
let
|
||||||
fullpath = findPath(filename)
|
fullpath = findPath(filename)
|
||||||
|
|
||||||
echo "# Importing " & fullpath & " with c2nim"
|
gecho "# Importing " & fullpath & " with c2nim"
|
||||||
|
|
||||||
let
|
let
|
||||||
output = getToast(@[fullpath], recurse, dynlib, mode, noNimout = true)
|
output = getToast(@[fullpath], recurse, dynlib, mode, noNimout = true)
|
||||||
|
|
@ -700,7 +700,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
|
||||||
nimout = &"const {header} = \"{fullpath}\"\n\n" & readFile(npath)
|
nimout = &"const {header} = \"{fullpath}\"\n\n" & readFile(npath)
|
||||||
|
|
||||||
if gStateCT.debug:
|
if gStateCT.debug:
|
||||||
echo nimout
|
gecho nimout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let body = parseStmt(nimout)
|
let body = parseStmt(nimout)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import tables
|
import strutils, tables
|
||||||
|
|
||||||
when defined(TOAST):
|
when defined(TOAST):
|
||||||
import sets, sequtils, strutils
|
import sets, sequtils, strutils
|
||||||
|
|
@ -124,16 +124,31 @@ when defined(TOAST):
|
||||||
Status* = enum
|
Status* = enum
|
||||||
success, unknown, error
|
success, unknown, error
|
||||||
|
|
||||||
# Redirect output to file when required
|
proc getCommented*(str: string): string =
|
||||||
template gecho*(args: string) =
|
"\n# " & str.strip().replace("\n", "\n# ")
|
||||||
if gState.outputHandle.isNil:
|
|
||||||
|
# Redirect output to file when required
|
||||||
|
template gecho*(args: string) =
|
||||||
|
when defined(TOAST):
|
||||||
|
when nimvm:
|
||||||
echo args
|
echo args
|
||||||
else:
|
else:
|
||||||
gState.outputHandle.writeLine(args)
|
if gState.outputHandle.isNil:
|
||||||
|
echo args
|
||||||
|
else:
|
||||||
|
gState.outputHandle.writeLine(args)
|
||||||
|
else:
|
||||||
|
echo args
|
||||||
|
|
||||||
template decho*(args: varargs[string, `$`]): untyped =
|
template decho*(args: varargs[string, `$`]): untyped =
|
||||||
|
let
|
||||||
|
str = join(args, "").getCommented()
|
||||||
|
when defined(TOAST):
|
||||||
if gState.debug:
|
if gState.debug:
|
||||||
gecho join(args, "").getCommented()
|
gecho str
|
||||||
|
else:
|
||||||
|
if gStateCT.debug:
|
||||||
|
echo str
|
||||||
|
|
||||||
template nBl*(s: typed): untyped {.used.} =
|
template nBl*(s: typed): untyped {.used.} =
|
||||||
(s.len != 0)
|
(s.len != 0)
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,7 @@ proc main(
|
||||||
doAssert gState.outputHandle.open(outputFile, fmWrite),
|
doAssert gState.outputHandle.open(outputFile, fmWrite),
|
||||||
&"Failed to write to {outputFile}"
|
&"Failed to write to {outputFile}"
|
||||||
|
|
||||||
if gState.debug:
|
decho &"# Writing output to {outputFile}\n"
|
||||||
echo &"# Writing output to {outputFile}\n"
|
|
||||||
|
|
||||||
if source.nBl:
|
if source.nBl:
|
||||||
# Print source after preprocess or Nim output
|
# Print source after preprocess or Nim output
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,6 @@ template withCodeAst*(code: string, mode: string, body: untyped): untyped =
|
||||||
defer:
|
defer:
|
||||||
tree.tsTreeDelete()
|
tree.tsTreeDelete()
|
||||||
|
|
||||||
proc getCommented*(str: string): string =
|
|
||||||
"\n# " & str.strip().replace("\n", "\n# ")
|
|
||||||
|
|
||||||
proc isNil*(node: TSNode): bool =
|
proc isNil*(node: TSNode): bool =
|
||||||
node.tsNodeIsNull()
|
node.tsNodeIsNull()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue