1
0

cmCTestBuildHandler.cxx 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestBuildHandler.h"
  11. #include "cmCTest.h"
  12. #include "cmake.h"
  13. #include "cmMakefile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmXMLSafe.h"
  18. #include "cmFileTimeComparison.h"
  19. //#include <cmsys/RegularExpression.hxx>
  20. #include <cmsys/Process.h>
  21. #include <cmsys/Directory.hxx>
  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. #if defined(__BORLANDC__)
  31. # pragma warn -8060 /* possibly incorrect assignment */
  32. #endif
  33. static const char* cmCTestErrorMatches[] = {
  34. "^[Bb]us [Ee]rror",
  35. "^[Ss]egmentation [Vv]iolation",
  36. "^[Ss]egmentation [Ff]ault",
  37. ":.*[Pp]ermission [Dd]enied",
  38. "([^ :]+):([0-9]+): ([^ \\t])",
  39. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  40. "^Error ([0-9]+):",
  41. "^Fatal",
  42. "^Error: ",
  43. "^Error ",
  44. "[0-9] ERROR: ",
  45. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  46. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  47. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  48. "^ild:([ \\t])*\\(undefined symbol\\)",
  49. "([^ :]+) : (error|fatal error|catastrophic error)",
  50. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  51. "([^:]+)\\(([^\\)]+)\\) ?: (error|fatal error|catastrophic error)",
  52. "^fatal error C[0-9]+:",
  53. ": syntax error ",
  54. "^collect2: ld returned 1 exit status",
  55. "ld terminated with signal",
  56. "Unsatisfied symbol",
  57. "^Unresolved:",
  58. "Undefined symbol",
  59. "^Undefined[ \\t]+first referenced",
  60. "^CMake Error.*:",
  61. ":[ \\t]cannot find",
  62. ":[ \\t]can't find",
  63. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  64. ": \\*\\*\\* No targets specified and no makefile found",
  65. ": Invalid loader fixup for symbol",
  66. ": Invalid fixups exist",
  67. ": Can't find library for",
  68. ": internal link edit command failed",
  69. ": Unrecognized option \\`.*\\'",
  70. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
  71. "ld: 0706-006 Cannot find or open library file: -l ",
  72. "ild: \\(argument error\\) can't find library argument ::",
  73. "^could not be found and will not be loaded.",
  74. "s:616 string too big",
  75. "make: Fatal error: ",
  76. "ld: 0711-993 Error occurred while writing to the output file:",
  77. "ld: fatal: ",
  78. "final link failed:",
  79. "make: \\*\\*\\*.*Error",
  80. "make\\[.*\\]: \\*\\*\\*.*Error",
  81. "\\*\\*\\* Error code",
  82. "nternal error:",
  83. "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
  84. ": No such file or directory",
  85. ": Invalid argument",
  86. "^The project cannot be built\\.",
  87. "^\\[ERROR\\]",
  88. "^Command .* failed with exit code",
  89. 0
  90. };
  91. static const char* cmCTestErrorExceptions[] = {
  92. "instantiated from ",
  93. "candidates are:",
  94. ": warning",
  95. ": \\(Warning\\)",
  96. ": note",
  97. "makefile:",
  98. "Makefile:",
  99. ":[ \\t]+Where:",
  100. "([^ :]+):([0-9]+): Warning",
  101. "------ Build started: .* ------",
  102. 0
  103. };
  104. static const char* cmCTestWarningMatches[] = {
  105. "([^ :]+):([0-9]+): warning:",
  106. "([^ :]+):([0-9]+): note:",
  107. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  108. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  109. "([^:]+): warning ([0-9]+):",
  110. "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
  111. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  112. "^(Warning|Warnung) ([0-9]+):",
  113. "^(Warning|Warnung)[ :]",
  114. "WARNING: ",
  115. "([^ :]+) : warning",
  116. "([^:]+): warning",
  117. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([WI]\\)",
  118. "^cxx: Warning:",
  119. ".*file: .* has no symbols",
  120. "([^ :]+):([0-9]+): (Warning|Warnung)",
  121. "\\([0-9]*\\): remark #[0-9]*",
  122. "\".*\", line [0-9]+: remark\\([0-9]*\\):",
  123. "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
  124. "^CMake Warning.*:",
  125. "^\\[WARNING\\]",
  126. 0
  127. };
  128. static const char* cmCTestWarningExceptions[] = {
  129. "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  130. "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  131. "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  132. "WARNING 84 :",
  133. "WARNING 47 :",
  134. "makefile:",
  135. "Makefile:",
  136. "warning: Clock skew detected. Your build may be incomplete.",
  137. "/usr/openwin/include/GL/[^:]+:",
  138. "bind_at_load",
  139. "XrmQGetResource",
  140. "IceFlush",
  141. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  142. "ld32: WARNING 85: definition of dataKey in",
  143. "cc: warning 422: Unknown option \"\\+b",
  144. "_with_warning_C",
  145. 0
  146. };
  147. struct cmCTestBuildCompileErrorWarningRex
  148. {
  149. const char* RegularExpressionString;
  150. int FileIndex;
  151. int LineIndex;
  152. };
  153. static cmCTestBuildCompileErrorWarningRex
  154. cmCTestWarningErrorFileLine[] = {
  155. { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
  156. { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
  157. { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  158. { "^[0-9]+>([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  159. { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  160. { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
  161. { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
  162. { 0, 0, 0 }
  163. };
  164. //----------------------------------------------------------------------
  165. cmCTestBuildHandler::cmCTestBuildHandler()
  166. {
  167. this->MaxPreContext = 10;
  168. this->MaxPostContext = 10;
  169. this->MaxErrors = 50;
  170. this->MaxWarnings = 50;
  171. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  172. this->UseCTestLaunch = false;
  173. }
  174. //----------------------------------------------------------------------
  175. void cmCTestBuildHandler::Initialize()
  176. {
  177. this->Superclass::Initialize();
  178. this->StartBuild = "";
  179. this->EndBuild = "";
  180. this->CustomErrorMatches.clear();
  181. this->CustomErrorExceptions.clear();
  182. this->CustomWarningMatches.clear();
  183. this->CustomWarningExceptions.clear();
  184. this->ReallyCustomWarningMatches.clear();
  185. this->ReallyCustomWarningExceptions.clear();
  186. this->ErrorWarningFileLineRegex.clear();
  187. this->ErrorMatchRegex.clear();
  188. this->ErrorExceptionRegex.clear();
  189. this->WarningMatchRegex.clear();
  190. this->WarningExceptionRegex.clear();
  191. this->BuildProcessingQueue.clear();
  192. this->BuildProcessingErrorQueue.clear();
  193. this->BuildOutputLogSize = 0;
  194. this->CurrentProcessingLine.clear();
  195. this->SimplifySourceDir = "";
  196. this->SimplifyBuildDir = "";
  197. this->OutputLineCounter = 0;
  198. this->ErrorsAndWarnings.clear();
  199. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  200. this->PostContextCount = 0;
  201. this->MaxPreContext = 10;
  202. this->MaxPostContext = 10;
  203. this->PreContext.clear();
  204. this->TotalErrors = 0;
  205. this->TotalWarnings = 0;
  206. this->LastTickChar = 0;
  207. this->ErrorQuotaReached = false;
  208. this->WarningQuotaReached = false;
  209. this->MaxErrors = 50;
  210. this->MaxWarnings = 50;
  211. this->UseCTestLaunch = false;
  212. }
  213. //----------------------------------------------------------------------
  214. void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)
  215. {
  216. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
  217. this->CustomErrorMatches);
  218. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
  219. this->CustomErrorExceptions);
  220. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
  221. this->CustomWarningMatches);
  222. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
  223. this->CustomWarningExceptions);
  224. this->CTest->PopulateCustomInteger(mf,
  225. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
  226. this->MaxErrors);
  227. this->CTest->PopulateCustomInteger(mf,
  228. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
  229. this->MaxWarnings);
  230. int n = -1;
  231. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_PRE_CONTEXT", n);
  232. if (n != -1)
  233. {
  234. this->MaxPreContext = static_cast<size_t>(n);
  235. }
  236. n = -1;
  237. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_POST_CONTEXT", n);
  238. if (n != -1)
  239. {
  240. this->MaxPostContext = static_cast<size_t>(n);
  241. }
  242. // Record the user-specified custom warning rules.
  243. if(const char* customWarningMatchers =
  244. mf->GetDefinition("CTEST_CUSTOM_WARNING_MATCH"))
  245. {
  246. cmSystemTools::ExpandListArgument(customWarningMatchers,
  247. this->ReallyCustomWarningMatches);
  248. }
  249. if(const char* customWarningExceptions =
  250. mf->GetDefinition("CTEST_CUSTOM_WARNING_EXCEPTION"))
  251. {
  252. cmSystemTools::ExpandListArgument(customWarningExceptions,
  253. this->ReallyCustomWarningExceptions);
  254. }
  255. }
  256. //----------------------------------------------------------------------
  257. std::string cmCTestBuildHandler::GetMakeCommand()
  258. {
  259. std::string makeCommand
  260. = this->CTest->GetCTestConfiguration("MakeCommand");
  261. cmCTestLog(this->CTest,
  262. HANDLER_VERBOSE_OUTPUT, "MakeCommand:" << makeCommand <<
  263. "\n");
  264. std::string configType = this->CTest->GetConfigType();
  265. if (configType == "")
  266. {
  267. configType
  268. = this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
  269. }
  270. if (configType == "")
  271. {
  272. configType = "Release";
  273. }
  274. cmSystemTools::ReplaceString(makeCommand,
  275. "${CTEST_CONFIGURATION_TYPE}", configType.c_str());
  276. return makeCommand;
  277. }
  278. //----------------------------------------------------------------------
  279. //clearly it would be nice if this were broken up into a few smaller
  280. //functions and commented...
  281. int cmCTestBuildHandler::ProcessHandler()
  282. {
  283. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl);
  284. // do we have time for this
  285. if (this->CTest->GetRemainingTimeAllowed() < 120)
  286. {
  287. return 0;
  288. }
  289. int entry;
  290. for ( entry = 0;
  291. cmCTestWarningErrorFileLine[entry].RegularExpressionString;
  292. ++ entry )
  293. {
  294. cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
  295. if ( r.RegularExpression.compile(
  296. cmCTestWarningErrorFileLine[entry].RegularExpressionString) )
  297. {
  298. r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
  299. r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
  300. this->ErrorWarningFileLineRegex.push_back(r);
  301. }
  302. else
  303. {
  304. cmCTestLog(this->CTest, ERROR_MESSAGE,
  305. "Problem Compiling regular expression: "
  306. << cmCTestWarningErrorFileLine[entry].RegularExpressionString
  307. << std::endl);
  308. }
  309. }
  310. // Determine build command and build directory
  311. std::string makeCommand = this->GetMakeCommand();
  312. if ( makeCommand.size() == 0 )
  313. {
  314. cmCTestLog(this->CTest, ERROR_MESSAGE,
  315. "Cannot find MakeCommand key in the DartConfiguration.tcl"
  316. << std::endl);
  317. return -1;
  318. }
  319. const std::string &buildDirectory
  320. = this->CTest->GetCTestConfiguration("BuildDirectory");
  321. if ( buildDirectory.size() == 0 )
  322. {
  323. cmCTestLog(this->CTest, ERROR_MESSAGE,
  324. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  325. << std::endl);
  326. return -1;
  327. }
  328. std::string const& useLaunchers =
  329. this->CTest->GetCTestConfiguration("UseLaunchers");
  330. this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers.c_str());
  331. // Create a last build log
  332. cmGeneratedFileStream ofs;
  333. double elapsed_time_start = cmSystemTools::GetTime();
  334. if ( !this->StartLogFile("Build", ofs) )
  335. {
  336. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file"
  337. << std::endl);
  338. }
  339. // Create lists of regular expression strings for errors, error exceptions,
  340. // warnings and warning exceptions.
  341. std::vector<cmStdString>::size_type cc;
  342. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  343. {
  344. this->CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  345. }
  346. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  347. {
  348. this->CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  349. }
  350. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  351. {
  352. this->CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  353. }
  354. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  355. {
  356. this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  357. }
  358. // Pre-compile regular expressions objects for all regular expressions
  359. std::vector<cmStdString>::iterator it;
  360. #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
  361. regexes.clear(); \
  362. cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
  363. << std::endl); \
  364. for ( it = strings.begin(); it != strings.end(); ++it ) \
  365. { \
  366. cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
  367. << it->c_str() << std::endl); \
  368. regexes.push_back(it->c_str()); \
  369. }
  370. cmCTestBuildHandlerPopulateRegexVector(
  371. this->CustomErrorMatches, this->ErrorMatchRegex);
  372. cmCTestBuildHandlerPopulateRegexVector(
  373. this->CustomErrorExceptions, this->ErrorExceptionRegex);
  374. cmCTestBuildHandlerPopulateRegexVector(
  375. this->CustomWarningMatches, this->WarningMatchRegex);
  376. cmCTestBuildHandlerPopulateRegexVector(
  377. this->CustomWarningExceptions, this->WarningExceptionRegex);
  378. // Determine source and binary tree substitutions to simplify the output.
  379. this->SimplifySourceDir = "";
  380. this->SimplifyBuildDir = "";
  381. if ( this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20 )
  382. {
  383. std::string srcdir
  384. = this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
  385. std::string srcdirrep;
  386. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  387. {
  388. if ( srcdir[cc] == '/' )
  389. {
  390. srcdirrep = srcdir.c_str() + cc;
  391. srcdirrep = "/..." + srcdirrep;
  392. srcdir = srcdir.substr(0, cc+1);
  393. break;
  394. }
  395. }
  396. this->SimplifySourceDir = srcdir;
  397. }
  398. if ( this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20 )
  399. {
  400. std::string bindir
  401. = this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
  402. std::string bindirrep;
  403. for ( cc = bindir.size()-2; cc > 0; cc -- )
  404. {
  405. if ( bindir[cc] == '/' )
  406. {
  407. bindirrep = bindir.c_str() + cc;
  408. bindirrep = "/..." + bindirrep;
  409. bindir = bindir.substr(0, cc+1);
  410. break;
  411. }
  412. }
  413. this->SimplifyBuildDir = bindir;
  414. }
  415. // Ok, let's do the build
  416. // Remember start build time
  417. this->StartBuild = this->CTest->CurrentTime();
  418. this->StartBuildTime = cmSystemTools::GetTime();
  419. int retVal = 0;
  420. int res = cmsysProcess_State_Exited;
  421. if ( !this->CTest->GetShowOnly() )
  422. {
  423. res = this->RunMakeCommand(makeCommand.c_str(), &retVal,
  424. buildDirectory.c_str(), 0, ofs);
  425. }
  426. else
  427. {
  428. cmCTestLog(this->CTest, DEBUG, "Build with command: " << makeCommand
  429. << std::endl);
  430. }
  431. // Remember end build time and calculate elapsed time
  432. this->EndBuild = this->CTest->CurrentTime();
  433. this->EndBuildTime = cmSystemTools::GetTime();
  434. double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
  435. // Cleanups strings in the errors and warnings list.
  436. t_ErrorsAndWarningsVector::iterator evit;
  437. if ( !this->SimplifySourceDir.empty() )
  438. {
  439. for ( evit = this->ErrorsAndWarnings.begin();
  440. evit != this->ErrorsAndWarnings.end();
  441. ++ evit )
  442. {
  443. cmSystemTools::ReplaceString(
  444. evit->Text, this->SimplifySourceDir.c_str(), "/.../");
  445. cmSystemTools::ReplaceString(
  446. evit->PreContext, this->SimplifySourceDir.c_str(), "/.../");
  447. cmSystemTools::ReplaceString(
  448. evit->PostContext, this->SimplifySourceDir.c_str(), "/.../");
  449. }
  450. }
  451. if ( !this->SimplifyBuildDir.empty() )
  452. {
  453. for ( evit = this->ErrorsAndWarnings.begin();
  454. evit != this->ErrorsAndWarnings.end();
  455. ++ evit )
  456. {
  457. cmSystemTools::ReplaceString(
  458. evit->Text, this->SimplifyBuildDir.c_str(), "/.../");
  459. cmSystemTools::ReplaceString(
  460. evit->PreContext, this->SimplifyBuildDir.c_str(), "/.../");
  461. cmSystemTools::ReplaceString(
  462. evit->PostContext, this->SimplifyBuildDir.c_str(), "/.../");
  463. }
  464. }
  465. // Generate XML output
  466. cmGeneratedFileStream xofs;
  467. if(!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs))
  468. {
  469. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
  470. << std::endl);
  471. return -1;
  472. }
  473. this->GenerateXMLHeader(xofs);
  474. if(this->UseCTestLaunch)
  475. {
  476. this->GenerateXMLLaunched(xofs);
  477. }
  478. else
  479. {
  480. this->GenerateXMLLogScraped(xofs);
  481. }
  482. this->GenerateXMLFooter(xofs, elapsed_build_time);
  483. if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0)
  484. {
  485. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
  486. << std::endl);
  487. }
  488. // Display message about number of errors and warnings
  489. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalErrors
  490. << (this->TotalErrors >= this->MaxErrors ? " or more" : "")
  491. << " Compiler errors" << std::endl);
  492. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalWarnings
  493. << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
  494. << " Compiler warnings" << std::endl);
  495. return retVal;
  496. }
  497. //----------------------------------------------------------------------------
  498. void cmCTestBuildHandler::GenerateXMLHeader(std::ostream& os)
  499. {
  500. this->CTest->StartXML(os, this->AppendXML);
  501. os << "<Build>\n"
  502. << "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n"
  503. << "\t<StartBuildTime>" <<
  504. static_cast<unsigned int>(this->StartBuildTime)
  505. << "</StartBuildTime>\n"
  506. << "<BuildCommand>"
  507. << cmXMLSafe(this->GetMakeCommand())
  508. << "</BuildCommand>" << std::endl;
  509. }
  510. //----------------------------------------------------------------------------
  511. class cmCTestBuildHandler::FragmentCompare
  512. {
  513. public:
  514. FragmentCompare(cmFileTimeComparison* ftc): FTC(ftc) {}
  515. FragmentCompare(): FTC(0) {}
  516. bool operator()(std::string const& l, std::string const& r)
  517. {
  518. // Order files by modification time. Use lexicographic order
  519. // among files with the same time.
  520. int result;
  521. if(this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
  522. result != 0)
  523. {
  524. return result < 0;
  525. }
  526. else
  527. {
  528. return l < r;
  529. }
  530. }
  531. private:
  532. cmFileTimeComparison* FTC;
  533. };
  534. //----------------------------------------------------------------------------
  535. void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os)
  536. {
  537. if(this->CTestLaunchDir.empty())
  538. {
  539. return;
  540. }
  541. // Sort XML fragments in chronological order.
  542. cmFileTimeComparison ftc;
  543. FragmentCompare fragmentCompare(&ftc);
  544. typedef std::set<cmStdString, FragmentCompare> Fragments;
  545. Fragments fragments(fragmentCompare);
  546. // Identify fragments on disk.
  547. cmsys::Directory launchDir;
  548. launchDir.Load(this->CTestLaunchDir.c_str());
  549. unsigned long n = launchDir.GetNumberOfFiles();
  550. for(unsigned long i=0; i < n; ++i)
  551. {
  552. const char* fname = launchDir.GetFile(i);
  553. if(this->IsLaunchedErrorFile(fname))
  554. {
  555. fragments.insert(this->CTestLaunchDir + "/" + fname);
  556. ++this->TotalErrors;
  557. }
  558. else if(this->IsLaunchedWarningFile(fname))
  559. {
  560. fragments.insert(this->CTestLaunchDir + "/" + fname);
  561. ++this->TotalWarnings;
  562. }
  563. }
  564. // Copy the fragments into the final XML file.
  565. for(Fragments::const_iterator fi = fragments.begin();
  566. fi != fragments.end(); ++fi)
  567. {
  568. this->GenerateXMLLaunchedFragment(os, fi->c_str());
  569. }
  570. }
  571. //----------------------------------------------------------------------------
  572. void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
  573. {
  574. std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
  575. std::vector<cmCTestBuildErrorWarning>::iterator it;
  576. // only report the first 50 warnings and first 50 errors
  577. int numErrorsAllowed = this->MaxErrors;
  578. int numWarningsAllowed = this->MaxWarnings;
  579. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  580. // make sure the source dir is in the correct case on windows
  581. // via a call to collapse full path.
  582. srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str());
  583. srcdir += "/";
  584. for ( it = ew.begin();
  585. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
  586. {
  587. cmCTestBuildErrorWarning *cm = &(*it);
  588. if ((cm->Error && numErrorsAllowed) ||
  589. (!cm->Error && numWarningsAllowed))
  590. {
  591. if (cm->Error)
  592. {
  593. numErrorsAllowed--;
  594. }
  595. else
  596. {
  597. numWarningsAllowed--;
  598. }
  599. os << "\t<" << (cm->Error ? "Error" : "Warning") << ">\n"
  600. << "\t\t<BuildLogLine>" << cm->LogLine << "</BuildLogLine>\n"
  601. << "\t\t<Text>" << cmXMLSafe(cm->Text).Quotes(false)
  602. << "\n</Text>" << std::endl;
  603. std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
  604. for ( rit = this->ErrorWarningFileLineRegex.begin();
  605. rit != this->ErrorWarningFileLineRegex.end(); ++ rit )
  606. {
  607. cmsys::RegularExpression* re = &rit->RegularExpression;
  608. if ( re->find(cm->Text.c_str() ) )
  609. {
  610. cm->SourceFile = re->match(rit->FileIndex);
  611. // At this point we need to make this->SourceFile relative to
  612. // the source root of the project, so cvs links will work
  613. cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
  614. if(cm->SourceFile.find("/.../") != cm->SourceFile.npos)
  615. {
  616. cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
  617. std::string::size_type p = cm->SourceFile.find("/");
  618. if(p != cm->SourceFile.npos)
  619. {
  620. cm->SourceFile = cm->SourceFile.substr(
  621. p+1, cm->SourceFile.size()-p);
  622. }
  623. }
  624. else
  625. {
  626. // make sure it is a full path with the correct case
  627. cm->SourceFile = cmSystemTools::CollapseFullPath(
  628. cm->SourceFile.c_str());
  629. cmSystemTools::ReplaceString(
  630. cm->SourceFile, srcdir.c_str(), "");
  631. }
  632. cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
  633. break;
  634. }
  635. }
  636. if ( !cm->SourceFile.empty() && cm->LineNumber >= 0 )
  637. {
  638. if ( cm->SourceFile.size() > 0 )
  639. {
  640. os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>"
  641. << std::endl;
  642. }
  643. if ( cm->SourceFileTail.size() > 0 )
  644. {
  645. os << "\t\t<SourceFileTail>" << cm->SourceFileTail
  646. << "</SourceFileTail>" << std::endl;
  647. }
  648. if ( cm->LineNumber >= 0 )
  649. {
  650. os << "\t\t<SourceLineNumber>" << cm->LineNumber
  651. << "</SourceLineNumber>" << std::endl;
  652. }
  653. }
  654. os << "\t\t<PreContext>" << cmXMLSafe(cm->PreContext).Quotes(false)
  655. << "</PreContext>\n"
  656. << "\t\t<PostContext>" << cmXMLSafe(cm->PostContext).Quotes(false);
  657. // is this the last warning or error, if so notify
  658. if ((cm->Error && !numErrorsAllowed) ||
  659. (!cm->Error && !numWarningsAllowed))
  660. {
  661. os << "\nThe maximum number of reported warnings or errors has been "
  662. "reached!!!\n";
  663. }
  664. os << "</PostContext>\n"
  665. << "\t\t<RepeatCount>0</RepeatCount>\n"
  666. << "</" << (cm->Error ? "Error" : "Warning") << ">\n\n"
  667. << std::endl;
  668. }
  669. }
  670. }
  671. //----------------------------------------------------------------------------
  672. void cmCTestBuildHandler::GenerateXMLFooter(std::ostream& os,
  673. double elapsed_build_time)
  674. {
  675. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  676. << "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n"
  677. << "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime)
  678. << "</EndBuildTime>\n"
  679. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  680. << "</ElapsedMinutes>"
  681. << "</Build>" << std::endl;
  682. this->CTest->EndXML(os);
  683. }
  684. //----------------------------------------------------------------------------
  685. void cmCTestBuildHandler::GenerateXMLLaunchedFragment(std::ostream& os,
  686. const char* fname)
  687. {
  688. std::ifstream fin(fname, std::ios::in | std::ios::binary);
  689. std::string line;
  690. while(cmSystemTools::GetLineFromStream(fin, line))
  691. {
  692. os << line << "\n";
  693. }
  694. }
  695. //----------------------------------------------------------------------------
  696. bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
  697. {
  698. // error-{hash}.xml
  699. return (cmHasLiteralPrefix(fname, "error-") &&
  700. strcmp(fname+strlen(fname)-4, ".xml") == 0);
  701. }
  702. //----------------------------------------------------------------------------
  703. bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
  704. {
  705. // warning-{hash}.xml
  706. return (cmHasLiteralPrefix(fname, "warning-") &&
  707. strcmp(fname+strlen(fname)-4, ".xml") == 0);
  708. }
  709. //######################################################################
  710. //######################################################################
  711. //######################################################################
  712. //######################################################################
  713. //----------------------------------------------------------------------------
  714. class cmCTestBuildHandler::LaunchHelper
  715. {
  716. public:
  717. LaunchHelper(cmCTestBuildHandler* handler);
  718. ~LaunchHelper();
  719. private:
  720. cmCTestBuildHandler* Handler;
  721. cmCTest* CTest;
  722. void WriteLauncherConfig();
  723. void WriteScrapeMatchers(const char* purpose,
  724. std::vector<std::string> const& matchers);
  725. };
  726. //----------------------------------------------------------------------------
  727. cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler):
  728. Handler(handler), CTest(handler->CTest)
  729. {
  730. std::string tag = this->CTest->GetCurrentTag();
  731. if(tag.empty())
  732. {
  733. // This is not for a dashboard submission, so there is no XML.
  734. // Skip enabling the launchers.
  735. this->Handler->UseCTestLaunch = false;
  736. }
  737. else
  738. {
  739. // Compute a directory in which to store launcher fragments.
  740. std::string& launchDir = this->Handler->CTestLaunchDir;
  741. launchDir = this->CTest->GetBinaryDir();
  742. launchDir += "/Testing/";
  743. launchDir += tag;
  744. launchDir += "/Build";
  745. // Clean out any existing launcher fragments.
  746. cmSystemTools::RemoveADirectory(launchDir.c_str());
  747. if(this->Handler->UseCTestLaunch)
  748. {
  749. // Enable launcher fragments.
  750. cmSystemTools::MakeDirectory(launchDir.c_str());
  751. this->WriteLauncherConfig();
  752. std::string launchEnv = "CTEST_LAUNCH_LOGS=";
  753. launchEnv += launchDir;
  754. cmSystemTools::PutEnv(launchEnv.c_str());
  755. }
  756. }
  757. // If not using launchers, make sure they passthru.
  758. if(!this->Handler->UseCTestLaunch)
  759. {
  760. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  761. }
  762. }
  763. //----------------------------------------------------------------------------
  764. cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
  765. {
  766. if(this->Handler->UseCTestLaunch)
  767. {
  768. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  769. }
  770. }
  771. //----------------------------------------------------------------------------
  772. void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
  773. {
  774. this->WriteScrapeMatchers("Warning",
  775. this->Handler->ReallyCustomWarningMatches);
  776. this->WriteScrapeMatchers("WarningSuppress",
  777. this->Handler->ReallyCustomWarningExceptions);
  778. // Give some testing configuration information to the launcher.
  779. std::string fname = this->Handler->CTestLaunchDir;
  780. fname += "/CTestLaunchConfig.cmake";
  781. cmGeneratedFileStream fout(fname.c_str());
  782. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  783. fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
  784. }
  785. //----------------------------------------------------------------------------
  786. void
  787. cmCTestBuildHandler::LaunchHelper
  788. ::WriteScrapeMatchers(const char* purpose,
  789. std::vector<std::string> const& matchers)
  790. {
  791. if(matchers.empty())
  792. {
  793. return;
  794. }
  795. std::string fname = this->Handler->CTestLaunchDir;
  796. fname += "/Custom";
  797. fname += purpose;
  798. fname += ".txt";
  799. cmGeneratedFileStream fout(fname.c_str());
  800. for(std::vector<std::string>::const_iterator mi = matchers.begin();
  801. mi != matchers.end(); ++mi)
  802. {
  803. fout << *mi << "\n";
  804. }
  805. }
  806. //----------------------------------------------------------------------
  807. int cmCTestBuildHandler::RunMakeCommand(const char* command,
  808. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  809. {
  810. // First generate the command and arguments
  811. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  812. if(args.size() < 1)
  813. {
  814. return false;
  815. }
  816. std::vector<const char*> argv;
  817. for(std::vector<cmStdString>::const_iterator a = args.begin();
  818. a != args.end(); ++a)
  819. {
  820. argv.push_back(a->c_str());
  821. }
  822. argv.push_back(0);
  823. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
  824. std::vector<const char*>::iterator ait;
  825. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  826. {
  827. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  828. }
  829. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  830. // Optionally use make rule launchers to record errors and warnings.
  831. LaunchHelper launchHelper(this);
  832. static_cast<void>(launchHelper);
  833. // Now create process object
  834. cmsysProcess* cp = cmsysProcess_New();
  835. cmsysProcess_SetCommand(cp, &*argv.begin());
  836. cmsysProcess_SetWorkingDirectory(cp, dir);
  837. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  838. cmsysProcess_SetTimeout(cp, timeout);
  839. cmsysProcess_Execute(cp);
  840. // Initialize tick's
  841. std::string::size_type tick = 0;
  842. const std::string::size_type tick_len = 1024;
  843. char* data;
  844. int length;
  845. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  846. " Each symbol represents " << tick_len << " bytes of output."
  847. << std::endl
  848. << (this->UseCTestLaunch? "" :
  849. " '!' represents an error and '*' a warning.\n")
  850. << " " << std::flush);
  851. // Initialize building structures
  852. this->BuildProcessingQueue.clear();
  853. this->OutputLineCounter = 0;
  854. this->ErrorsAndWarnings.clear();
  855. this->TotalErrors = 0;
  856. this->TotalWarnings = 0;
  857. this->BuildOutputLogSize = 0;
  858. this->LastTickChar = '.';
  859. this->WarningQuotaReached = false;
  860. this->ErrorQuotaReached = false;
  861. // For every chunk of data
  862. int res;
  863. while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
  864. {
  865. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  866. // for Visual Studio output
  867. for(int cc =0; cc < length; ++cc)
  868. {
  869. if(data[cc] == 0)
  870. {
  871. data[cc] = '\n';
  872. }
  873. }
  874. // Process the chunk of data
  875. if ( res == cmsysProcess_Pipe_STDERR )
  876. {
  877. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  878. &this->BuildProcessingErrorQueue);
  879. }
  880. else
  881. {
  882. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  883. &this->BuildProcessingQueue);
  884. }
  885. }
  886. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &this->BuildProcessingQueue);
  887. this->ProcessBuffer(0, 0, tick, tick_len, ofs,
  888. &this->BuildProcessingErrorQueue);
  889. cmCTestLog(this->CTest, OUTPUT, " Size of output: "
  890. << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl);
  891. // Properly handle output of the build command
  892. cmsysProcess_WaitForExit(cp, 0);
  893. int result = cmsysProcess_GetState(cp);
  894. if(result == cmsysProcess_State_Exited)
  895. {
  896. if (retVal)
  897. {
  898. *retVal = cmsysProcess_GetExitValue(cp);
  899. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  900. "Command exited with the value: " << *retVal << std::endl);
  901. // if a non zero return value
  902. if (*retVal)
  903. {
  904. // If there was an error running command, report that on the
  905. // dashboard.
  906. cmCTestBuildErrorWarning errorwarning;
  907. errorwarning.LogLine = 1;
  908. errorwarning.Text
  909. = "*** WARNING non-zero return value in ctest from: ";
  910. errorwarning.Text += argv[0];
  911. errorwarning.PreContext = "";
  912. errorwarning.PostContext = "";
  913. errorwarning.Error = false;
  914. this->ErrorsAndWarnings.push_back(errorwarning);
  915. this->TotalWarnings ++;
  916. }
  917. }
  918. }
  919. else if(result == cmsysProcess_State_Exception)
  920. {
  921. if (retVal)
  922. {
  923. *retVal = cmsysProcess_GetExitException(cp);
  924. cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
  925. << std::endl);
  926. }
  927. }
  928. else if(result == cmsysProcess_State_Expired)
  929. {
  930. cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
  931. }
  932. else if(result == cmsysProcess_State_Error)
  933. {
  934. // If there was an error running command, report that on the dashboard.
  935. cmCTestBuildErrorWarning errorwarning;
  936. errorwarning.LogLine = 1;
  937. errorwarning.Text = "*** ERROR executing: ";
  938. errorwarning.Text += cmsysProcess_GetErrorString(cp);
  939. errorwarning.PreContext = "";
  940. errorwarning.PostContext = "";
  941. errorwarning.Error = true;
  942. this->ErrorsAndWarnings.push_back(errorwarning);
  943. this->TotalErrors ++;
  944. cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
  945. << cmsysProcess_GetErrorString(cp) << std::endl);
  946. }
  947. cmsysProcess_Delete(cp);
  948. return result;
  949. }
  950. //######################################################################
  951. //######################################################################
  952. //######################################################################
  953. //######################################################################
  954. //----------------------------------------------------------------------
  955. void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
  956. size_t& tick, size_t tick_len, std::ofstream& ofs,
  957. t_BuildProcessingQueueType* queue)
  958. {
  959. const std::string::size_type tick_line_len = 50;
  960. const char* ptr;
  961. for ( ptr = data; ptr < data+length; ptr ++ )
  962. {
  963. queue->push_back(*ptr);
  964. }
  965. this->BuildOutputLogSize += length;
  966. // until there are any lines left in the buffer
  967. while ( 1 )
  968. {
  969. // Find the end of line
  970. t_BuildProcessingQueueType::iterator it;
  971. for ( it = queue->begin();
  972. it != queue->end();
  973. ++ it )
  974. {
  975. if ( *it == '\n' )
  976. {
  977. break;
  978. }
  979. }
  980. // Once certain number of errors or warnings reached, ignore future errors
  981. // or warnings.
  982. if ( this->TotalWarnings >= this->MaxWarnings )
  983. {
  984. this->WarningQuotaReached = true;
  985. }
  986. if ( this->TotalErrors >= this->MaxErrors )
  987. {
  988. this->ErrorQuotaReached = true;
  989. }
  990. // If the end of line was found
  991. if ( it != queue->end() )
  992. {
  993. // Create a contiguous array for the line
  994. this->CurrentProcessingLine.clear();
  995. t_BuildProcessingQueueType::iterator cit;
  996. for ( cit = queue->begin(); cit != it; ++cit )
  997. {
  998. this->CurrentProcessingLine.push_back(*cit);
  999. }
  1000. this->CurrentProcessingLine.push_back(0);
  1001. const char* line = &*this->CurrentProcessingLine.begin();
  1002. // Process the line
  1003. int lineType = this->ProcessSingleLine(line);
  1004. // Erase the line from the queue
  1005. queue->erase(queue->begin(), it+1);
  1006. // Depending on the line type, produce error or warning, or nothing
  1007. cmCTestBuildErrorWarning errorwarning;
  1008. bool found = false;
  1009. switch ( lineType )
  1010. {
  1011. case b_WARNING_LINE:
  1012. this->LastTickChar = '*';
  1013. errorwarning.Error = false;
  1014. found = true;
  1015. this->TotalWarnings ++;
  1016. break;
  1017. case b_ERROR_LINE:
  1018. this->LastTickChar = '!';
  1019. errorwarning.Error = true;
  1020. found = true;
  1021. this->TotalErrors ++;
  1022. break;
  1023. }
  1024. if ( found )
  1025. {
  1026. // This is an error or warning, so generate report
  1027. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter+1);
  1028. errorwarning.Text = line;
  1029. errorwarning.PreContext = "";
  1030. errorwarning.PostContext = "";
  1031. // Copy pre-context to report
  1032. std::deque<cmStdString>::iterator pcit;
  1033. for ( pcit = this->PreContext.begin();
  1034. pcit != this->PreContext.end();
  1035. ++pcit )
  1036. {
  1037. errorwarning.PreContext += *pcit + "\n";
  1038. }
  1039. this->PreContext.clear();
  1040. // Store report
  1041. this->ErrorsAndWarnings.push_back(errorwarning);
  1042. this->LastErrorOrWarning = this->ErrorsAndWarnings.end()-1;
  1043. this->PostContextCount = 0;
  1044. }
  1045. else
  1046. {
  1047. // This is not an error or warning.
  1048. // So, figure out if this is a post-context line
  1049. if ( this->ErrorsAndWarnings.size() &&
  1050. this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  1051. this->PostContextCount < this->MaxPostContext )
  1052. {
  1053. this->PostContextCount ++;
  1054. this->LastErrorOrWarning->PostContext += line;
  1055. if ( this->PostContextCount < this->MaxPostContext )
  1056. {
  1057. this->LastErrorOrWarning->PostContext += "\n";
  1058. }
  1059. }
  1060. else
  1061. {
  1062. // Otherwise store pre-context for the next error
  1063. this->PreContext.push_back(line);
  1064. if ( this->PreContext.size() > this->MaxPreContext )
  1065. {
  1066. this->PreContext.erase(this->PreContext.begin(),
  1067. this->PreContext.end()-this->MaxPreContext);
  1068. }
  1069. }
  1070. }
  1071. this->OutputLineCounter ++;
  1072. }
  1073. else
  1074. {
  1075. break;
  1076. }
  1077. }
  1078. // Now that the buffer is processed, display missing ticks
  1079. int tickDisplayed = false;
  1080. while ( this->BuildOutputLogSize > (tick * tick_len) )
  1081. {
  1082. tick ++;
  1083. cmCTestLog(this->CTest, HANDLER_OUTPUT, this->LastTickChar);
  1084. tickDisplayed = true;
  1085. if ( tick % tick_line_len == 0 && tick > 0 )
  1086. {
  1087. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Size: "
  1088. << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl
  1089. << " ");
  1090. }
  1091. }
  1092. if ( tickDisplayed )
  1093. {
  1094. this->LastTickChar = '.';
  1095. }
  1096. // And if this is verbose output, display the content of the chunk
  1097. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1098. cmCTestLogWrite(data, length));
  1099. // Always store the chunk to the file
  1100. ofs << cmCTestLogWrite(data, length);
  1101. }
  1102. //----------------------------------------------------------------------
  1103. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  1104. {
  1105. if(this->UseCTestLaunch)
  1106. {
  1107. // No log scraping when using launchers.
  1108. return b_REGULAR_LINE;
  1109. }
  1110. cmCTestLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl);
  1111. std::vector<cmsys::RegularExpression>::iterator it;
  1112. int warningLine = 0;
  1113. int errorLine = 0;
  1114. // Check for regular expressions
  1115. if ( !this->ErrorQuotaReached )
  1116. {
  1117. // Errors
  1118. int wrxCnt = 0;
  1119. for ( it = this->ErrorMatchRegex.begin();
  1120. it != this->ErrorMatchRegex.end();
  1121. ++ it )
  1122. {
  1123. if ( it->find(data) )
  1124. {
  1125. errorLine = 1;
  1126. cmCTestLog(this->CTest, DEBUG, " Error Line: " << data
  1127. << " (matches: " << this->CustomErrorMatches[wrxCnt] << ")"
  1128. << std::endl);
  1129. break;
  1130. }
  1131. wrxCnt ++;
  1132. }
  1133. // Error exceptions
  1134. wrxCnt = 0;
  1135. for ( it = this->ErrorExceptionRegex.begin();
  1136. it != this->ErrorExceptionRegex.end();
  1137. ++ it )
  1138. {
  1139. if ( it->find(data) )
  1140. {
  1141. errorLine = 0;
  1142. cmCTestLog(this->CTest, DEBUG, " Not an error Line: " << data
  1143. << " (matches: " << this->CustomErrorExceptions[wrxCnt] << ")"
  1144. << std::endl);
  1145. break;
  1146. }
  1147. wrxCnt ++;
  1148. }
  1149. }
  1150. if ( !this->WarningQuotaReached )
  1151. {
  1152. // Warnings
  1153. int wrxCnt = 0;
  1154. for ( it = this->WarningMatchRegex.begin();
  1155. it != this->WarningMatchRegex.end();
  1156. ++ it )
  1157. {
  1158. if ( it->find(data) )
  1159. {
  1160. warningLine = 1;
  1161. cmCTestLog(this->CTest, DEBUG,
  1162. " Warning Line: " << data
  1163. << " (matches: " << this->CustomWarningMatches[wrxCnt] << ")"
  1164. << std::endl);
  1165. break;
  1166. }
  1167. wrxCnt ++;
  1168. }
  1169. wrxCnt = 0;
  1170. // Warning exceptions
  1171. for ( it = this->WarningExceptionRegex.begin();
  1172. it != this->WarningExceptionRegex.end();
  1173. ++ it )
  1174. {
  1175. if ( it->find(data) )
  1176. {
  1177. warningLine = 0;
  1178. cmCTestLog(this->CTest, DEBUG, " Not a warning Line: " << data
  1179. << " (matches: " << this->CustomWarningExceptions[wrxCnt] << ")"
  1180. << std::endl);
  1181. break;
  1182. }
  1183. wrxCnt ++;
  1184. }
  1185. }
  1186. if ( errorLine )
  1187. {
  1188. return b_ERROR_LINE;
  1189. }
  1190. if ( warningLine )
  1191. {
  1192. return b_WARNING_LINE;
  1193. }
  1194. return b_REGULAR_LINE;
  1195. }