cmCTestBuildHandler.cxx 41 KB

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