cmCTestBuildHandler.cxx 32 KB

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