cmCTestBuildHandler.cxx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestBuildHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmGeneratedFileStream.h"
  20. //#include <cmsys/RegularExpression.hxx>
  21. #include <cmsys/Process.h>
  22. // used for sleep
  23. #ifdef _WIN32
  24. #include "windows.h"
  25. #endif
  26. #include <stdlib.h>
  27. #include <time.h>
  28. #include <math.h>
  29. #include <float.h>
  30. static const char* cmCTestErrorMatches[] = {
  31. "^[Bb]us [Ee]rror",
  32. "^[Ss]egmentation [Vv]iolation",
  33. "^[Ss]egmentation [Ff]ault",
  34. "([^ :]+):([0-9]+): ([^ \\t])",
  35. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  36. "^Error ([0-9]+):",
  37. "^Fatal",
  38. "^Error: ",
  39. "^Error ",
  40. "[0-9] ERROR: ",
  41. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  42. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  43. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  44. "^ild:([ \\t])*\\(undefined symbol\\)",
  45. "([^ :]+) : (error|fatal error|catastrophic error)",
  46. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  47. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  48. "^fatal error C[0-9]+:",
  49. ": syntax error ",
  50. "^collect2: ld returned 1 exit status",
  51. "Unsatisfied symbols:",
  52. "^Unresolved:",
  53. "Undefined symbols:",
  54. "^Undefined[ \\t]+first referenced",
  55. "^CMake Error:",
  56. ":[ \\t]cannot find",
  57. ":[ \\t]can't find",
  58. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  59. ": Invalid loader fixup for symbol",
  60. ": Invalid fixups exist",
  61. ": Can't find library for",
  62. ": internal link edit command failed",
  63. ": Unrecognized option \\`.*\\'",
  64. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
  65. "ld: 0706-006 Cannot find or open library file: -l ",
  66. "ild: \\(argument error\\) can't find library argument ::",
  67. "^could not be found and will not be loaded.",
  68. "s:616 string too big",
  69. "make: Fatal error: ",
  70. "ld: 0711-993 Error occurred while writing to the output file:",
  71. "ld: fatal: ",
  72. "final link failed:",
  73. "make: \\*\\*\\*.*Error",
  74. "make\\[.*\\]: \\*\\*\\*.*Error",
  75. "\\*\\*\\* Error code",
  76. "nternal error:",
  77. "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
  78. 0
  79. };
  80. static const char* cmCTestErrorExceptions[] = {
  81. "instantiated from ",
  82. "candidates are:",
  83. ": warning",
  84. ": \\(Warning\\)",
  85. "makefile:",
  86. "Makefile:",
  87. ":[ \\t]+Where:",
  88. "([^ :]+):([0-9]+): Warning",
  89. "------ Build started: .* ------",
  90. 0
  91. };
  92. static const char* cmCTestWarningMatches[] = {
  93. "([^ :]+):([0-9]+): warning:",
  94. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  95. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  96. "([^:]+): warning ([0-9]+):",
  97. "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
  98. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  99. "^(Warning|Warnung) ([0-9]+):",
  100. "^(Warning|Warnung) ",
  101. "WARNING: ",
  102. "([^ :]+) : warning",
  103. "([^:]+): warning",
  104. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
  105. "^cxx: Warning:",
  106. ".*file: .* has no symbols",
  107. "([^ :]+):([0-9]+): (Warning|Warnung)",
  108. "\\([0-9]*\\): remark #[0-9]*",
  109. "\".*\", line [0-9]+: remark\\([0-9]*\\):",
  110. "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
  111. 0
  112. };
  113. static const char* cmCTestWarningExceptions[] = {
  114. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  115. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  116. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  117. "WARNING 84 :",
  118. "WARNING 47 :",
  119. "makefile:",
  120. "Makefile:",
  121. "warning: Clock skew detected. Your build may be incomplete.",
  122. "/usr/openwin/include/GL/[^:]+:",
  123. "bind_at_load",
  124. "XrmQGetResource",
  125. "IceFlush",
  126. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  127. "ld32: WARNING 85: definition of dataKey in",
  128. "cc: warning 422: Unknown option \"\\+b",
  129. "_with_warning_C",
  130. 0
  131. };
  132. struct cmCTestBuildCompileErrorWarningRex
  133. {
  134. const char* m_RegularExpressionString;
  135. int m_FileIndex;
  136. int m_LineIndex;
  137. };
  138. static cmCTestBuildCompileErrorWarningRex
  139. cmCTestWarningErrorFileLine[] = {
  140. { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
  141. { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
  142. { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  143. { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  144. { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
  145. { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
  146. { 0, 0, 0 }
  147. };
  148. //----------------------------------------------------------------------
  149. cmCTestBuildHandler::cmCTestBuildHandler()
  150. {
  151. m_MaxPreContext = 6;
  152. m_MaxPostContext = 6;
  153. m_MaxErrors = 50;
  154. m_MaxWarnings = 50;
  155. m_LastErrorOrWarning = m_ErrorsAndWarnings.end();
  156. }
  157. //----------------------------------------------------------------------
  158. void cmCTestBuildHandler::Initialize()
  159. {
  160. this->Superclass::Initialize();
  161. m_StartBuild = "";
  162. m_EndBuild = "";
  163. m_CustomErrorMatches.clear();
  164. m_CustomErrorExceptions.clear();
  165. m_CustomWarningMatches.clear();
  166. m_CustomWarningExceptions.clear();
  167. m_ErrorWarningFileLineRegex.clear();
  168. m_ErrorMatchRegex.clear();
  169. m_ErrorExceptionRegex.clear();
  170. m_WarningMatchRegex.clear();
  171. m_WarningExceptionRegex.clear();
  172. m_BuildProcessingQueue.clear();
  173. m_BuildProcessingErrorQueue.clear();
  174. m_BuildOutputLogSize = 0;
  175. m_CurrentProcessingLine.clear();
  176. m_SimplifySourceDir = "";
  177. m_SimplifyBuildDir = "";
  178. m_OutputLineCounter = 0;
  179. m_ErrorsAndWarnings.clear();
  180. m_LastErrorOrWarning = m_ErrorsAndWarnings.end();
  181. m_PostContextCount = 0;
  182. m_MaxPreContext = 6;
  183. m_MaxPostContext = 6;
  184. m_PreContext.clear();
  185. m_TotalErrors = 0;
  186. m_TotalWarnings = 0;
  187. m_LastTickChar = 0;
  188. m_ErrorQuotaReached = false;
  189. m_WarningQuotaReached = false;
  190. m_MaxErrors = 50;
  191. m_MaxWarnings = 50;
  192. }
  193. //----------------------------------------------------------------------
  194. void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)
  195. {
  196. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
  197. m_CustomErrorMatches);
  198. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
  199. m_CustomErrorExceptions);
  200. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
  201. m_CustomWarningMatches);
  202. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
  203. m_CustomWarningExceptions);
  204. cmCTest::PopulateCustomInteger(mf,
  205. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
  206. m_MaxErrors);
  207. cmCTest::PopulateCustomInteger(mf,
  208. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
  209. m_MaxWarnings);
  210. }
  211. //----------------------------------------------------------------------
  212. //clearly it would be nice if this were broken up into a few smaller
  213. //functions and commented...
  214. int cmCTestBuildHandler::ProcessHandler()
  215. {
  216. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Build project" << std::endl);
  217. int entry;
  218. for ( entry = 0; cmCTestWarningErrorFileLine[entry].m_RegularExpressionString; ++ entry )
  219. {
  220. cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
  221. if ( r.m_RegularExpression.compile(
  222. cmCTestWarningErrorFileLine[entry].m_RegularExpressionString) )
  223. {
  224. r.m_FileIndex = cmCTestWarningErrorFileLine[entry].m_FileIndex;
  225. r.m_LineIndex = cmCTestWarningErrorFileLine[entry].m_LineIndex;
  226. m_ErrorWarningFileLineRegex.push_back(r);
  227. }
  228. else
  229. {
  230. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem Compiling regular expression: "
  231. << cmCTestWarningErrorFileLine[entry].m_RegularExpressionString << std::endl);
  232. }
  233. }
  234. // Determine build command and build directory
  235. const std::string &makeCommand = m_CTest->GetCTestConfiguration("MakeCommand");
  236. if ( makeCommand.size() == 0 )
  237. {
  238. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl);
  239. return -1;
  240. }
  241. const std::string &buildDirectory = m_CTest->GetCTestConfiguration("BuildDirectory");
  242. if ( buildDirectory.size() == 0 )
  243. {
  244. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl);
  245. return -1;
  246. }
  247. // Create a last build log
  248. cmGeneratedFileStream ofs;
  249. double elapsed_time_start = cmSystemTools::GetTime();
  250. if ( !this->StartLogFile("Build", ofs) )
  251. {
  252. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot create build log file" << std::endl);
  253. }
  254. // Create lists of regular expression strings for errors, error exceptions,
  255. // warnings and warning exceptions.
  256. std::vector<cmStdString>::size_type cc;
  257. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  258. {
  259. m_CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  260. }
  261. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  262. {
  263. m_CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  264. }
  265. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  266. {
  267. m_CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  268. }
  269. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  270. {
  271. m_CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  272. }
  273. // Pre-compile regular expressions objects for all regular expressions
  274. std::vector<cmStdString>::iterator it;
  275. #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
  276. regexes.clear(); \
  277. for ( it = strings.begin(); it != strings.end(); ++it ) \
  278. { \
  279. regexes.push_back(it->c_str()); \
  280. }
  281. cmCTestBuildHandlerPopulateRegexVector(m_CustomErrorMatches, m_ErrorMatchRegex);
  282. cmCTestBuildHandlerPopulateRegexVector(m_CustomErrorExceptions, m_ErrorExceptionRegex);
  283. cmCTestBuildHandlerPopulateRegexVector(m_CustomWarningMatches, m_WarningMatchRegex);
  284. cmCTestBuildHandlerPopulateRegexVector(m_CustomWarningExceptions, m_WarningExceptionRegex);
  285. // Determine source and binary tree substitutions to simplify the output.
  286. m_SimplifySourceDir = "";
  287. m_SimplifyBuildDir = "";
  288. if ( m_CTest->GetCTestConfiguration("SourceDirectory").size() > 20 )
  289. {
  290. std::string srcdir = m_CTest->GetCTestConfiguration("SourceDirectory") + "/";
  291. std::string srcdirrep;
  292. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  293. {
  294. if ( srcdir[cc] == '/' )
  295. {
  296. srcdirrep = srcdir.c_str() + cc;
  297. srcdirrep = "/..." + srcdirrep;
  298. srcdir = srcdir.substr(0, cc+1);
  299. break;
  300. }
  301. }
  302. m_SimplifySourceDir = srcdir;
  303. }
  304. if ( m_CTest->GetCTestConfiguration("BuildDirectory").size() > 20 )
  305. {
  306. std::string bindir = m_CTest->GetCTestConfiguration("BuildDirectory") + "/";
  307. std::string bindirrep;
  308. for ( cc = bindir.size()-2; cc > 0; cc -- )
  309. {
  310. if ( bindir[cc] == '/' )
  311. {
  312. bindirrep = bindir.c_str() + cc;
  313. bindirrep = "/..." + bindirrep;
  314. bindir = bindir.substr(0, cc+1);
  315. break;
  316. }
  317. }
  318. m_SimplifyBuildDir = bindir;
  319. }
  320. // Ok, let's do the build
  321. // Remember start build time
  322. m_StartBuild = m_CTest->CurrentTime();
  323. int retVal = 0;
  324. int res = cmsysProcess_State_Exited;
  325. if ( !m_CTest->GetShowOnly() )
  326. {
  327. res = this->RunMakeCommand(makeCommand.c_str(), &retVal, buildDirectory.c_str(), 0, ofs);
  328. }
  329. else
  330. {
  331. cmCTestLog(m_CTest, DEBUG, "Build with command: " << makeCommand << std::endl);
  332. }
  333. // Remember end build time and calculate elapsed time
  334. m_EndBuild = m_CTest->CurrentTime();
  335. double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
  336. if (res != cmsysProcess_State_Exited || retVal )
  337. {
  338. cmCTestLog(m_CTest, ERROR_MESSAGE, "Error(s) when building project" << std::endl);
  339. }
  340. // Cleanups strings in the errors and warnings list.
  341. t_ErrorsAndWarningsVector::iterator evit;
  342. if ( !m_SimplifySourceDir.empty() )
  343. {
  344. for ( evit = m_ErrorsAndWarnings.begin(); evit != m_ErrorsAndWarnings.end(); ++ evit )
  345. {
  346. cmSystemTools::ReplaceString(evit->m_Text, m_SimplifySourceDir.c_str(), "/.../");
  347. cmSystemTools::ReplaceString(evit->m_PreContext, m_SimplifySourceDir.c_str(), "/.../");
  348. cmSystemTools::ReplaceString(evit->m_PostContext, m_SimplifySourceDir.c_str(), "/.../");
  349. }
  350. }
  351. if ( !m_SimplifyBuildDir.empty() )
  352. {
  353. for ( evit = m_ErrorsAndWarnings.begin(); evit != m_ErrorsAndWarnings.end(); ++ evit )
  354. {
  355. cmSystemTools::ReplaceString(evit->m_Text, m_SimplifyBuildDir.c_str(), "/.../");
  356. cmSystemTools::ReplaceString(evit->m_PreContext, m_SimplifyBuildDir.c_str(), "/.../");
  357. cmSystemTools::ReplaceString(evit->m_PostContext, m_SimplifyBuildDir.c_str(), "/.../");
  358. }
  359. }
  360. // Display message about number of errors and warnings
  361. cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << m_TotalErrors
  362. << (m_TotalErrors >= m_MaxErrors ? " or more" : "")
  363. << " Compiler errors" << std::endl);
  364. cmCTestLog(m_CTest, HANDLER_OUTPUT, " " << m_TotalWarnings
  365. << (m_TotalWarnings >= m_MaxWarnings ? " or more" : "")
  366. << " Compiler warnings" << std::endl);
  367. // Generate XML output
  368. cmGeneratedFileStream xofs;
  369. if( !this->StartResultingXML("Build", xofs))
  370. {
  371. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot create build XML file" << std::endl);
  372. return -1;
  373. }
  374. this->GenerateDartBuildOutput(xofs, m_ErrorsAndWarnings, elapsed_build_time);
  375. return 0;
  376. }
  377. //----------------------------------------------------------------------
  378. void cmCTestBuildHandler::GenerateDartBuildOutput(
  379. std::ostream& os,
  380. std::vector<cmCTestBuildErrorWarning> ew,
  381. double elapsed_build_time)
  382. {
  383. m_CTest->StartXML(os);
  384. os << "<Build>\n"
  385. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  386. << "<BuildCommand>"
  387. << m_CTest->MakeXMLSafe(m_CTest->GetCTestConfiguration("MakeCommand"))
  388. << "</BuildCommand>" << std::endl;
  389. std::vector<cmCTestBuildErrorWarning>::iterator it;
  390. // only report the first 50 warnings and first 50 errors
  391. unsigned short numErrorsAllowed = m_MaxErrors;
  392. unsigned short numWarningsAllowed = m_MaxWarnings;
  393. std::string srcdir = m_CTest->GetCTestConfiguration("SourceDirectory");
  394. // make sure the source dir is in the correct case on windows
  395. // via a call to collapse full path.
  396. srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str());
  397. srcdir += "/";
  398. for ( it = ew.begin();
  399. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
  400. {
  401. cmCTestBuildErrorWarning *cm = &(*it);
  402. if (cm->m_Error && numErrorsAllowed ||
  403. !cm->m_Error && numWarningsAllowed)
  404. {
  405. if (cm->m_Error)
  406. {
  407. numErrorsAllowed--;
  408. }
  409. else
  410. {
  411. numWarningsAllowed--;
  412. }
  413. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  414. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  415. << "\t\t<Text>" << m_CTest->MakeXMLSafe(cm->m_Text)
  416. << "\n</Text>" << std::endl;
  417. std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
  418. for ( rit = m_ErrorWarningFileLineRegex.begin();
  419. rit != m_ErrorWarningFileLineRegex.end(); ++ rit )
  420. {
  421. cmsys::RegularExpression* re = &rit->m_RegularExpression;
  422. if ( re->find(cm->m_Text.c_str() ) )
  423. {
  424. cm->m_SourceFile = re->match(rit->m_FileIndex);
  425. // At this point we need to make m_SourceFile relative to
  426. // the source root of the project, so cvs links will work
  427. cmSystemTools::ConvertToUnixSlashes(cm->m_SourceFile);
  428. if(cm->m_SourceFile.find("/.../") != cm->m_SourceFile.npos)
  429. {
  430. cmSystemTools::ReplaceString(cm->m_SourceFile, "/.../", "");
  431. std::string::size_type p = cm->m_SourceFile.find("/");
  432. if(p != cm->m_SourceFile.npos)
  433. {
  434. cm->m_SourceFile = cm->m_SourceFile.substr(p+1, cm->m_SourceFile.size()-p);
  435. }
  436. }
  437. else
  438. {
  439. // make sure it is a full path with the correct case
  440. cm->m_SourceFile = cmSystemTools::CollapseFullPath(cm->m_SourceFile.c_str());
  441. cmSystemTools::ReplaceString(cm->m_SourceFile, srcdir.c_str(), "");
  442. }
  443. cm->m_LineNumber = atoi(re->match(rit->m_LineIndex).c_str());
  444. break;
  445. }
  446. }
  447. if ( cm->m_SourceFile.size() > 0 )
  448. {
  449. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  450. << std::endl;
  451. }
  452. if ( cm->m_SourceFileTail.size() > 0 )
  453. {
  454. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  455. << "</SourceFileTail>" << std::endl;
  456. }
  457. if ( cm->m_LineNumber >= 0 )
  458. {
  459. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  460. << "</SourceLineNumber>" << std::endl;
  461. }
  462. os << "\t\t<PreContext>" << m_CTest->MakeXMLSafe(cm->m_PreContext)
  463. << "</PreContext>\n"
  464. << "\t\t<PostContext>" << m_CTest->MakeXMLSafe(cm->m_PostContext);
  465. // is this the last warning or error, if so notify
  466. if (cm->m_Error && !numErrorsAllowed ||
  467. !cm->m_Error && !numWarningsAllowed)
  468. {
  469. os << "\nThe maximum number of reported warnings or errors has been reached!!!\n";
  470. }
  471. os << "</PostContext>\n"
  472. << "\t\t<RepeatCount>0</RepeatCount>\n"
  473. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  474. << std::endl;
  475. }
  476. }
  477. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  478. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  479. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  480. << "</ElapsedMinutes>"
  481. << "</Build>" << std::endl;
  482. m_CTest->EndXML(os);
  483. }
  484. //######################################################################
  485. //######################################################################
  486. //######################################################################
  487. //######################################################################
  488. //----------------------------------------------------------------------
  489. int cmCTestBuildHandler::RunMakeCommand(const char* command,
  490. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  491. {
  492. // First generate the command and arguments
  493. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  494. if(args.size() < 1)
  495. {
  496. return false;
  497. }
  498. std::vector<const char*> argv;
  499. for(std::vector<cmStdString>::const_iterator a = args.begin();
  500. a != args.end(); ++a)
  501. {
  502. argv.push_back(a->c_str());
  503. }
  504. argv.push_back(0);
  505. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
  506. std::vector<const char*>::iterator ait;
  507. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  508. {
  509. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  510. }
  511. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  512. // Now create process object
  513. cmsysProcess* cp = cmsysProcess_New();
  514. cmsysProcess_SetCommand(cp, &*argv.begin());
  515. cmsysProcess_SetWorkingDirectory(cp, dir);
  516. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  517. cmsysProcess_SetTimeout(cp, timeout);
  518. cmsysProcess_Execute(cp);
  519. // Initialize tick's
  520. std::string::size_type tick = 0;
  521. const std::string::size_type tick_len = 1024;
  522. char* data;
  523. int length;
  524. cmCTestLog(m_CTest, HANDLER_OUTPUT,
  525. " Each symbol represents " << tick_len << " bytes of output." << std::endl
  526. << " '!' represents an error and '*' a warning." << std::endl
  527. << " " << std::flush);
  528. // Initialize building structures
  529. m_BuildProcessingQueue.clear();
  530. m_OutputLineCounter = 0;
  531. m_ErrorsAndWarnings.clear();
  532. m_TotalErrors = 0;
  533. m_TotalWarnings = 0;
  534. m_BuildOutputLogSize = 0;
  535. m_LastTickChar = '.';
  536. m_WarningQuotaReached = false;
  537. m_ErrorQuotaReached = false;
  538. // For every chunk of data
  539. int res;
  540. while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
  541. {
  542. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  543. // for Visual Studio output
  544. for(int cc =0; cc < length; ++cc)
  545. {
  546. if(data[cc] == 0)
  547. {
  548. data[cc] = '\n';
  549. }
  550. }
  551. // Process the chunk of data
  552. if ( res == cmsysProcess_Pipe_STDERR )
  553. {
  554. this->ProcessBuffer(data, length, tick, tick_len, ofs, &m_BuildProcessingErrorQueue);
  555. }
  556. else
  557. {
  558. this->ProcessBuffer(data, length, tick, tick_len, ofs, &m_BuildProcessingQueue);
  559. }
  560. }
  561. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &m_BuildProcessingQueue);
  562. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &m_BuildProcessingErrorQueue);
  563. cmCTestLog(m_CTest, OUTPUT, " Size of output: "
  564. << int(m_BuildOutputLogSize / 1024.0) << "K" << std::endl);
  565. // Properly handle output of the build command
  566. cmsysProcess_WaitForExit(cp, 0);
  567. int result = cmsysProcess_GetState(cp);
  568. if(result == cmsysProcess_State_Exited)
  569. {
  570. *retVal = cmsysProcess_GetExitValue(cp);
  571. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Command exited with the value: " << *retVal << std::endl);
  572. }
  573. else if(result == cmsysProcess_State_Exception)
  574. {
  575. *retVal = cmsysProcess_GetExitException(cp);
  576. cmCTestLog(m_CTest, WARNING, "There was an exception: " << *retVal << std::endl);
  577. }
  578. else if(result == cmsysProcess_State_Expired)
  579. {
  580. cmCTestLog(m_CTest, WARNING, "There was a timeout" << std::endl);
  581. }
  582. else if(result == cmsysProcess_State_Error)
  583. {
  584. // If there was an error running command, report that on the dashboard.
  585. cmCTestBuildErrorWarning errorwarning;
  586. errorwarning.m_LogLine = 1;
  587. errorwarning.m_Text = "*** ERROR executing: ";
  588. errorwarning.m_Text += cmsysProcess_GetErrorString(cp);
  589. errorwarning.m_PreContext = "";
  590. errorwarning.m_PostContext = "";
  591. errorwarning.m_Error = true;
  592. m_ErrorsAndWarnings.push_back(errorwarning);
  593. m_TotalErrors ++;
  594. cmCTestLog(m_CTest, ERROR_MESSAGE, "There was an error: " << cmsysProcess_GetErrorString(cp) << std::endl);
  595. }
  596. cmsysProcess_Delete(cp);
  597. return result;
  598. }
  599. //######################################################################
  600. //######################################################################
  601. //######################################################################
  602. //######################################################################
  603. //----------------------------------------------------------------------
  604. void cmCTestBuildHandler::ProcessBuffer(const char* data, int length, size_t& tick, size_t tick_len,
  605. std::ofstream& ofs, t_BuildProcessingQueueType* queue)
  606. {
  607. #undef cerr
  608. const std::string::size_type tick_line_len = 50;
  609. const char* ptr;
  610. for ( ptr = data; ptr < data+length; ptr ++ )
  611. {
  612. queue->push_back(*ptr);
  613. }
  614. m_BuildOutputLogSize += length;
  615. // until there are any lines left in the buffer
  616. while ( 1 )
  617. {
  618. // Find the end of line
  619. t_BuildProcessingQueueType::iterator it;
  620. for ( it = queue->begin();
  621. it != queue->end();
  622. ++ it )
  623. {
  624. if ( *it == '\n' )
  625. {
  626. break;
  627. }
  628. }
  629. // Once certain number of errors or warnings reached, ignore future errors or warnings.
  630. if ( m_TotalWarnings >= m_MaxWarnings )
  631. {
  632. m_WarningQuotaReached = true;
  633. }
  634. if ( m_TotalErrors >= m_MaxErrors )
  635. {
  636. m_ErrorQuotaReached = true;
  637. }
  638. // If the end of line was found
  639. if ( it != queue->end() )
  640. {
  641. // Create a contiguous array for the line
  642. m_CurrentProcessingLine.clear();
  643. t_BuildProcessingQueueType::iterator cit;
  644. for ( cit = queue->begin(); cit != it; ++cit )
  645. {
  646. m_CurrentProcessingLine.push_back(*cit);
  647. }
  648. m_CurrentProcessingLine.push_back(0);
  649. const char* line = &*m_CurrentProcessingLine.begin();
  650. // Process the line
  651. int lineType = this->ProcessSingleLine(line);
  652. // Erase the line from the queue
  653. queue->erase(queue->begin(), it+1);
  654. // Depending on the line type, produce error or warning, or nothing
  655. cmCTestBuildErrorWarning errorwarning;
  656. bool found = false;
  657. switch ( lineType )
  658. {
  659. case b_WARNING_LINE:
  660. m_LastTickChar = '*';
  661. errorwarning.m_Error = false;
  662. found = true;
  663. m_TotalWarnings ++;
  664. break;
  665. case b_ERROR_LINE:
  666. m_LastTickChar = '!';
  667. errorwarning.m_Error = true;
  668. found = true;
  669. m_TotalErrors ++;
  670. break;
  671. }
  672. if ( found )
  673. {
  674. // This is an error or warning, so generate report
  675. errorwarning.m_LogLine = static_cast<int>(m_OutputLineCounter+1);
  676. errorwarning.m_Text = line;
  677. errorwarning.m_PreContext = "";
  678. errorwarning.m_PostContext = "";
  679. // Copy pre-context to report
  680. std::deque<cmStdString>::iterator pcit;
  681. for ( pcit = m_PreContext.begin(); pcit != m_PreContext.end(); ++pcit )
  682. {
  683. errorwarning.m_PreContext += *pcit + "\n";
  684. }
  685. m_PreContext.clear();
  686. // Store report
  687. m_ErrorsAndWarnings.push_back(errorwarning);
  688. m_LastErrorOrWarning = m_ErrorsAndWarnings.end()-1;
  689. m_PostContextCount = 0;
  690. }
  691. else
  692. {
  693. // This is not an error or warning.
  694. // So, figure out if this is a post-context line
  695. if ( m_LastErrorOrWarning != m_ErrorsAndWarnings.end() && m_PostContextCount < m_MaxPostContext )
  696. {
  697. m_PostContextCount ++;
  698. m_LastErrorOrWarning->m_PostContext += line;
  699. if ( m_PostContextCount < m_MaxPostContext )
  700. {
  701. m_LastErrorOrWarning->m_PostContext += "\n";
  702. }
  703. }
  704. else
  705. {
  706. // Otherwise store pre-context for the next error
  707. m_PreContext.push_back(line);
  708. if ( m_PreContext.size() > m_MaxPreContext )
  709. {
  710. m_PreContext.erase(m_PreContext.begin(), m_PreContext.end()-m_MaxPreContext);
  711. }
  712. }
  713. }
  714. m_OutputLineCounter ++;
  715. }
  716. else
  717. {
  718. break;
  719. }
  720. }
  721. // Now that the buffer is processed, display missing ticks
  722. int tickDisplayed = false;
  723. while ( m_BuildOutputLogSize > (tick * tick_len) )
  724. {
  725. tick ++;
  726. cmCTestLog(m_CTest, HANDLER_OUTPUT, m_LastTickChar);
  727. tickDisplayed = true;
  728. if ( tick % tick_line_len == 0 && tick > 0 )
  729. {
  730. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Size: "
  731. << int((m_BuildOutputLogSize / 1024.0) + 1) << "K" << std::endl
  732. << " ");
  733. }
  734. }
  735. if ( tickDisplayed )
  736. {
  737. m_LastTickChar = '.';
  738. }
  739. // And if this is verbose output, display the content of the chunk
  740. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  741. // Always store the chunk to the file
  742. ofs << cmCTestLogWrite(data, length);
  743. }
  744. //----------------------------------------------------------------------
  745. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  746. {
  747. cmCTestLog(m_CTest, DEBUG, "Line: [" << data << "]" << std::endl);
  748. std::vector<cmsys::RegularExpression>::iterator it;
  749. int warningLine = 0;
  750. int errorLine = 0;
  751. // Check for regular expressions
  752. if ( !m_ErrorQuotaReached )
  753. {
  754. // Errors
  755. for ( it = m_ErrorMatchRegex.begin(); it != m_ErrorMatchRegex.end(); ++ it )
  756. {
  757. if ( it->find(data) )
  758. {
  759. errorLine = 1;
  760. cmCTestLog(m_CTest, DEBUG, " Error Line: " << data << std::endl);
  761. break;
  762. }
  763. }
  764. // Error exceptions
  765. for ( it = m_ErrorExceptionRegex.begin(); it != m_ErrorExceptionRegex.end(); ++ it )
  766. {
  767. if ( it->find(data) )
  768. {
  769. errorLine = 0;
  770. cmCTestLog(m_CTest, DEBUG, " Not an error Line: " << data << std::endl);
  771. break;
  772. }
  773. }
  774. }
  775. if ( !m_WarningQuotaReached )
  776. {
  777. // Warnings
  778. for ( it = m_WarningMatchRegex.begin(); it != m_WarningMatchRegex.end(); ++ it )
  779. {
  780. if ( it->find(data) )
  781. {
  782. warningLine = 1;
  783. cmCTestLog(m_CTest, DEBUG, " Warning Line: " << data << std::endl);
  784. break;
  785. }
  786. }
  787. // Warning exceptions
  788. for ( it = m_WarningExceptionRegex.begin(); it != m_WarningExceptionRegex.end(); ++ it )
  789. {
  790. if ( it->find(data) )
  791. {
  792. warningLine = 0;
  793. cmCTestLog(m_CTest, DEBUG, " Not a warning Line: " << data << std::endl);
  794. break;
  795. }
  796. }
  797. }
  798. if ( errorLine )
  799. {
  800. return b_ERROR_LINE;
  801. }
  802. if ( warningLine )
  803. {
  804. return b_WARNING_LINE;
  805. }
  806. return b_REGULAR_LINE;
  807. }