cmCTestBuildHandler.cxx 40 KB

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