Error Message if CC invocation fails (#5663)

This commit is contained in:
Fredrik Høisæther Rasch 2017-04-08 19:06:19 +02:00 • committed by Andreas Rumpf
commit 392f025148

View file

@ -697,6 +697,17 @@ proc getLinkCmd(projectfile, objfiles: string): string =
"nim", quoteShell(getPrefixDir()), "nim", quoteShell(getPrefixDir()),
"lib", quoteShell(libpath)]) "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) = proc callCCompiler*(projectfile: string) =
var var
linkCmd: string linkCmd: string
@ -721,17 +732,20 @@ proc callCCompiler*(projectfile: string) =
var res = 0 var res = 0
if gNumberOfProcessors <= 1: if gNumberOfProcessors <= 1:
for i in countup(0, high(cmds)): 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]) 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: else:
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams}, tryExceptOSErrorMessage("invocation of external compiler program failed."):
gNumberOfProcessors, afterRunEvent=runCb) 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 res != 0:
if gNumberOfProcessors <= 1: if gNumberOfProcessors <= 1:
rawMessage(errExecutionOfProgramFailed, cmds.join()) rawMessage(errExecutionOfProgramFailed, cmds.join())
@ -749,8 +763,9 @@ proc callCCompiler*(projectfile: string) =
linkCmd = getLinkCmd(projectfile, objfiles) linkCmd = getLinkCmd(projectfile, objfiles)
if optCompileOnly notin gGlobalOptions: if optCompileOnly notin gGlobalOptions:
execExternalProgram(linkCmd, tryExceptOSErrorMessage("invocation of external linker program failed."):
if optListCmd in gGlobalOptions or gVerbosity > 1: hintExecuting else: hintLinking) execExternalProgram(linkCmd,
if optListCmd in gGlobalOptions or gVerbosity > 1: hintExecuting else: hintLinking)
else: else:
linkCmd = "" linkCmd = ""
if optGenScript in gGlobalOptions: if optGenScript in gGlobalOptions: