cmCTestBuildHandler.cxx 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestBuildHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmGeneratedFileStream.h"
  20. //#include <cmsys/RegularExpression.hxx>
  21. #include <cmsys/Process.h>
  22. // used for sleep
  23. #ifdef _WIN32
  24. #include "windows.h"
  25. #endif
  26. #include <stdlib.h>
  27. #include <time.h>
  28. #include <math.h>
  29. #include <float.h>
  30. #if defined(__BORLANDC__)
  31. # pragma warn -8060 /* possibly incorrect assignment */
  32. #endif
  33. static const char* cmCTestErrorMatches[] = {
  34. "^[Bb]us [Ee]rror",
  35. "^[Ss]egmentation [Vv]iolation",
  36. "^[Ss]egmentation [Ff]ault",
  37. "([^ :]+):([0-9]+): ([^ \\t])",
  38. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  39. "^Error ([0-9]+):",
  40. "^Fatal",
  41. "^Error: ",
  42. "^Error ",
  43. "[0-9] ERROR: ",
  44. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  45. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  46. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  47. "^ild:([ \\t])*\\(undefined symbol\\)",
  48. "([^ :]+) : (error|fatal error|catastrophic error)",
  49. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  50. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  51. "^fatal error C[0-9]+:",
  52. ": syntax error ",
  53. "^collect2: ld returned 1 exit status",
  54. "ld terminated with signal",
  55. "Unsatisfied symbols:",
  56. "^Unresolved:",
  57. "Undefined symbols:",
  58. "^Undefined[ \\t]+first referenced",
  59. "^CMake Error:",
  60. ":[ \\t]cannot find",
  61. ":[ \\t]can't find",
  62. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  63. ": \\*\\*\\* No targets specified and no makefile found",
  64. ": Invalid loader fixup for symbol",
  65. ": Invalid fixups exist",
  66. ": Can't find library for",
  67. ": internal link edit command failed",
  68. ": Unrecognized option \\`.*\\'",
  69. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^WI]\\)",
  70. "ld: 0706-006 Cannot find or open library file: -l ",
  71. "ild: \\(argument error\\) can't find library argument ::",
  72. "^could not be found and will not be loaded.",
  73. "s:616 string too big",
  74. "make: Fatal error: ",
  75. "ld: 0711-993 Error occurred while writing to the output file:",
  76. "ld: fatal: ",
  77. "final link failed:",
  78. "make: \\*\\*\\*.*Error",
  79. "make\\[.*\\]: \\*\\*\\*.*Error",
  80. "\\*\\*\\* Error code",
  81. "nternal error:",
  82. "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
  83. ": No such file or directory",
  84. ": Invalid argument",
  85. "^The project cannot be built\\.",
  86. 0
  87. };
  88. static const char* cmCTestErrorExceptions[] = {
  89. "instantiated from ",
  90. "candidates are:",
  91. ": warning",
  92. ": \\(Warning\\)",
  93. ": note",
  94. "makefile:",
  95. "Makefile:",
  96. ":[ \\t]+Where:",
  97. "([^ :]+):([0-9]+): Warning",
  98. "------ Build started: .* ------",
  99. 0
  100. };
  101. static const char* cmCTestWarningMatches[] = {
  102. "([^ :]+):([0-9]+): warning:",
  103. "([^ :]+):([0-9]+): note:",
  104. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  105. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  106. "([^:]+): warning ([0-9]+):",
  107. "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
  108. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  109. "^(Warning|Warnung) ([0-9]+):",
  110. "^(Warning|Warnung) ",
  111. "WARNING: ",
  112. "([^ :]+) : warning",
  113. "([^:]+): warning",
  114. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([WI]\\)",
  115. "^cxx: Warning:",
  116. ".*file: .* has no symbols",
  117. "([^ :]+):([0-9]+): (Warning|Warnung)",
  118. "\\([0-9]*\\): remark #[0-9]*",
  119. "\".*\", line [0-9]+: remark\\([0-9]*\\):",
  120. "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
  121. 0
  122. };
  123. static const char* cmCTestWarningExceptions[] = {
  124. "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  125. "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  126. "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  127. "WARNING 84 :",
  128. "WARNING 47 :",
  129. "makefile:",
  130. "Makefile:",
  131. "warning: Clock skew detected. Your build may be incomplete.",
  132. "/usr/openwin/include/GL/[^:]+:",
  133. "bind_at_load",
  134. "XrmQGetResource",
  135. "IceFlush",
  136. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  137. "ld32: WARNING 85: definition of dataKey in",
  138. "cc: warning 422: Unknown option \"\\+b",
  139. "_with_warning_C",
  140. 0
  141. };
  142. struct cmCTestBuildCompileErrorWarningRex
  143. {
  144. const char* RegularExpressionString;
  145. int FileIndex;
  146. int LineIndex;
  147. };
  148. static cmCTestBuildCompileErrorWarningRex
  149. cmCTestWarningErrorFileLine[] = {
  150. { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
  151. { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
  152. { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  153. { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  154. { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
  155. { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
  156. { 0, 0, 0 }
  157. };
  158. //----------------------------------------------------------------------
  159. cmCTestBuildHandler::cmCTestBuildHandler()
  160. {
  161. this->MaxPreContext = 6;
  162. this->MaxPostContext = 6;
  163. this->MaxErrors = 50;
  164. this->MaxWarnings = 50;
  165. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  166. }
  167. //----------------------------------------------------------------------
  168. void cmCTestBuildHandler::Initialize()
  169. {
  170. this->Superclass::Initialize();
  171. this->StartBuild = "";
  172. this->EndBuild = "";
  173. this->CustomErrorMatches.clear();
  174. this->CustomErrorExceptions.clear();
  175. this->CustomWarningMatches.clear();
  176. this->CustomWarningExceptions.clear();
  177. this->ErrorWarningFileLineRegex.clear();
  178. this->ErrorMatchRegex.clear();
  179. this->ErrorExceptionRegex.clear();
  180. this->WarningMatchRegex.clear();
  181. this->WarningExceptionRegex.clear();
  182. this->BuildProcessingQueue.clear();
  183. this->BuildProcessingErrorQueue.clear();
  184. this->BuildOutputLogSize = 0;
  185. this->CurrentProcessingLine.clear();
  186. this->SimplifySourceDir = "";
  187. this->SimplifyBuildDir = "";
  188. this->OutputLineCounter = 0;
  189. this->ErrorsAndWarnings.clear();
  190. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  191. this->PostContextCount = 0;
  192. this->MaxPreContext = 6;
  193. this->MaxPostContext = 6;
  194. this->PreContext.clear();
  195. this->TotalErrors = 0;
  196. this->TotalWarnings = 0;
  197. this->LastTickChar = 0;
  198. this->ErrorQuotaReached = false;
  199. this->WarningQuotaReached = false;
  200. this->MaxErrors = 50;
  201. this->MaxWarnings = 50;
  202. }
  203. //----------------------------------------------------------------------
  204. void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)
  205. {
  206. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
  207. this->CustomErrorMatches);
  208. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
  209. this->CustomErrorExceptions);
  210. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
  211. this->CustomWarningMatches);
  212. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
  213. this->CustomWarningExceptions);
  214. this->CTest->PopulateCustomInteger(mf,
  215. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
  216. this->MaxErrors);
  217. this->CTest->PopulateCustomInteger(mf,
  218. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
  219. this->MaxWarnings);
  220. }
  221. //----------------------------------------------------------------------
  222. //clearly it would be nice if this were broken up into a few smaller
  223. //functions and commented...
  224. int cmCTestBuildHandler::ProcessHandler()
  225. {
  226. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl);
  227. // do we have time for this
  228. if (this->CTest->GetRemainingTimeAllowed() < 120)
  229. {
  230. return 0;
  231. }
  232. int entry;
  233. for ( entry = 0;
  234. cmCTestWarningErrorFileLine[entry].RegularExpressionString;
  235. ++ entry )
  236. {
  237. cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
  238. if ( r.RegularExpression.compile(
  239. cmCTestWarningErrorFileLine[entry].RegularExpressionString) )
  240. {
  241. r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
  242. r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
  243. this->ErrorWarningFileLineRegex.push_back(r);
  244. }
  245. else
  246. {
  247. cmCTestLog(this->CTest, ERROR_MESSAGE,
  248. "Problem Compiling regular expression: "
  249. << cmCTestWarningErrorFileLine[entry].RegularExpressionString
  250. << std::endl);
  251. }
  252. }
  253. // Determine build command and build directory
  254. const std::string &makeCommand
  255. = this->CTest->GetCTestConfiguration("MakeCommand");
  256. cmCTestLog(this->CTest,
  257. HANDLER_VERBOSE_OUTPUT, "MakeCommand:" << makeCommand <<
  258. "\n");
  259. if ( makeCommand.size() == 0 )
  260. {
  261. cmCTestLog(this->CTest, ERROR_MESSAGE,
  262. "Cannot find MakeCommand key in the DartConfiguration.tcl"
  263. << std::endl);
  264. return -1;
  265. }
  266. const std::string &buildDirectory
  267. = this->CTest->GetCTestConfiguration("BuildDirectory");
  268. if ( buildDirectory.size() == 0 )
  269. {
  270. cmCTestLog(this->CTest, ERROR_MESSAGE,
  271. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  272. << std::endl);
  273. return -1;
  274. }
  275. // Create a last build log
  276. cmGeneratedFileStream ofs;
  277. double elapsed_time_start = cmSystemTools::GetTime();
  278. if ( !this->StartLogFile("Build", ofs) )
  279. {
  280. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file"
  281. << std::endl);
  282. }
  283. // Create lists of regular expression strings for errors, error exceptions,
  284. // warnings and warning exceptions.
  285. std::vector<cmStdString>::size_type cc;
  286. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  287. {
  288. this->CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  289. }
  290. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  291. {
  292. this->CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  293. }
  294. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  295. {
  296. this->CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  297. }
  298. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  299. {
  300. this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  301. }
  302. // Pre-compile regular expressions objects for all regular expressions
  303. std::vector<cmStdString>::iterator it;
  304. #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
  305. regexes.clear(); \
  306. cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
  307. << std::endl); \
  308. for ( it = strings.begin(); it != strings.end(); ++it ) \
  309. { \
  310. cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
  311. << it->c_str() << std::endl); \
  312. regexes.push_back(it->c_str()); \
  313. }
  314. cmCTestBuildHandlerPopulateRegexVector(
  315. this->CustomErrorMatches, this->ErrorMatchRegex);
  316. cmCTestBuildHandlerPopulateRegexVector(
  317. this->CustomErrorExceptions, this->ErrorExceptionRegex);
  318. cmCTestBuildHandlerPopulateRegexVector(
  319. this->CustomWarningMatches, this->WarningMatchRegex);
  320. cmCTestBuildHandlerPopulateRegexVector(
  321. this->CustomWarningExceptions, this->WarningExceptionRegex);
  322. // Determine source and binary tree substitutions to simplify the output.
  323. this->SimplifySourceDir = "";
  324. this->SimplifyBuildDir = "";
  325. if ( this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20 )
  326. {
  327. std::string srcdir
  328. = this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
  329. std::string srcdirrep;
  330. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  331. {
  332. if ( srcdir[cc] == '/' )
  333. {
  334. srcdirrep = srcdir.c_str() + cc;
  335. srcdirrep = "/..." + srcdirrep;
  336. srcdir = srcdir.substr(0, cc+1);
  337. break;
  338. }
  339. }
  340. this->SimplifySourceDir = srcdir;
  341. }
  342. if ( this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20 )
  343. {
  344. std::string bindir
  345. = this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
  346. std::string bindirrep;
  347. for ( cc = bindir.size()-2; cc > 0; cc -- )
  348. {
  349. if ( bindir[cc] == '/' )
  350. {
  351. bindirrep = bindir.c_str() + cc;
  352. bindirrep = "/..." + bindirrep;
  353. bindir = bindir.substr(0, cc+1);
  354. break;
  355. }
  356. }
  357. this->SimplifyBuildDir = bindir;
  358. }
  359. // Ok, let's do the build
  360. // Remember start build time
  361. this->StartBuild = this->CTest->CurrentTime();
  362. this->StartBuildTime = cmSystemTools::GetTime();
  363. int retVal = 0;
  364. int res = cmsysProcess_State_Exited;
  365. if ( !this->CTest->GetShowOnly() )
  366. {
  367. res = this->RunMakeCommand(makeCommand.c_str(), &retVal,
  368. buildDirectory.c_str(), 0, ofs);
  369. }
  370. else
  371. {
  372. cmCTestLog(this->CTest, DEBUG, "Build with command: " << makeCommand
  373. << std::endl);
  374. }
  375. // Remember end build time and calculate elapsed time
  376. this->EndBuild = this->CTest->CurrentTime();
  377. this->EndBuildTime = cmSystemTools::GetTime();
  378. double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
  379. if (res != cmsysProcess_State_Exited || retVal )
  380. {
  381. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
  382. << std::endl);
  383. }
  384. // Cleanups strings in the errors and warnings list.
  385. t_ErrorsAndWarningsVector::iterator evit;
  386. if ( !this->SimplifySourceDir.empty() )
  387. {
  388. for ( evit = this->ErrorsAndWarnings.begin();
  389. evit != this->ErrorsAndWarnings.end();
  390. ++ evit )
  391. {
  392. cmSystemTools::ReplaceString(
  393. evit->Text, this->SimplifySourceDir.c_str(), "/.../");
  394. cmSystemTools::ReplaceString(
  395. evit->PreContext, this->SimplifySourceDir.c_str(), "/.../");
  396. cmSystemTools::ReplaceString(
  397. evit->PostContext, this->SimplifySourceDir.c_str(), "/.../");
  398. }
  399. }
  400. if ( !this->SimplifyBuildDir.empty() )
  401. {
  402. for ( evit = this->ErrorsAndWarnings.begin();
  403. evit != this->ErrorsAndWarnings.end();
  404. ++ evit )
  405. {
  406. cmSystemTools::ReplaceString(
  407. evit->Text, this->SimplifyBuildDir.c_str(), "/.../");
  408. cmSystemTools::ReplaceString(
  409. evit->PreContext, this->SimplifyBuildDir.c_str(), "/.../");
  410. cmSystemTools::ReplaceString(
  411. evit->PostContext, this->SimplifyBuildDir.c_str(), "/.../");
  412. }
  413. }
  414. // Display message about number of errors and warnings
  415. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalErrors
  416. << (this->TotalErrors >= this->MaxErrors ? " or more" : "")
  417. << " Compiler errors" << std::endl);
  418. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalWarnings
  419. << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
  420. << " Compiler warnings" << std::endl);
  421. // Generate XML output
  422. cmGeneratedFileStream xofs;
  423. if( !this->StartResultingXML("Build", xofs))
  424. {
  425. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
  426. << std::endl);
  427. return -1;
  428. }
  429. this->GenerateDartBuildOutput(
  430. xofs, this->ErrorsAndWarnings, elapsed_build_time);
  431. return 0;
  432. }
  433. //----------------------------------------------------------------------
  434. void cmCTestBuildHandler::GenerateDartBuildOutput(
  435. std::ostream& os,
  436. std::vector<cmCTestBuildErrorWarning> ew,
  437. double elapsed_build_time)
  438. {
  439. this->CTest->StartXML(os);
  440. os << "<Build>\n"
  441. << "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n"
  442. << "\t<StartBuildTime>" <<
  443. static_cast<unsigned int>(this->StartBuildTime)
  444. << "</StartBuildTime>\n"
  445. << "<BuildCommand>"
  446. << this->CTest->MakeXMLSafe(
  447. this->CTest->GetCTestConfiguration("MakeCommand"))
  448. << "</BuildCommand>" << std::endl;
  449. std::vector<cmCTestBuildErrorWarning>::iterator it;
  450. // only report the first 50 warnings and first 50 errors
  451. unsigned short numErrorsAllowed = this->MaxErrors;
  452. unsigned short numWarningsAllowed = this->MaxWarnings;
  453. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  454. // make sure the source dir is in the correct case on windows
  455. // via a call to collapse full path.
  456. srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str());
  457. srcdir += "/";
  458. for ( it = ew.begin();
  459. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
  460. {
  461. cmCTestBuildErrorWarning *cm = &(*it);
  462. if (cm->Error && numErrorsAllowed ||
  463. !cm->Error && numWarningsAllowed)
  464. {
  465. if (cm->Error)
  466. {
  467. numErrorsAllowed--;
  468. }
  469. else
  470. {
  471. numWarningsAllowed--;
  472. }
  473. os << "\t<" << (cm->Error ? "Error" : "Warning") << ">\n"
  474. << "\t\t<BuildLogLine>" << cm->LogLine << "</BuildLogLine>\n"
  475. << "\t\t<Text>" << this->CTest->MakeXMLSafe(cm->Text)
  476. << "\n</Text>" << std::endl;
  477. std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
  478. for ( rit = this->ErrorWarningFileLineRegex.begin();
  479. rit != this->ErrorWarningFileLineRegex.end(); ++ rit )
  480. {
  481. cmsys::RegularExpression* re = &rit->RegularExpression;
  482. if ( re->find(cm->Text.c_str() ) )
  483. {
  484. cm->SourceFile = re->match(rit->FileIndex);
  485. // At this point we need to make this->SourceFile relative to
  486. // the source root of the project, so cvs links will work
  487. cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
  488. if(cm->SourceFile.find("/.../") != cm->SourceFile.npos)
  489. {
  490. cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
  491. std::string::size_type p = cm->SourceFile.find("/");
  492. if(p != cm->SourceFile.npos)
  493. {
  494. cm->SourceFile = cm->SourceFile.substr(
  495. p+1, cm->SourceFile.size()-p);
  496. }
  497. }
  498. else
  499. {
  500. // make sure it is a full path with the correct case
  501. cm->SourceFile = cmSystemTools::CollapseFullPath(
  502. cm->SourceFile.c_str());
  503. cmSystemTools::ReplaceString(
  504. cm->SourceFile, srcdir.c_str(), "");
  505. }
  506. cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
  507. break;
  508. }
  509. }
  510. if ( !cm->SourceFile.empty() && cm->LineNumber >= 0 )
  511. {
  512. if ( cm->SourceFile.size() > 0 )
  513. {
  514. os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>"
  515. << std::endl;
  516. }
  517. if ( cm->SourceFileTail.size() > 0 )
  518. {
  519. os << "\t\t<SourceFileTail>" << cm->SourceFileTail
  520. << "</SourceFileTail>" << std::endl;
  521. }
  522. if ( cm->LineNumber >= 0 )
  523. {
  524. os << "\t\t<SourceLineNumber>" << cm->LineNumber
  525. << "</SourceLineNumber>" << std::endl;
  526. }
  527. }
  528. os << "\t\t<PreContext>" << this->CTest->MakeXMLSafe(cm->PreContext)
  529. << "</PreContext>\n"
  530. << "\t\t<PostContext>" << this->CTest->MakeXMLSafe(cm->PostContext);
  531. // is this the last warning or error, if so notify
  532. if (cm->Error && !numErrorsAllowed ||
  533. !cm->Error && !numWarningsAllowed)
  534. {
  535. os << "\nThe maximum number of reported warnings or errors has been "
  536. "reached!!!\n";
  537. }
  538. os << "</PostContext>\n"
  539. << "\t\t<RepeatCount>0</RepeatCount>\n"
  540. << "</" << (cm->Error ? "Error" : "Warning") << ">\n\n"
  541. << std::endl;
  542. }
  543. }
  544. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  545. << "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n"
  546. << "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime)
  547. << "</EndBuildTime>\n"
  548. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  549. << "</ElapsedMinutes>"
  550. << "</Build>" << std::endl;
  551. this->CTest->EndXML(os);
  552. }
  553. //######################################################################
  554. //######################################################################
  555. //######################################################################
  556. //######################################################################
  557. //----------------------------------------------------------------------
  558. int cmCTestBuildHandler::RunMakeCommand(const char* command,
  559. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  560. {
  561. // First generate the command and arguments
  562. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  563. if(args.size() < 1)
  564. {
  565. return false;
  566. }
  567. std::vector<const char*> argv;
  568. for(std::vector<cmStdString>::const_iterator a = args.begin();
  569. a != args.end(); ++a)
  570. {
  571. argv.push_back(a->c_str());
  572. }
  573. argv.push_back(0);
  574. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
  575. std::vector<const char*>::iterator ait;
  576. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  577. {
  578. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  579. }
  580. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  581. // Now create process object
  582. cmsysProcess* cp = cmsysProcess_New();
  583. cmsysProcess_SetCommand(cp, &*argv.begin());
  584. cmsysProcess_SetWorkingDirectory(cp, dir);
  585. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  586. cmsysProcess_SetTimeout(cp, timeout);
  587. cmsysProcess_Execute(cp);
  588. // Initialize tick's
  589. std::string::size_type tick = 0;
  590. const std::string::size_type tick_len = 1024;
  591. char* data;
  592. int length;
  593. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  594. " Each symbol represents " << tick_len << " bytes of output."
  595. << std::endl
  596. << " '!' represents an error and '*' a warning." << std::endl
  597. << " " << std::flush);
  598. // Initialize building structures
  599. this->BuildProcessingQueue.clear();
  600. this->OutputLineCounter = 0;
  601. this->ErrorsAndWarnings.clear();
  602. this->TotalErrors = 0;
  603. this->TotalWarnings = 0;
  604. this->BuildOutputLogSize = 0;
  605. this->LastTickChar = '.';
  606. this->WarningQuotaReached = false;
  607. this->ErrorQuotaReached = false;
  608. // For every chunk of data
  609. int res;
  610. while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
  611. {
  612. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  613. // for Visual Studio output
  614. for(int cc =0; cc < length; ++cc)
  615. {
  616. if(data[cc] == 0)
  617. {
  618. data[cc] = '\n';
  619. }
  620. }
  621. // Process the chunk of data
  622. if ( res == cmsysProcess_Pipe_STDERR )
  623. {
  624. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  625. &this->BuildProcessingErrorQueue);
  626. }
  627. else
  628. {
  629. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  630. &this->BuildProcessingQueue);
  631. }
  632. }
  633. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &this->BuildProcessingQueue);
  634. this->ProcessBuffer(0, 0, tick, tick_len, ofs,
  635. &this->BuildProcessingErrorQueue);
  636. cmCTestLog(this->CTest, OUTPUT, " Size of output: "
  637. << int(this->BuildOutputLogSize / 1024.0) << "K" << std::endl);
  638. // Properly handle output of the build command
  639. cmsysProcess_WaitForExit(cp, 0);
  640. int result = cmsysProcess_GetState(cp);
  641. if(result == cmsysProcess_State_Exited)
  642. {
  643. if (retVal)
  644. {
  645. *retVal = cmsysProcess_GetExitValue(cp);
  646. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  647. "Command exited with the value: " << *retVal << std::endl);
  648. // if a non zero return value
  649. if (*retVal)
  650. {
  651. // If there was an error running command, report that on the
  652. // dashboard.
  653. cmCTestBuildErrorWarning errorwarning;
  654. errorwarning.LogLine = 1;
  655. errorwarning.Text
  656. = "*** WARNING non-zero return value in ctest from: ";
  657. errorwarning.Text += argv[0];
  658. errorwarning.PreContext = "";
  659. errorwarning.PostContext = "";
  660. errorwarning.Error = false;
  661. this->ErrorsAndWarnings.push_back(errorwarning);
  662. this->TotalWarnings ++;
  663. }
  664. }
  665. }
  666. else if(result == cmsysProcess_State_Exception)
  667. {
  668. if (retVal)
  669. {
  670. *retVal = cmsysProcess_GetExitException(cp);
  671. cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
  672. << std::endl);
  673. }
  674. }
  675. else if(result == cmsysProcess_State_Expired)
  676. {
  677. cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
  678. }
  679. else if(result == cmsysProcess_State_Error)
  680. {
  681. // If there was an error running command, report that on the dashboard.
  682. cmCTestBuildErrorWarning errorwarning;
  683. errorwarning.LogLine = 1;
  684. errorwarning.Text = "*** ERROR executing: ";
  685. errorwarning.Text += cmsysProcess_GetErrorString(cp);
  686. errorwarning.PreContext = "";
  687. errorwarning.PostContext = "";
  688. errorwarning.Error = true;
  689. this->ErrorsAndWarnings.push_back(errorwarning);
  690. this->TotalErrors ++;
  691. cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
  692. << cmsysProcess_GetErrorString(cp) << std::endl);
  693. }
  694. cmsysProcess_Delete(cp);
  695. return result;
  696. }
  697. //######################################################################
  698. //######################################################################
  699. //######################################################################
  700. //######################################################################
  701. //----------------------------------------------------------------------
  702. void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
  703. size_t& tick, size_t tick_len, std::ofstream& ofs,
  704. t_BuildProcessingQueueType* queue)
  705. {
  706. const std::string::size_type tick_line_len = 50;
  707. const char* ptr;
  708. for ( ptr = data; ptr < data+length; ptr ++ )
  709. {
  710. queue->push_back(*ptr);
  711. }
  712. this->BuildOutputLogSize += length;
  713. // until there are any lines left in the buffer
  714. while ( 1 )
  715. {
  716. // Find the end of line
  717. t_BuildProcessingQueueType::iterator it;
  718. for ( it = queue->begin();
  719. it != queue->end();
  720. ++ it )
  721. {
  722. if ( *it == '\n' )
  723. {
  724. break;
  725. }
  726. }
  727. // Once certain number of errors or warnings reached, ignore future errors
  728. // or warnings.
  729. if ( this->TotalWarnings >= this->MaxWarnings )
  730. {
  731. this->WarningQuotaReached = true;
  732. }
  733. if ( this->TotalErrors >= this->MaxErrors )
  734. {
  735. this->ErrorQuotaReached = true;
  736. }
  737. // If the end of line was found
  738. if ( it != queue->end() )
  739. {
  740. // Create a contiguous array for the line
  741. this->CurrentProcessingLine.clear();
  742. t_BuildProcessingQueueType::iterator cit;
  743. for ( cit = queue->begin(); cit != it; ++cit )
  744. {
  745. this->CurrentProcessingLine.push_back(*cit);
  746. }
  747. this->CurrentProcessingLine.push_back(0);
  748. const char* line = &*this->CurrentProcessingLine.begin();
  749. // Process the line
  750. int lineType = this->ProcessSingleLine(line);
  751. // Erase the line from the queue
  752. queue->erase(queue->begin(), it+1);
  753. // Depending on the line type, produce error or warning, or nothing
  754. cmCTestBuildErrorWarning errorwarning;
  755. bool found = false;
  756. switch ( lineType )
  757. {
  758. case b_WARNING_LINE:
  759. this->LastTickChar = '*';
  760. errorwarning.Error = false;
  761. found = true;
  762. this->TotalWarnings ++;
  763. break;
  764. case b_ERROR_LINE:
  765. this->LastTickChar = '!';
  766. errorwarning.Error = true;
  767. found = true;
  768. this->TotalErrors ++;
  769. break;
  770. }
  771. if ( found )
  772. {
  773. // This is an error or warning, so generate report
  774. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter+1);
  775. errorwarning.Text = line;
  776. errorwarning.PreContext = "";
  777. errorwarning.PostContext = "";
  778. // Copy pre-context to report
  779. std::deque<cmStdString>::iterator pcit;
  780. for ( pcit = this->PreContext.begin();
  781. pcit != this->PreContext.end();
  782. ++pcit )
  783. {
  784. errorwarning.PreContext += *pcit + "\n";
  785. }
  786. this->PreContext.clear();
  787. // Store report
  788. this->ErrorsAndWarnings.push_back(errorwarning);
  789. this->LastErrorOrWarning = this->ErrorsAndWarnings.end()-1;
  790. this->PostContextCount = 0;
  791. }
  792. else
  793. {
  794. // This is not an error or warning.
  795. // So, figure out if this is a post-context line
  796. if ( this->ErrorsAndWarnings.size() &&
  797. this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  798. this->PostContextCount < this->MaxPostContext )
  799. {
  800. this->PostContextCount ++;
  801. this->LastErrorOrWarning->PostContext += line;
  802. if ( this->PostContextCount < this->MaxPostContext )
  803. {
  804. this->LastErrorOrWarning->PostContext += "\n";
  805. }
  806. }
  807. else
  808. {
  809. // Otherwise store pre-context for the next error
  810. this->PreContext.push_back(line);
  811. if ( this->PreContext.size() > this->MaxPreContext )
  812. {
  813. this->PreContext.erase(this->PreContext.begin(),
  814. this->PreContext.end()-this->MaxPreContext);
  815. }
  816. }
  817. }
  818. this->OutputLineCounter ++;
  819. }
  820. else
  821. {
  822. break;
  823. }
  824. }
  825. // Now that the buffer is processed, display missing ticks
  826. int tickDisplayed = false;
  827. while ( this->BuildOutputLogSize > (tick * tick_len) )
  828. {
  829. tick ++;
  830. cmCTestLog(this->CTest, HANDLER_OUTPUT, this->LastTickChar);
  831. tickDisplayed = true;
  832. if ( tick % tick_line_len == 0 && tick > 0 )
  833. {
  834. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Size: "
  835. << int((this->BuildOutputLogSize / 1024.0) + 1) << "K" << std::endl
  836. << " ");
  837. }
  838. }
  839. if ( tickDisplayed )
  840. {
  841. this->LastTickChar = '.';
  842. }
  843. // And if this is verbose output, display the content of the chunk
  844. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  845. cmCTestLogWrite(data, length));
  846. // Always store the chunk to the file
  847. ofs << cmCTestLogWrite(data, length);
  848. }
  849. //----------------------------------------------------------------------
  850. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  851. {
  852. cmCTestLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl);
  853. std::vector<cmsys::RegularExpression>::iterator it;
  854. int warningLine = 0;
  855. int errorLine = 0;
  856. // Check for regular expressions
  857. if ( !this->ErrorQuotaReached )
  858. {
  859. // Errors
  860. int wrxCnt = 0;
  861. for ( it = this->ErrorMatchRegex.begin();
  862. it != this->ErrorMatchRegex.end();
  863. ++ it )
  864. {
  865. if ( it->find(data) )
  866. {
  867. errorLine = 1;
  868. cmCTestLog(this->CTest, DEBUG, " Error Line: " << data
  869. << " (matches: " << this->CustomErrorMatches[wrxCnt] << ")"
  870. << std::endl);
  871. break;
  872. }
  873. wrxCnt ++;
  874. }
  875. // Error exceptions
  876. wrxCnt = 0;
  877. for ( it = this->ErrorExceptionRegex.begin();
  878. it != this->ErrorExceptionRegex.end();
  879. ++ it )
  880. {
  881. if ( it->find(data) )
  882. {
  883. errorLine = 0;
  884. cmCTestLog(this->CTest, DEBUG, " Not an error Line: " << data
  885. << " (matches: " << this->CustomErrorExceptions[wrxCnt] << ")"
  886. << std::endl);
  887. break;
  888. }
  889. wrxCnt ++;
  890. }
  891. }
  892. if ( !this->WarningQuotaReached )
  893. {
  894. // Warnings
  895. int wrxCnt = 0;
  896. for ( it = this->WarningMatchRegex.begin();
  897. it != this->WarningMatchRegex.end();
  898. ++ it )
  899. {
  900. if ( it->find(data) )
  901. {
  902. warningLine = 1;
  903. cmCTestLog(this->CTest, DEBUG,
  904. " Warning Line: " << data
  905. << " (matches: " << this->CustomWarningMatches[wrxCnt] << ")"
  906. << std::endl);
  907. break;
  908. }
  909. wrxCnt ++;
  910. }
  911. wrxCnt = 0;
  912. // Warning exceptions
  913. for ( it = this->WarningExceptionRegex.begin();
  914. it != this->WarningExceptionRegex.end();
  915. ++ it )
  916. {
  917. if ( it->find(data) )
  918. {
  919. warningLine = 0;
  920. cmCTestLog(this->CTest, DEBUG, " Not a warning Line: " << data
  921. << " (matches: " << this->CustomWarningExceptions[wrxCnt] << ")"
  922. << std::endl);
  923. break;
  924. }
  925. wrxCnt ++;
  926. }
  927. }
  928. if ( errorLine )
  929. {
  930. return b_ERROR_LINE;
  931. }
  932. if ( warningLine )
  933. {
  934. return b_WARNING_LINE;
  935. }
  936. return b_REGULAR_LINE;
  937. }