cmCTestBuildHandler.cxx 30 KB

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