cmCTestBuildHandler.cxx 40 KB

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