cmCTestBuildHandler.cxx 31 KB

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