cmCTestBuildHandler.cxx 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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.size() > 0 )
  490. {
  491. os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>"
  492. << std::endl;
  493. }
  494. if ( cm->SourceFileTail.size() > 0 )
  495. {
  496. os << "\t\t<SourceFileTail>" << cm->SourceFileTail
  497. << "</SourceFileTail>" << std::endl;
  498. }
  499. if ( cm->LineNumber >= 0 )
  500. {
  501. os << "\t\t<SourceLineNumber>" << cm->LineNumber
  502. << "</SourceLineNumber>" << std::endl;
  503. }
  504. os << "\t\t<PreContext>" << this->CTest->MakeXMLSafe(cm->PreContext)
  505. << "</PreContext>\n"
  506. << "\t\t<PostContext>" << this->CTest->MakeXMLSafe(cm->PostContext);
  507. // is this the last warning or error, if so notify
  508. if (cm->Error && !numErrorsAllowed ||
  509. !cm->Error && !numWarningsAllowed)
  510. {
  511. os << "\nThe maximum number of reported warnings or errors has been "
  512. "reached!!!\n";
  513. }
  514. os << "</PostContext>\n"
  515. << "\t\t<RepeatCount>0</RepeatCount>\n"
  516. << "</" << (cm->Error ? "Error" : "Warning") << ">\n\n"
  517. << std::endl;
  518. }
  519. }
  520. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  521. << "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n"
  522. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  523. << "</ElapsedMinutes>"
  524. << "</Build>" << std::endl;
  525. this->CTest->EndXML(os);
  526. }
  527. //######################################################################
  528. //######################################################################
  529. //######################################################################
  530. //######################################################################
  531. //----------------------------------------------------------------------
  532. int cmCTestBuildHandler::RunMakeCommand(const char* command,
  533. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  534. {
  535. // First generate the command and arguments
  536. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  537. if(args.size() < 1)
  538. {
  539. return false;
  540. }
  541. std::vector<const char*> argv;
  542. for(std::vector<cmStdString>::const_iterator a = args.begin();
  543. a != args.end(); ++a)
  544. {
  545. argv.push_back(a->c_str());
  546. }
  547. argv.push_back(0);
  548. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
  549. std::vector<const char*>::iterator ait;
  550. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  551. {
  552. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  553. }
  554. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  555. // Now create process object
  556. cmsysProcess* cp = cmsysProcess_New();
  557. cmsysProcess_SetCommand(cp, &*argv.begin());
  558. cmsysProcess_SetWorkingDirectory(cp, dir);
  559. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  560. cmsysProcess_SetTimeout(cp, timeout);
  561. cmsysProcess_Execute(cp);
  562. // Initialize tick's
  563. std::string::size_type tick = 0;
  564. const std::string::size_type tick_len = 1024;
  565. char* data;
  566. int length;
  567. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  568. " Each symbol represents " << tick_len << " bytes of output."
  569. << std::endl
  570. << " '!' represents an error and '*' a warning." << std::endl
  571. << " " << std::flush);
  572. // Initialize building structures
  573. this->BuildProcessingQueue.clear();
  574. this->OutputLineCounter = 0;
  575. this->ErrorsAndWarnings.clear();
  576. this->TotalErrors = 0;
  577. this->TotalWarnings = 0;
  578. this->BuildOutputLogSize = 0;
  579. this->LastTickChar = '.';
  580. this->WarningQuotaReached = false;
  581. this->ErrorQuotaReached = false;
  582. // For every chunk of data
  583. int res;
  584. while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
  585. {
  586. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  587. // for Visual Studio output
  588. for(int cc =0; cc < length; ++cc)
  589. {
  590. if(data[cc] == 0)
  591. {
  592. data[cc] = '\n';
  593. }
  594. }
  595. // Process the chunk of data
  596. if ( res == cmsysProcess_Pipe_STDERR )
  597. {
  598. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  599. &this->BuildProcessingErrorQueue);
  600. }
  601. else
  602. {
  603. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  604. &this->BuildProcessingQueue);
  605. }
  606. }
  607. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &this->BuildProcessingQueue);
  608. this->ProcessBuffer(0, 0, tick, tick_len, ofs,
  609. &this->BuildProcessingErrorQueue);
  610. cmCTestLog(this->CTest, OUTPUT, " Size of output: "
  611. << int(this->BuildOutputLogSize / 1024.0) << "K" << std::endl);
  612. // Properly handle output of the build command
  613. cmsysProcess_WaitForExit(cp, 0);
  614. int result = cmsysProcess_GetState(cp);
  615. if(result == cmsysProcess_State_Exited)
  616. {
  617. *retVal = cmsysProcess_GetExitValue(cp);
  618. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  619. "Command exited with the value: " << *retVal << std::endl);
  620. }
  621. else if(result == cmsysProcess_State_Exception)
  622. {
  623. *retVal = cmsysProcess_GetExitException(cp);
  624. cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
  625. << std::endl);
  626. }
  627. else if(result == cmsysProcess_State_Expired)
  628. {
  629. cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
  630. }
  631. else if(result == cmsysProcess_State_Error)
  632. {
  633. // If there was an error running command, report that on the dashboard.
  634. cmCTestBuildErrorWarning errorwarning;
  635. errorwarning.LogLine = 1;
  636. errorwarning.Text = "*** ERROR executing: ";
  637. errorwarning.Text += cmsysProcess_GetErrorString(cp);
  638. errorwarning.PreContext = "";
  639. errorwarning.PostContext = "";
  640. errorwarning.Error = true;
  641. this->ErrorsAndWarnings.push_back(errorwarning);
  642. this->TotalErrors ++;
  643. cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
  644. << cmsysProcess_GetErrorString(cp) << std::endl);
  645. }
  646. cmsysProcess_Delete(cp);
  647. return result;
  648. }
  649. //######################################################################
  650. //######################################################################
  651. //######################################################################
  652. //######################################################################
  653. //----------------------------------------------------------------------
  654. void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
  655. size_t& tick, size_t tick_len, std::ofstream& ofs,
  656. t_BuildProcessingQueueType* queue)
  657. {
  658. #undef cerr
  659. const std::string::size_type tick_line_len = 50;
  660. const char* ptr;
  661. for ( ptr = data; ptr < data+length; ptr ++ )
  662. {
  663. queue->push_back(*ptr);
  664. }
  665. this->BuildOutputLogSize += length;
  666. // until there are any lines left in the buffer
  667. while ( 1 )
  668. {
  669. // Find the end of line
  670. t_BuildProcessingQueueType::iterator it;
  671. for ( it = queue->begin();
  672. it != queue->end();
  673. ++ it )
  674. {
  675. if ( *it == '\n' )
  676. {
  677. break;
  678. }
  679. }
  680. // Once certain number of errors or warnings reached, ignore future errors
  681. // or warnings.
  682. if ( this->TotalWarnings >= this->MaxWarnings )
  683. {
  684. this->WarningQuotaReached = true;
  685. }
  686. if ( this->TotalErrors >= this->MaxErrors )
  687. {
  688. this->ErrorQuotaReached = true;
  689. }
  690. // If the end of line was found
  691. if ( it != queue->end() )
  692. {
  693. // Create a contiguous array for the line
  694. this->CurrentProcessingLine.clear();
  695. t_BuildProcessingQueueType::iterator cit;
  696. for ( cit = queue->begin(); cit != it; ++cit )
  697. {
  698. this->CurrentProcessingLine.push_back(*cit);
  699. }
  700. this->CurrentProcessingLine.push_back(0);
  701. const char* line = &*this->CurrentProcessingLine.begin();
  702. // Process the line
  703. int lineType = this->ProcessSingleLine(line);
  704. // Erase the line from the queue
  705. queue->erase(queue->begin(), it+1);
  706. // Depending on the line type, produce error or warning, or nothing
  707. cmCTestBuildErrorWarning errorwarning;
  708. bool found = false;
  709. switch ( lineType )
  710. {
  711. case b_WARNING_LINE:
  712. this->LastTickChar = '*';
  713. errorwarning.Error = false;
  714. found = true;
  715. this->TotalWarnings ++;
  716. break;
  717. case b_ERROR_LINE:
  718. this->LastTickChar = '!';
  719. errorwarning.Error = true;
  720. found = true;
  721. this->TotalErrors ++;
  722. break;
  723. }
  724. if ( found )
  725. {
  726. // This is an error or warning, so generate report
  727. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter+1);
  728. errorwarning.Text = line;
  729. errorwarning.PreContext = "";
  730. errorwarning.PostContext = "";
  731. // Copy pre-context to report
  732. std::deque<cmStdString>::iterator pcit;
  733. for ( pcit = this->PreContext.begin();
  734. pcit != this->PreContext.end();
  735. ++pcit )
  736. {
  737. errorwarning.PreContext += *pcit + "\n";
  738. }
  739. this->PreContext.clear();
  740. // Store report
  741. this->ErrorsAndWarnings.push_back(errorwarning);
  742. this->LastErrorOrWarning = this->ErrorsAndWarnings.end()-1;
  743. this->PostContextCount = 0;
  744. }
  745. else
  746. {
  747. // This is not an error or warning.
  748. // So, figure out if this is a post-context line
  749. if ( this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  750. this->PostContextCount < this->MaxPostContext )
  751. {
  752. this->PostContextCount ++;
  753. this->LastErrorOrWarning->PostContext += line;
  754. if ( this->PostContextCount < this->MaxPostContext )
  755. {
  756. this->LastErrorOrWarning->PostContext += "\n";
  757. }
  758. }
  759. else
  760. {
  761. // Otherwise store pre-context for the next error
  762. this->PreContext.push_back(line);
  763. if ( this->PreContext.size() > this->MaxPreContext )
  764. {
  765. this->PreContext.erase(this->PreContext.begin(),
  766. this->PreContext.end()-this->MaxPreContext);
  767. }
  768. }
  769. }
  770. this->OutputLineCounter ++;
  771. }
  772. else
  773. {
  774. break;
  775. }
  776. }
  777. // Now that the buffer is processed, display missing ticks
  778. int tickDisplayed = false;
  779. while ( this->BuildOutputLogSize > (tick * tick_len) )
  780. {
  781. tick ++;
  782. cmCTestLog(this->CTest, HANDLER_OUTPUT, this->LastTickChar);
  783. tickDisplayed = true;
  784. if ( tick % tick_line_len == 0 && tick > 0 )
  785. {
  786. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Size: "
  787. << int((this->BuildOutputLogSize / 1024.0) + 1) << "K" << std::endl
  788. << " ");
  789. }
  790. }
  791. if ( tickDisplayed )
  792. {
  793. this->LastTickChar = '.';
  794. }
  795. // And if this is verbose output, display the content of the chunk
  796. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  797. cmCTestLogWrite(data, length));
  798. // Always store the chunk to the file
  799. ofs << cmCTestLogWrite(data, length);
  800. }
  801. //----------------------------------------------------------------------
  802. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  803. {
  804. cmCTestLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl);
  805. std::vector<cmsys::RegularExpression>::iterator it;
  806. int warningLine = 0;
  807. int errorLine = 0;
  808. // Check for regular expressions
  809. if ( !this->ErrorQuotaReached )
  810. {
  811. // Errors
  812. for ( it = this->ErrorMatchRegex.begin();
  813. it != this->ErrorMatchRegex.end();
  814. ++ it )
  815. {
  816. if ( it->find(data) )
  817. {
  818. errorLine = 1;
  819. cmCTestLog(this->CTest, DEBUG, " Error Line: " << data << std::endl);
  820. break;
  821. }
  822. }
  823. // Error exceptions
  824. for ( it = this->ErrorExceptionRegex.begin();
  825. it != this->ErrorExceptionRegex.end();
  826. ++ it )
  827. {
  828. if ( it->find(data) )
  829. {
  830. errorLine = 0;
  831. cmCTestLog(this->CTest, DEBUG, " Not an error Line: " << data
  832. << std::endl);
  833. break;
  834. }
  835. }
  836. }
  837. if ( !this->WarningQuotaReached )
  838. {
  839. // Warnings
  840. for ( it = this->WarningMatchRegex.begin();
  841. it != this->WarningMatchRegex.end();
  842. ++ it )
  843. {
  844. if ( it->find(data) )
  845. {
  846. warningLine = 1;
  847. cmCTestLog(this->CTest, DEBUG,
  848. " Warning Line: " << data << std::endl);
  849. break;
  850. }
  851. }
  852. // Warning exceptions
  853. for ( it = this->WarningExceptionRegex.begin();
  854. it != this->WarningExceptionRegex.end();
  855. ++ it )
  856. {
  857. if ( it->find(data) )
  858. {
  859. warningLine = 0;
  860. cmCTestLog(this->CTest, DEBUG, " Not a warning Line: " << data
  861. << std::endl);
  862. break;
  863. }
  864. }
  865. }
  866. if ( errorLine )
  867. {
  868. return b_ERROR_LINE;
  869. }
  870. if ( warningLine )
  871. {
  872. return b_WARNING_LINE;
  873. }
  874. return b_REGULAR_LINE;
  875. }