Browse Source

HPCC-18977 Ensure failing to start g++ is reported in the workunit

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 7 years ago
parent
commit
7055276da6
2 changed files with 35 additions and 6 deletions
  1. 31 5
      system/jlib/jcomp.cpp
  2. 4 1
      system/jlib/jcomp.ipp

+ 31 - 5
system/jlib/jcomp.cpp

@@ -279,6 +279,13 @@ void CppCompiler::setPrecompileHeader(bool _pch)
     precompileHeader = _pch;
 }
 
+bool CppCompiler::fireException(IException *e)
+{
+    CriticalBlock block(cs);
+    exceptions.append(*LINK(e));
+    return true;
+}
+
 void CppCompiler::addDefine(const char * symbolName, const char * value)
 {
     compilerOptions.append(" ").append(USE_DEFINE_FLAG[targetCompiler]).append(symbolName);
@@ -384,7 +391,7 @@ bool CppCompiler::compile()
 
     TIME_SECTION(!verbose ? NULL : onlyCompile ? "compile" : "compile/link");
 
-    Owned<IThreadPool> pool = createThreadPool("CCompilerWorker", this, NULL, maxCompileThreads?maxCompileThreads:1, INFINITE);
+    Owned<IThreadPool> pool = createThreadPool("CCompilerWorker", this, this, maxCompileThreads?maxCompileThreads:1, INFINITE);
     addCompileOption(COMPILE_ONLY[targetCompiler]);
 
     bool ret = false;
@@ -523,6 +530,13 @@ bool CppCompiler::compileFile(IThreadPool * pool, const char * filename, Semapho
 
 void CppCompiler::extractErrors(IArrayOf<IError> & errors)
 {
+    ForEachItemIn(i, exceptions)
+    {
+        IException & cur = exceptions.item(i);
+        StringBuffer msg;
+        cur.errorMessage(msg);
+        errors.append(*createError(JLIBERR_CppCompileError, msg, nullptr));
+    }
     const char* cclog = ccLogPath.get();
     if(!cclog||!*cclog)
         cclog = queryCcLogName();
@@ -684,7 +698,17 @@ bool CppCompiler::doLink()
         PrintLog("%s", expanded.str());
     StringBuffer logFile = StringBuffer(coreName).append("_link.log.tmp");
     logFiles.append(logFile);
-    bool ret = invoke_program(expanded.str(), runcode, true, logFile) && (runcode == 0);
+
+    bool ret;
+    try
+    {
+        ret = invoke_program(expanded.str(), runcode, true, logFile, nullptr, true) && (runcode == 0);
+    }
+    catch (IException * e)
+    {
+        exceptions.append(*e);
+        ret = false;
+    }
     linkFailed = !ret;
     return ret;
 }
@@ -901,9 +925,10 @@ public:
         bool success;
         aborted = false;
         handle = 0;
+        Owned<IException> error;
         try
         {
-            success = invoke_program(params->cmdline, runcode, false, params->logfile, &handle, false, okToAbort);
+            success = invoke_program(params->cmdline, runcode, false, params->logfile, &handle, true, okToAbort);
             if (success)
                 wait_program(handle, runcode, true);
         }
@@ -911,7 +936,7 @@ public:
         {
             StringBuffer sb;
             e->errorMessage(sb);
-            e->Release();
+            error.setown(e);
             if (sb.length())
                 PrintLog("%s", sb.str());
             success = false;
@@ -921,7 +946,8 @@ public:
         if (!success || aborted)
             compiler->numFailed++;
         params->finishedCompiling.signal();
-        return;
+        if (error)
+            throw error.getClear();
     }
 
 private:

+ 4 - 1
system/jlib/jcomp.ipp

@@ -22,7 +22,7 @@
 
 #include "jlib.hpp"
 
-class CppCompiler : implements ICppCompiler, implements IThreadFactory, public CInterface
+class CppCompiler : implements ICppCompiler, implements IThreadFactory, public CInterface, implements IExceptionHandler
 {
 public:
     CppCompiler(const char * _coreName, const char * _sourceDir, const char * _targetDir, unsigned _targetCompiler, bool _verbose);
@@ -50,6 +50,7 @@ public:
     virtual void setSaveTemps(bool _save) { saveTemps = _save; }
     virtual void setPrecompileHeader(bool _pch);
     virtual void setAbortChecker(IAbortRequestCallback * _abortChecker) {abortChecker = _abortChecker;}
+    virtual bool fireException(IException *e);
 
 protected:
     void expandCompileOptions(StringBuffer & target);
@@ -85,6 +86,8 @@ protected:
     bool            precompileHeader;
     bool            linkFailed;
     IAbortRequestCallback * abortChecker;
+    CriticalSection cs;
+    IArrayOf<IException> exceptions;
 };