diff options
author | Fredrik Høisæther Rasch <fredrik.rasch@gmail.com> | 2017-04-08 19:06:19 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-04-08 19:06:19 +0200 |
commit | 392f02514885d8e6de9af44642001ab0ca621c6b (patch) | |
tree | 57066f61c30038a8d3d0a3d4d37aceaad21a1816 /compiler/extccomp.nim | |
parent | 6eb74c72811a9aba497417df12a9ad031e735b02 (diff) | |
download | Nim-392f02514885d8e6de9af44642001ab0ca621c6b.tar.gz |
Error Message if CC invocation fails (#5663)
Diffstat (limited to 'compiler/extccomp.nim')
-rw-r--r-- | compiler/extccomp.nim | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 1af113be6..ca4f621e4 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -697,6 +697,17 @@ proc getLinkCmd(projectfile, objfiles: string): string = "nim", quoteShell(getPrefixDir()), "lib", quoteShell(libpath)]) +template tryExceptOSErrorMessage(errorPrefix: string = "", body: untyped): typed = + try: + body + except OSError: + let ose = (ref OSError)(getCurrentException()) + if errorPrefix.len > 0: + rawMessage(errGenerated, errorPrefix & " " & ose.msg & " " & $ose.errorCode) + else: + rawMessage(errExecutionOfProgramFailed, ose.msg & " " & $ose.errorCode) + raise + proc callCCompiler*(projectfile: string) = var linkCmd: string @@ -721,17 +732,20 @@ proc callCCompiler*(projectfile: string) = var res = 0 if gNumberOfProcessors <= 1: for i in countup(0, high(cmds)): - res = execWithEcho(cmds[i]) + tryExceptOSErrorMessage("invocation of external compiler program failed."): + res = execWithEcho(cmds[i]) if res != 0: rawMessage(errExecutionOfProgramFailed, cmds[i]) - elif optListCmd in gGlobalOptions or gVerbosity > 1: - res = execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams}, - gNumberOfProcessors, afterRunEvent=runCb) - elif gVerbosity == 1: - res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams}, - gNumberOfProcessors, prettyCb, afterRunEvent=runCb) else: - res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams}, - gNumberOfProcessors, afterRunEvent=runCb) + tryExceptOSErrorMessage("invocation of external compiler program failed."): + if optListCmd in gGlobalOptions or gVerbosity > 1: + res = execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams}, + gNumberOfProcessors, afterRunEvent=runCb) + elif gVerbosity == 1: + res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams}, + gNumberOfProcessors, prettyCb, afterRunEvent=runCb) + else: + res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams}, + gNumberOfProcessors, afterRunEvent=runCb) if res != 0: if gNumberOfProcessors <= 1: rawMessage(errExecutionOfProgramFailed, cmds.join()) @@ -749,8 +763,9 @@ proc callCCompiler*(projectfile: string) = linkCmd = getLinkCmd(projectfile, objfiles) if optCompileOnly notin gGlobalOptions: - execExternalProgram(linkCmd, - if optListCmd in gGlobalOptions or gVerbosity > 1: hintExecuting else: hintLinking) + tryExceptOSErrorMessage("invocation of external linker program failed."): + execExternalProgram(linkCmd, + if optListCmd in gGlobalOptions or gVerbosity > 1: hintExecuting else: hintLinking) else: linkCmd = "" if optGenScript in gGlobalOptions: |