diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index d992c04..114ab80 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -82,18 +82,6 @@ proc getCacheValue(fullpaths: seq[string]): string = for fullpath in fullpaths: result &= getCacheValue(fullpath) -proc getToastError(output: string): string = - # Filter out preprocessor errors - for line in output.splitLines(): - if "fatal error:" in line.toLowerAscii: - if result.len == 0: - result = "\n\nFailed in preprocessing, check if `cIncludeDir()` is needed or compiler `mode` is correct (c/cpp)" - result &= "\n\nERROR:$1\n" % line.split("fatal error:")[1] - - # Toast error - if result.Bl: - result = "\n\n" & output - proc getNimCheckError(nimFile: string) = let (check, _) = execAction( @@ -159,7 +147,7 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = "" when defined(Windows): result = result.replace(DirSep, '/') - if not fileExists(result) or compileOption("forceBuild"): + if not fileExists(result) or gStateCT.nocache or compileOption("forceBuild"): let dir = result.parentDir() if not dirExists(dir): @@ -168,8 +156,8 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = "" cmd.add &" -o {result.sanitizePath}" var - (_, ret) = execAction(cmd, die = false) - doAssert ret == 0, getToastError(result.readFile()) + (output, ret) = execAction(cmd, die = false) + doAssert ret == 0, result.readFile() & output macro cOverride*(body): untyped = ## When the wrapper code generated by nimterop is missing certain symbols or not @@ -577,6 +565,8 @@ macro cImport*(filenames: static seq[string], recurse: static bool = false, dynl if gStateCT.debug: gecho nimFile.readFile() + gecho "# Saved to " & nimFile + try: let nimFileNode = newStrLitNode(nimFile.changeFileExt("")) @@ -673,7 +663,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib: nimFile = if nimFile.nBl: fixRelFile(nimFile) else: hFile.changeFileExt("nim") header = "header" & fullpath.splitFile().name.split(seps = {'-', '.'}).join() - if not fileExists(nimFile) or compileOption("forceBuild"): + if not fileExists(nimFile) or gStateCT.nocache or compileOption("forceBuild"): var cmd = when defined(Windows): "cmd /c " else: "" cmd &= &"c2nim {hFile} --header:{header} --out:{nimFile.sanitizePath}" @@ -699,6 +689,8 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib: if gStateCT.debug: gecho nimFile.readFile() + gecho "# Saved to " & nimFile + try: let nimFileNode = newStrLitNode(nimFile.changeFileExt("")) diff --git a/nimterop/toastlib/getters.nim b/nimterop/toastlib/getters.nim index bfbd4be..df930bb 100644 --- a/nimterop/toastlib/getters.nim +++ b/nimterop/toastlib/getters.nim @@ -338,6 +338,10 @@ proc getPreprocessor*(gState: State, fullpath: string) = start = true newHeaders.incl line break + elif ": fatal error:" in line: + doAssert false, + "\n\nFailed in preprocessing, check if `cIncludeDir()` is needed or compiler `mode` is correct (c/cpp)" & + "\n\nERROR:$1\n" % line.split(": fatal error:")[1] else: if start: if "#undef" in line: @@ -345,6 +349,9 @@ proc getPreprocessor*(gState: State, fullpath: string) = gState.code.add line & "\n" elif not p.running(): break p.close() + assert p.peekExitCode() == 0, + gState.code & "\n\nFailed in preprocessing:\n " & + getCompiler() & " " & args.join(" ") gState.headersProcessed.incl newHeaders # Plugin related diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 06a0078..f9e0017 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -276,7 +276,7 @@ typedef union sx_ivec3 { struct { int x; int y; - struct z { + struct { int z; }; };