Support 0.17.0 onwards, fix IOError
This commit is contained in:
parent
bb881a2e65
commit
a0369758af
2 changed files with 11 additions and 15 deletions
24
nimgen.nim
24
nimgen.nim
|
|
@ -194,15 +194,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()
|
||||||
|
|
@ -211,7 +213,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:
|
||||||
|
|
@ -476,9 +478,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
cfile = "temp-$#.c" % [outfile.extractFilename()]
|
cfile = "temp-$#.c" % [outfile.extractFilename()]
|
||||||
writeFile(cfile, runCtags(file))
|
writeFile(cfile, runCtags(file))
|
||||||
|
|
||||||
while not fileExists(cfile):
|
|
||||||
sleep(10)
|
|
||||||
|
|
||||||
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
||||||
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
||||||
|
|
||||||
|
|
@ -534,9 +533,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
cmd = "cmd /c " & cmd
|
cmd = "cmd /c " & cmd
|
||||||
discard execProc(cmd)
|
discard execProc(cmd)
|
||||||
|
|
||||||
while not fileExists(outfile):
|
|
||||||
sleep(10)
|
|
||||||
|
|
||||||
if c2nimConfig.preprocess or c2nimConfig.ctags:
|
if c2nimConfig.preprocess or c2nimConfig.ctags:
|
||||||
try:
|
try:
|
||||||
removeFile(cfile)
|
removeFile(cfile)
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue