Inline fixes
This commit is contained in:
parent
2c3cc71540
commit
1dbff5cbd1
5 changed files with 36 additions and 35 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
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"
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,7 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
if file.len() == 0:
|
if file.len() == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
echo " Generating " & outfile
|
echo "Generating " & outfile
|
||||||
|
|
||||||
# Remove static inline function bodies
|
|
||||||
removeStatic(file)
|
|
||||||
|
|
||||||
fixFuncProtos(file)
|
|
||||||
|
|
||||||
var cfile = file
|
var cfile = file
|
||||||
if c2nimConfig.preprocess:
|
if c2nimConfig.preprocess:
|
||||||
|
|
@ -122,6 +117,3 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
# Add dynamic library
|
# Add dynamic library
|
||||||
if outlib != "":
|
if outlib != "":
|
||||||
prepend(outfile, outlib)
|
prepend(outfile, outlib)
|
||||||
|
|
||||||
# Add back static functions for compilation
|
|
||||||
reAddStatic(file)
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,10 @@ proc gitReset*() =
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
defer: setCurrentDir(gProjectDir)
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
discard execProc("git reset --hard HEAD")
|
let cmd = "git reset --hard HEAD"
|
||||||
|
while execCmdEx(cmd)[0].contains("Permission denied"):
|
||||||
|
sleep(1000)
|
||||||
|
echo " Retrying ..."
|
||||||
|
|
||||||
proc gitCheckout*(file: string) =
|
proc gitCheckout*(file: string) =
|
||||||
echo "Resetting " & file
|
echo "Resetting " & file
|
||||||
|
|
@ -59,9 +62,9 @@ proc gitCheckout*(file: string) =
|
||||||
defer: setCurrentDir(gProjectDir)
|
defer: setCurrentDir(gProjectDir)
|
||||||
|
|
||||||
let cmd = "git checkout $#" % file.replace(gOutput & "/", "")
|
let cmd = "git checkout $#" % file.replace(gOutput & "/", "")
|
||||||
if execCmdEx(cmd)[0].contains("Permission denied"):
|
while execCmdEx(cmd)[0].contains("Permission denied"):
|
||||||
sleep(500)
|
sleep(500)
|
||||||
discard execProc(cmd)
|
echo " Retrying ..."
|
||||||
|
|
||||||
proc gitRemotePull*(url: string, pull=true) =
|
proc gitRemotePull*(url: string, pull=true) =
|
||||||
if dirExists(gOutput/".git"):
|
if dirExists(gOutput/".git"):
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ proc getDefines*(file: string, inline=false): string =
|
||||||
for incl in incls:
|
for incl in incls:
|
||||||
let sincl = search(incl)
|
let sincl = search(incl)
|
||||||
if sincl != "":
|
if sincl != "":
|
||||||
echo "Inlining " & sincl
|
|
||||||
result &= getDefines(sincl)
|
result &= getDefines(sincl)
|
||||||
withFile(file):
|
withFile(file):
|
||||||
for def in content.findAll(re"(?m)^(\s*#\s*define\s+[\w\d_]+\s+[\d\-.xf]+)(?:\r|//|/*).*?$"):
|
for def in content.findAll(re"(?m)^(\s*#\s*define\s+[\w\d_]+\s+[\d\-.xf]+)(?:\r|//|/*).*?$"):
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
|
||||||
writeFileFlush(file, cfg[act])
|
writeFileFlush(file, cfg[act])
|
||||||
if file in gExcludes:
|
if file in gExcludes:
|
||||||
gExcludes.delete(gExcludes.find(file))
|
gExcludes.delete(gExcludes.find(file))
|
||||||
sfile = search(file)
|
sfile = file
|
||||||
gDoneRecursive.add(sfile)
|
gDoneRecursive.add(sfile)
|
||||||
elif action in @["prepend", "append", "replace", "comment",
|
elif action in @["prepend", "append", "replace", "comment",
|
||||||
"rename", "compile", "dynlib", "pragma",
|
"rename", "compile", "dynlib", "pragma",
|
||||||
|
|
@ -127,11 +127,11 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
|
||||||
echo "Cannot use recurse and inline simultaneously"
|
echo "Cannot use recurse and inline simultaneously"
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
if not noprocess:
|
removeStatic(sfile)
|
||||||
let outfile = getNimout(sfile)
|
fixFuncProtos(sfile)
|
||||||
c2nim(file, outfile, c2nimConfig)
|
|
||||||
|
|
||||||
if c2nimConfig.recurse:
|
let outfile = getNimout(sfile)
|
||||||
|
if c2nimConfig.recurse or c2nimConfig.inline:
|
||||||
var
|
var
|
||||||
cfg = newOrderedTable[string, string]()
|
cfg = newOrderedTable[string, string]()
|
||||||
incls = getIncls(sfile)
|
incls = getIncls(sfile)
|
||||||
|
|
@ -146,13 +146,20 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
|
||||||
for i in c2nimConfig.dynlib:
|
for i in c2nimConfig.dynlib:
|
||||||
cfg["dynlib." & i] = i
|
cfg["dynlib." & i] = i
|
||||||
|
|
||||||
|
if c2nimConfig.inline:
|
||||||
|
cfg["noprocess"] = "true"
|
||||||
|
|
||||||
for inc in incls:
|
for inc in incls:
|
||||||
runFile(inc, cfg)
|
runFile(inc, cfg)
|
||||||
|
if c2nimConfig.recurse:
|
||||||
incout &= "import $#\n" % inc.search().getNimout()[0 .. ^5]
|
incout &= "import $#\n" % inc.search().getNimout()[0 .. ^5]
|
||||||
|
|
||||||
if incout.len() != 0:
|
if c2nimConfig.recurse and incout.len() != 0:
|
||||||
prepend(outfile, incout)
|
prepend(outfile, incout)
|
||||||
|
|
||||||
|
if not noprocess:
|
||||||
|
c2nim(file, outfile, c2nimConfig)
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
gitCheckout(sfile)
|
gitCheckout(sfile)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue