Fix #96 - run nim check on bad codegen
This commit is contained in:
parent
4152564b39
commit
1807580c71
1 changed files with 28 additions and 9 deletions
|
|
@ -77,11 +77,27 @@ proc getToastError(output: string): string =
|
||||||
# Filter out preprocessor errors
|
# Filter out preprocessor errors
|
||||||
for line in output.splitLines():
|
for line in output.splitLines():
|
||||||
if "fatal error:" in line.toLowerAscii:
|
if "fatal error:" in line.toLowerAscii:
|
||||||
result &= "\nERROR:$1\n" % line.split("fatal error:")[1]
|
result &= "\n\nERROR:$1\n" % line.split("fatal error:")[1]
|
||||||
|
|
||||||
# Toast error
|
# Toast error
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
result = output
|
result = "\n\n" & output
|
||||||
|
|
||||||
|
proc getNimCheckError(output: string): tuple[tmpFile, errors: string] =
|
||||||
|
let
|
||||||
|
hash = output.hash().abs()
|
||||||
|
|
||||||
|
result.tmpFile = getTempDir() / "nimterop_" & $hash & ".nim"
|
||||||
|
|
||||||
|
if not fileExists(result.tmpFile) or gStateCT.nocache or compileOption("forceBuild"):
|
||||||
|
writeFile(result.tmpFile, output)
|
||||||
|
|
||||||
|
doAssert fileExists(result.tmpFile), "Bad codegen - unable to write to TEMP: " & result.tmpFile
|
||||||
|
|
||||||
|
let
|
||||||
|
(check, ret) = gorgeEx("nim check " & result.tmpFile)
|
||||||
|
|
||||||
|
result.errors = "\n\n" & check
|
||||||
|
|
||||||
proc getToast(fullpath: string, recurse: bool = false): string =
|
proc getToast(fullpath: string, recurse: bool = false): string =
|
||||||
var
|
var
|
||||||
|
|
@ -433,11 +449,14 @@ macro cImport*(filename: static string, recurse: static bool = false): untyped =
|
||||||
output = getToast(fullpath, recurse)
|
output = getToast(fullpath, recurse)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result.add parseStmt(output)
|
let body = parseStmt(output)
|
||||||
except:
|
|
||||||
echo output
|
result.add body
|
||||||
echo "Failed to import generated nim"
|
|
||||||
result.add parseStmt(output)
|
if gStateCT.debug:
|
||||||
|
echo result.repr
|
||||||
|
except:
|
||||||
|
let
|
||||||
|
(tmpFile, errors) = getNimCheckError(output)
|
||||||
|
doAssert false, errors & "Nimterop codegen limitation or error - review 'nim check' output above generated for " & tmpFile
|
||||||
|
|
||||||
if gStateCT.debug:
|
|
||||||
echo result.repr
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue