cmCTestBuildHandler.cxx 31 KB

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