Merge remote-tracking branch 'upstream/master' into configurable_compiler
This commit is contained in:
commit
bfd9e50652
3 changed files with 34 additions and 18 deletions
|
|
@ -28,7 +28,7 @@ Nimble already requires Git so those commands can be assumed to be present to do
|
||||||
|
|
||||||
__Capabilities & Limitations__
|
__Capabilities & Limitations__
|
||||||
|
|
||||||
Nimgen supports compiling in C/C++ sources as well as loading in dynamic libraries at this time. Support for static libraries (.a, .lib) are still to come.
|
Nimgen supports compiling in C/C++ sources and static libraries as well as loading in dynamic libraries.
|
||||||
|
|
||||||
To see examples of nimgen in action check out the following wrappers:-
|
To see examples of nimgen in action check out the following wrappers:-
|
||||||
* Link with a dynamic library
|
* Link with a dynamic library
|
||||||
|
|
@ -147,6 +147,8 @@ The following keys apply to library source code (before processing) and generate
|
||||||
|
|
||||||
```search``` = search string providing context for following prepend/append/replace directives
|
```search``` = search string providing context for following prepend/append/replace directives
|
||||||
|
|
||||||
|
```pipe``` = execute a command on a file and store the output of the command as the new file contents. Ex: pipe = "cat $file | grep 'static inline'"
|
||||||
|
|
||||||
```prepend``` = string value to prepend into file at beginning or before search
|
```prepend``` = string value to prepend into file at beginning or before search
|
||||||
|
|
||||||
```append``` = string value to append into file at the end or after search
|
```append``` = string value to append into file at the end or after search
|
||||||
|
|
|
||||||
44
nimgen.nim
44
nimgen.nim
|
|
@ -4,6 +4,7 @@ var
|
||||||
gDoneRecursive: seq[string] = @[]
|
gDoneRecursive: seq[string] = @[]
|
||||||
gDoneInline: seq[string] = @[]
|
gDoneInline: seq[string] = @[]
|
||||||
|
|
||||||
|
gProjectDir = ""
|
||||||
gConfig: Config
|
gConfig: Config
|
||||||
gFilter = ""
|
gFilter = ""
|
||||||
gQuotes = true
|
gQuotes = true
|
||||||
|
|
@ -61,7 +62,7 @@ proc extractZip(zipfile: string) =
|
||||||
cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
|
cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir("..")
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
echo "Extracting " & zipfile
|
echo "Extracting " & zipfile
|
||||||
discard execProc(cmd % zipfile)
|
discard execProc(cmd % zipfile)
|
||||||
|
|
@ -86,7 +87,7 @@ proc gitReset() =
|
||||||
echo "Resetting Git repo"
|
echo "Resetting Git repo"
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir("..")
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
discard execProc("git reset --hard HEAD")
|
discard execProc("git reset --hard HEAD")
|
||||||
|
|
||||||
|
|
@ -97,7 +98,7 @@ proc gitRemotePull(url: string, pull=true) =
|
||||||
return
|
return
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir("..")
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
echo "Setting up Git repo"
|
echo "Setting up Git repo"
|
||||||
discard execProc("git init .")
|
discard execProc("git init .")
|
||||||
|
|
@ -114,7 +115,7 @@ proc gitSparseCheckout(plist: string) =
|
||||||
return
|
return
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir("..")
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
discard execProc("git config core.sparsecheckout true")
|
discard execProc("git config core.sparsecheckout true")
|
||||||
writeFile(sparsefile, plist)
|
writeFile(sparsefile, plist)
|
||||||
|
|
@ -195,15 +196,17 @@ proc search(file: string): string =
|
||||||
# ###
|
# ###
|
||||||
# Loading / unloading
|
# Loading / unloading
|
||||||
|
|
||||||
|
proc openRetry(file: string, mode: FileMode = fmRead): File =
|
||||||
|
while true:
|
||||||
|
try:
|
||||||
|
result = open(file, mode)
|
||||||
|
break
|
||||||
|
except IOError:
|
||||||
|
sleep(100)
|
||||||
|
|
||||||
template withFile(file: string, body: untyped): untyped =
|
template withFile(file: string, body: untyped): untyped =
|
||||||
if fileExists(file):
|
if fileExists(file):
|
||||||
var f: File
|
var f = openRetry(file)
|
||||||
while true:
|
|
||||||
try:
|
|
||||||
f = open(file)
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
sleep(100)
|
|
||||||
|
|
||||||
var contentOrig = f.readAll()
|
var contentOrig = f.readAll()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
@ -212,7 +215,7 @@ template withFile(file: string, body: untyped): untyped =
|
||||||
body
|
body
|
||||||
|
|
||||||
if content != contentOrig:
|
if content != contentOrig:
|
||||||
var f = open(file, fmWrite)
|
f = openRetry(file, fmWrite)
|
||||||
write(f, content)
|
write(f, content)
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
|
|
@ -230,6 +233,13 @@ proc prepend(file: string, data: string, search="") =
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
content = content[0..<idx] & data & content[idx..<content.len()]
|
content = content[0..<idx] & data & content[idx..<content.len()]
|
||||||
|
|
||||||
|
proc pipe(file: string, command: string) =
|
||||||
|
let cmd = command % ["file", file]
|
||||||
|
let commandResult = execProc(cmd).strip()
|
||||||
|
if commandResult != "":
|
||||||
|
withFile(file):
|
||||||
|
content = commandResult
|
||||||
|
|
||||||
proc append(file: string, data: string, search="") =
|
proc append(file: string, data: string, search="") =
|
||||||
withFile(file):
|
withFile(file):
|
||||||
if search == "":
|
if search == "":
|
||||||
|
|
@ -411,14 +421,14 @@ proc runPreprocess(file, ppflags, flags: string, inline: bool): string =
|
||||||
|
|
||||||
proc runCtags(file: string): string =
|
proc runCtags(file: string): string =
|
||||||
var
|
var
|
||||||
cmd = "ctags -o - --fields=+S+K --c-kinds=p --file-scope=no " & file
|
cmd = "ctags -o - --fields=+S+K --c-kinds=+p --file-scope=no " & file
|
||||||
fps = execProc(cmd)
|
fps = execProc(cmd)
|
||||||
fdata = ""
|
fdata = ""
|
||||||
|
|
||||||
for line in fps.splitLines():
|
for line in fps.splitLines():
|
||||||
var spl = line.split(re"\t")
|
var spl = line.split(re"\t")
|
||||||
if spl.len() > 4:
|
if spl.len() > 4:
|
||||||
if spl[0] != "main":
|
if spl[0] != "main" and spl[3] != "member":
|
||||||
var fn = ""
|
var fn = ""
|
||||||
var match = spl[2].find(re"/\^(.*?)\(")
|
var match = spl[2].find(re"/\^(.*?)\(")
|
||||||
if match.isSome():
|
if match.isSome():
|
||||||
|
|
@ -589,7 +599,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
if action == "create":
|
if action == "create":
|
||||||
createDir(file.splitPath().head)
|
createDir(file.splitPath().head)
|
||||||
writeFile(file, cfg[act])
|
writeFile(file, cfg[act])
|
||||||
elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma"] and sfile != "":
|
elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma", "pipe"] and sfile != "":
|
||||||
if action == "prepend":
|
if action == "prepend":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
prepend(sfile, cfg[act], cfg[srch])
|
prepend(sfile, cfg[act], cfg[srch])
|
||||||
|
|
@ -614,6 +624,8 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
c2nimConfig.dynlib.add(cfg[act])
|
c2nimConfig.dynlib.add(cfg[act])
|
||||||
elif action == "pragma":
|
elif action == "pragma":
|
||||||
c2nimConfig.pragma.add(cfg[act])
|
c2nimConfig.pragma.add(cfg[act])
|
||||||
|
elif action == "pipe":
|
||||||
|
pipe(sfile, cfg[act])
|
||||||
srch = ""
|
srch = ""
|
||||||
elif action == "search":
|
elif action == "search":
|
||||||
srch = act
|
srch = act
|
||||||
|
|
@ -652,6 +664,8 @@ proc runCfg(cfg: string) =
|
||||||
echo "Config doesn't exist: " & cfg
|
echo "Config doesn't exist: " & cfg
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
|
gProjectDir = parentDir(cfg.expandFilename())
|
||||||
|
|
||||||
gConfig = loadConfig(cfg)
|
gConfig = loadConfig(cfg)
|
||||||
|
|
||||||
if gConfig.hasKey("n.global"):
|
if gConfig.hasKey("n.global"):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
author = "genotrance"
|
author = "genotrance"
|
||||||
description = "c2nim helper to simplify and automate the wrapping of C libraries"
|
description = "c2nim helper to simplify and automate the wrapping of C libraries"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
@ -9,7 +9,7 @@ skipDirs = @["tests"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 0.17.2", "c2nim >= 0.9.13"
|
requires "nim >= 0.17.0", "c2nim >= 0.9.13"
|
||||||
|
|
||||||
bin = @["nimgen"]
|
bin = @["nimgen"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue