cmCTestBuildHandler.cxx 32 KB

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