aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-08-03 23:27:26 -0500
committerGanesh Viswanathan <dev@genotrance.com>2018-08-03 23:27:26 -0500
commit1dbff5cbd14f69529869720e72e153f6f9029957 (patch)
tree6c96b39dc00045c1c80a4708213b28b1f23c39e8
parent2c3cc71540f94783a98f34a82afc5c40bf320dd3 (diff)
downloadnimgen-1dbff5cbd14f69529869720e72e153f6f9029957.tar.gz
nimgen-1dbff5cbd14f69529869720e72e153f6f9029957.zip
Inline fixes
-rw-r--r--nimgen.nimble2
-rw-r--r--src/nimgen/c2nim.nim12
-rw-r--r--src/nimgen/external.nim9
-rw-r--r--src/nimgen/gencore.nim1
-rw-r--r--src/nimgen/runcfg.nim47
5 files changed, 36 insertions, 35 deletions
diff --git a/nimgen.nimble b/nimgen.nimble
index 3e65545..841cb09 100644
--- a/nimgen.nimble
+++ b/nimgen.nimble
@@ -1,6 +1,6 @@
# Package
-version = "0.3.0"
+version = "0.3.1"
author = "genotrance"
description = "c2nim helper to simplify and automate the wrapping of C libraries"
license = "MIT"
diff --git a/src/nimgen/c2nim.nim b/src/nimgen/c2nim.nim
index 428c767..73e4ebb 100644
--- a/src/nimgen/c2nim.nim
+++ b/src/nimgen/c2nim.nim
@@ -10,12 +10,7 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
if file.len() == 0:
return
- echo " Generating " & outfile
-
- # Remove static inline function bodies
- removeStatic(file)
-
- fixFuncProtos(file)
+ echo "Generating " & outfile
var cfile = file
if c2nimConfig.preprocess:
@@ -121,7 +116,4 @@ proc c2nim*(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
# Add dynamic library
if outlib != "":
- prepend(outfile, outlib)
-
- # Add back static functions for compilation
- reAddStatic(file)
+ prepend(outfile, outlib) \ No newline at end of file
diff --git a/src/nimgen/external.nim b/src/nimgen/external.nim
index 9575c38..571c7e0 100644
--- a/src/nimgen/external.nim
+++ b/src/nimgen/external.nim
@@ -50,7 +50,10 @@ proc gitReset*() =
setCurrentDir(gOutput)
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) =
echo "Resetting " & file
@@ -59,9 +62,9 @@ proc gitCheckout*(file: string) =
defer: setCurrentDir(gProjectDir)
let cmd = "git checkout $#" % file.replace(gOutput & "/", "")
- if execCmdEx(cmd)[0].contains("Permission denied"):
+ while execCmdEx(cmd)[0].contains("Permission denied"):
sleep(500)
- discard execProc(cmd)
+ echo " Retrying ..."
proc gitRemotePull*(url: string, pull=true) =
if dirExists(gOutput/".git"):
diff --git a/src/nimgen/gencore.nim b/src/nimgen/gencore.nim
index 382fa59..ff070df 100644
--- a/src/nimgen/gencore.nim
+++ b/src/nimgen/gencore.nim
@@ -87,7 +87,6 @@ proc getDefines*(file: string, inline=false): string =
for incl in incls:
let sincl = search(incl)
if sincl != "":
- echo "Inlining " & sincl
result &= getDefines(sincl)
withFile(file):
for def in content.findAll(re"(?m)^(\s*#\s*define\s+[\w\d_]+\s+[\d\-.xf]+)(?:\r|//|/*).*?$"):
diff --git a/src/nimgen/runcfg.nim b/src/nimgen/runcfg.nim
index 95cb1c4..fd65708 100644
--- a/src/nimgen/runcfg.nim
+++ b/src/nimgen/runcfg.nim
@@ -60,7 +60,7 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
writeFileFlush(file, cfg[act])
if file in gExcludes:
gExcludes.delete(gExcludes.find(file))
- sfile = search(file)
+ sfile = file
gDoneRecursive.add(sfile)
elif action in @["prepend", "append", "replace", "comment",
"rename", "compile", "dynlib", "pragma",
@@ -127,31 +127,38 @@ proc runFile*(file: string, cfgin: OrderedTableRef = newOrderedTable[string, str
echo "Cannot use recurse and inline simultaneously"
quit(1)
- if not noprocess:
- let outfile = getNimout(sfile)
- c2nim(file, outfile, c2nimConfig)
+ removeStatic(sfile)
+ fixFuncProtos(sfile)
+
+ let outfile = getNimout(sfile)
+ if c2nimConfig.recurse or c2nimConfig.inline:
+ var
+ cfg = newOrderedTable[string, string]()
+ incls = getIncls(sfile)
+ incout = ""
- if c2nimConfig.recurse:
- var
- cfg = newOrderedTable[string, string]()
- incls = getIncls(sfile)
- incout = ""
+ for name, value in c2nimConfig.fieldPairs:
+ when value is string:
+ cfg[name] = value
+ when value is bool:
+ cfg[name] = $value
- for name, value in c2nimConfig.fieldPairs:
- when value is string:
- cfg[name] = value
- when value is bool:
- cfg[name] = $value
+ for i in c2nimConfig.dynlib:
+ cfg["dynlib." & i] = i
- for i in c2nimConfig.dynlib:
- cfg["dynlib." & i] = i
+ if c2nimConfig.inline:
+ cfg["noprocess"] = "true"
- for inc in incls:
- runFile(inc, cfg)
+ for inc in incls:
+ runFile(inc, cfg)
+ if c2nimConfig.recurse:
incout &= "import $#\n" % inc.search().getNimout()[0 .. ^5]
- if incout.len() != 0:
- prepend(outfile, incout)
+ if c2nimConfig.recurse and incout.len() != 0:
+ prepend(outfile, incout)
+
+ if not noprocess:
+ c2nim(file, outfile, c2nimConfig)
if reset:
gitCheckout(sfile)