summary refs log tree commit diff stats
path: root/compiler/extccomp.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/extccomp.nim')
-rw-r--r--compiler/extccomp.nim37
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: