cmCTestBuildHandler.cxx 40 KB

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