cmCTestBuildHandler.cxx 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestBuildHandler.h"
  11. #include "cmCTest.h"
  12. #include "cmake.h"
  13. #include "cmMakefile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmXMLSafe.h"
  18. #include "cmFileTimeComparison.h"
  19. //#include <cmsys/RegularExpression.hxx>
  20. #include <cmsys/Process.h>
  21. #include <cmsys/Directory.hxx>
  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. "^CMake Warning.*:",
  122. 0
  123. };
  124. static const char* cmCTestWarningExceptions[] = {
  125. "/usr/.*/X11/Xlib\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  126. "/usr/.*/X11/Xutil\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  127. "/usr/.*/X11/XResource\\.h:[0-9]+: war.*: ANSI C\\+\\+ forbids declaration",
  128. "WARNING 84 :",
  129. "WARNING 47 :",
  130. "makefile:",
  131. "Makefile:",
  132. "warning: Clock skew detected. Your build may be incomplete.",
  133. "/usr/openwin/include/GL/[^:]+:",
  134. "bind_at_load",
  135. "XrmQGetResource",
  136. "IceFlush",
  137. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  138. "ld32: WARNING 85: definition of dataKey in",
  139. "cc: warning 422: Unknown option \"\\+b",
  140. "_with_warning_C",
  141. 0
  142. };
  143. struct cmCTestBuildCompileErrorWarningRex
  144. {
  145. const char* RegularExpressionString;
  146. int FileIndex;
  147. int LineIndex;
  148. };
  149. static cmCTestBuildCompileErrorWarningRex
  150. cmCTestWarningErrorFileLine[] = {
  151. { "^Warning W[0-9]+ ([a-zA-Z.\\:/0-9_+ ~-]+) ([0-9]+):", 1, 2 },
  152. { "^([a-zA-Z./0-9_+ ~-]+):([0-9]+):", 1, 2 },
  153. { "^([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  154. { "^[0-9]+>([a-zA-Z.\\:/0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  155. { "^([a-zA-Z./0-9_+ ~-]+)\\(([0-9]+)\\)", 1, 2 },
  156. { "\"([a-zA-Z./0-9_+ ~-]+)\", line ([0-9]+)", 1, 2 },
  157. { "File = ([a-zA-Z./0-9_+ ~-]+), Line = ([0-9]+)", 1, 2 },
  158. { 0, 0, 0 }
  159. };
  160. //----------------------------------------------------------------------
  161. cmCTestBuildHandler::cmCTestBuildHandler()
  162. {
  163. this->MaxPreContext = 10;
  164. this->MaxPostContext = 10;
  165. this->MaxErrors = 50;
  166. this->MaxWarnings = 50;
  167. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  168. this->UseCTestLaunch = false;
  169. }
  170. //----------------------------------------------------------------------
  171. void cmCTestBuildHandler::Initialize()
  172. {
  173. this->Superclass::Initialize();
  174. this->StartBuild = "";
  175. this->EndBuild = "";
  176. this->CustomErrorMatches.clear();
  177. this->CustomErrorExceptions.clear();
  178. this->CustomWarningMatches.clear();
  179. this->CustomWarningExceptions.clear();
  180. this->ReallyCustomWarningMatches.clear();
  181. this->ReallyCustomWarningExceptions.clear();
  182. this->ErrorWarningFileLineRegex.clear();
  183. this->ErrorMatchRegex.clear();
  184. this->ErrorExceptionRegex.clear();
  185. this->WarningMatchRegex.clear();
  186. this->WarningExceptionRegex.clear();
  187. this->BuildProcessingQueue.clear();
  188. this->BuildProcessingErrorQueue.clear();
  189. this->BuildOutputLogSize = 0;
  190. this->CurrentProcessingLine.clear();
  191. this->SimplifySourceDir = "";
  192. this->SimplifyBuildDir = "";
  193. this->OutputLineCounter = 0;
  194. this->ErrorsAndWarnings.clear();
  195. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  196. this->PostContextCount = 0;
  197. this->MaxPreContext = 10;
  198. this->MaxPostContext = 10;
  199. this->PreContext.clear();
  200. this->TotalErrors = 0;
  201. this->TotalWarnings = 0;
  202. this->LastTickChar = 0;
  203. this->ErrorQuotaReached = false;
  204. this->WarningQuotaReached = false;
  205. this->MaxErrors = 50;
  206. this->MaxWarnings = 50;
  207. this->UseCTestLaunch = false;
  208. }
  209. //----------------------------------------------------------------------
  210. void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile *mf)
  211. {
  212. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
  213. this->CustomErrorMatches);
  214. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
  215. this->CustomErrorExceptions);
  216. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
  217. this->CustomWarningMatches);
  218. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
  219. this->CustomWarningExceptions);
  220. this->CTest->PopulateCustomInteger(mf,
  221. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS",
  222. this->MaxErrors);
  223. this->CTest->PopulateCustomInteger(mf,
  224. "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS",
  225. this->MaxWarnings);
  226. int n = -1;
  227. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_PRE_CONTEXT", n);
  228. if (n != -1)
  229. {
  230. this->MaxPreContext = static_cast<size_t>(n);
  231. }
  232. n = -1;
  233. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_POST_CONTEXT", n);
  234. if (n != -1)
  235. {
  236. this->MaxPostContext = static_cast<size_t>(n);
  237. }
  238. // Record the user-specified custom warning rules.
  239. if(const char* customWarningMatchers =
  240. mf->GetDefinition("CTEST_CUSTOM_WARNING_MATCH"))
  241. {
  242. cmSystemTools::ExpandListArgument(customWarningMatchers,
  243. this->ReallyCustomWarningMatches);
  244. }
  245. if(const char* customWarningExceptions =
  246. mf->GetDefinition("CTEST_CUSTOM_WARNING_EXCEPTION"))
  247. {
  248. cmSystemTools::ExpandListArgument(customWarningExceptions,
  249. this->ReallyCustomWarningExceptions);
  250. }
  251. }
  252. //----------------------------------------------------------------------
  253. std::string cmCTestBuildHandler::GetMakeCommand()
  254. {
  255. std::string makeCommand
  256. = this->CTest->GetCTestConfiguration("MakeCommand");
  257. cmCTestLog(this->CTest,
  258. HANDLER_VERBOSE_OUTPUT, "MakeCommand:" << makeCommand <<
  259. "\n");
  260. std::string configType = this->CTest->GetConfigType();
  261. if (configType == "")
  262. {
  263. configType
  264. = this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
  265. }
  266. if (configType == "")
  267. {
  268. configType = "Release";
  269. }
  270. cmSystemTools::ReplaceString(makeCommand,
  271. "${CTEST_CONFIGURATION_TYPE}", configType.c_str());
  272. return makeCommand;
  273. }
  274. //----------------------------------------------------------------------
  275. //clearly it would be nice if this were broken up into a few smaller
  276. //functions and commented...
  277. int cmCTestBuildHandler::ProcessHandler()
  278. {
  279. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl);
  280. // do we have time for this
  281. if (this->CTest->GetRemainingTimeAllowed() < 120)
  282. {
  283. return 0;
  284. }
  285. int entry;
  286. for ( entry = 0;
  287. cmCTestWarningErrorFileLine[entry].RegularExpressionString;
  288. ++ entry )
  289. {
  290. cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
  291. if ( r.RegularExpression.compile(
  292. cmCTestWarningErrorFileLine[entry].RegularExpressionString) )
  293. {
  294. r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
  295. r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
  296. this->ErrorWarningFileLineRegex.push_back(r);
  297. }
  298. else
  299. {
  300. cmCTestLog(this->CTest, ERROR_MESSAGE,
  301. "Problem Compiling regular expression: "
  302. << cmCTestWarningErrorFileLine[entry].RegularExpressionString
  303. << std::endl);
  304. }
  305. }
  306. // Determine build command and build directory
  307. std::string makeCommand = this->GetMakeCommand();
  308. if ( makeCommand.size() == 0 )
  309. {
  310. cmCTestLog(this->CTest, ERROR_MESSAGE,
  311. "Cannot find MakeCommand key in the DartConfiguration.tcl"
  312. << std::endl);
  313. return -1;
  314. }
  315. const std::string &buildDirectory
  316. = this->CTest->GetCTestConfiguration("BuildDirectory");
  317. if ( buildDirectory.size() == 0 )
  318. {
  319. cmCTestLog(this->CTest, ERROR_MESSAGE,
  320. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  321. << std::endl);
  322. return -1;
  323. }
  324. std::string const& useLaunchers =
  325. this->CTest->GetCTestConfiguration("UseLaunchers");
  326. this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers.c_str());
  327. // Create a last build log
  328. cmGeneratedFileStream ofs;
  329. double elapsed_time_start = cmSystemTools::GetTime();
  330. if ( !this->StartLogFile("Build", ofs) )
  331. {
  332. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file"
  333. << std::endl);
  334. }
  335. // Create lists of regular expression strings for errors, error exceptions,
  336. // warnings and warning exceptions.
  337. std::vector<cmStdString>::size_type cc;
  338. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  339. {
  340. this->CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  341. }
  342. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  343. {
  344. this->CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  345. }
  346. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  347. {
  348. this->CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  349. }
  350. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  351. {
  352. this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  353. }
  354. // Pre-compile regular expressions objects for all regular expressions
  355. std::vector<cmStdString>::iterator it;
  356. #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
  357. regexes.clear(); \
  358. cmCTestLog(this->CTest, DEBUG, this << "Add " #regexes \
  359. << std::endl); \
  360. for ( it = strings.begin(); it != strings.end(); ++it ) \
  361. { \
  362. cmCTestLog(this->CTest, DEBUG, "Add " #strings ": " \
  363. << it->c_str() << std::endl); \
  364. regexes.push_back(it->c_str()); \
  365. }
  366. cmCTestBuildHandlerPopulateRegexVector(
  367. this->CustomErrorMatches, this->ErrorMatchRegex);
  368. cmCTestBuildHandlerPopulateRegexVector(
  369. this->CustomErrorExceptions, this->ErrorExceptionRegex);
  370. cmCTestBuildHandlerPopulateRegexVector(
  371. this->CustomWarningMatches, this->WarningMatchRegex);
  372. cmCTestBuildHandlerPopulateRegexVector(
  373. this->CustomWarningExceptions, this->WarningExceptionRegex);
  374. // Determine source and binary tree substitutions to simplify the output.
  375. this->SimplifySourceDir = "";
  376. this->SimplifyBuildDir = "";
  377. if ( this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20 )
  378. {
  379. std::string srcdir
  380. = this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
  381. std::string srcdirrep;
  382. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  383. {
  384. if ( srcdir[cc] == '/' )
  385. {
  386. srcdirrep = srcdir.c_str() + cc;
  387. srcdirrep = "/..." + srcdirrep;
  388. srcdir = srcdir.substr(0, cc+1);
  389. break;
  390. }
  391. }
  392. this->SimplifySourceDir = srcdir;
  393. }
  394. if ( this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20 )
  395. {
  396. std::string bindir
  397. = this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
  398. std::string bindirrep;
  399. for ( cc = bindir.size()-2; cc > 0; cc -- )
  400. {
  401. if ( bindir[cc] == '/' )
  402. {
  403. bindirrep = bindir.c_str() + cc;
  404. bindirrep = "/..." + bindirrep;
  405. bindir = bindir.substr(0, cc+1);
  406. break;
  407. }
  408. }
  409. this->SimplifyBuildDir = bindir;
  410. }
  411. // Ok, let's do the build
  412. // Remember start build time
  413. this->StartBuild = this->CTest->CurrentTime();
  414. this->StartBuildTime = cmSystemTools::GetTime();
  415. int retVal = 0;
  416. int res = cmsysProcess_State_Exited;
  417. if ( !this->CTest->GetShowOnly() )
  418. {
  419. res = this->RunMakeCommand(makeCommand.c_str(), &retVal,
  420. buildDirectory.c_str(), 0, ofs);
  421. }
  422. else
  423. {
  424. cmCTestLog(this->CTest, DEBUG, "Build with command: " << makeCommand
  425. << std::endl);
  426. }
  427. // Remember end build time and calculate elapsed time
  428. this->EndBuild = this->CTest->CurrentTime();
  429. this->EndBuildTime = cmSystemTools::GetTime();
  430. double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
  431. // Cleanups strings in the errors and warnings list.
  432. t_ErrorsAndWarningsVector::iterator evit;
  433. if ( !this->SimplifySourceDir.empty() )
  434. {
  435. for ( evit = this->ErrorsAndWarnings.begin();
  436. evit != this->ErrorsAndWarnings.end();
  437. ++ evit )
  438. {
  439. cmSystemTools::ReplaceString(
  440. evit->Text, this->SimplifySourceDir.c_str(), "/.../");
  441. cmSystemTools::ReplaceString(
  442. evit->PreContext, this->SimplifySourceDir.c_str(), "/.../");
  443. cmSystemTools::ReplaceString(
  444. evit->PostContext, this->SimplifySourceDir.c_str(), "/.../");
  445. }
  446. }
  447. if ( !this->SimplifyBuildDir.empty() )
  448. {
  449. for ( evit = this->ErrorsAndWarnings.begin();
  450. evit != this->ErrorsAndWarnings.end();
  451. ++ evit )
  452. {
  453. cmSystemTools::ReplaceString(
  454. evit->Text, this->SimplifyBuildDir.c_str(), "/.../");
  455. cmSystemTools::ReplaceString(
  456. evit->PreContext, this->SimplifyBuildDir.c_str(), "/.../");
  457. cmSystemTools::ReplaceString(
  458. evit->PostContext, this->SimplifyBuildDir.c_str(), "/.../");
  459. }
  460. }
  461. // Generate XML output
  462. cmGeneratedFileStream xofs;
  463. if(!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs))
  464. {
  465. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
  466. << std::endl);
  467. return -1;
  468. }
  469. this->GenerateXMLHeader(xofs);
  470. if(this->UseCTestLaunch)
  471. {
  472. this->GenerateXMLLaunched(xofs);
  473. }
  474. else
  475. {
  476. this->GenerateXMLLogScraped(xofs);
  477. }
  478. this->GenerateXMLFooter(xofs, elapsed_build_time);
  479. if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0)
  480. {
  481. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
  482. << std::endl);
  483. }
  484. // Display message about number of errors and warnings
  485. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalErrors
  486. << (this->TotalErrors >= this->MaxErrors ? " or more" : "")
  487. << " Compiler errors" << std::endl);
  488. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << this->TotalWarnings
  489. << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
  490. << " Compiler warnings" << std::endl);
  491. return retVal;
  492. }
  493. //----------------------------------------------------------------------------
  494. void cmCTestBuildHandler::GenerateXMLHeader(std::ostream& os)
  495. {
  496. this->CTest->StartXML(os, this->AppendXML);
  497. os << "<Build>\n"
  498. << "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n"
  499. << "\t<StartBuildTime>" <<
  500. static_cast<unsigned int>(this->StartBuildTime)
  501. << "</StartBuildTime>\n"
  502. << "<BuildCommand>"
  503. << cmXMLSafe(this->GetMakeCommand())
  504. << "</BuildCommand>" << std::endl;
  505. }
  506. //----------------------------------------------------------------------------
  507. class cmCTestBuildHandler::FragmentCompare
  508. {
  509. public:
  510. FragmentCompare(cmFileTimeComparison* ftc): FTC(ftc) {}
  511. FragmentCompare(): FTC(0) {}
  512. bool operator()(std::string const& l, std::string const& r)
  513. {
  514. // Order files by modification time. Use lexicographic order
  515. // among files with the same time.
  516. int result;
  517. if(this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
  518. result != 0)
  519. {
  520. return result < 0;
  521. }
  522. else
  523. {
  524. return l < r;
  525. }
  526. }
  527. private:
  528. cmFileTimeComparison* FTC;
  529. };
  530. //----------------------------------------------------------------------------
  531. void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os)
  532. {
  533. if(this->CTestLaunchDir.empty())
  534. {
  535. return;
  536. }
  537. // Sort XML fragments in chronological order.
  538. cmFileTimeComparison ftc;
  539. FragmentCompare fragmentCompare(&ftc);
  540. typedef std::set<cmStdString, FragmentCompare> Fragments;
  541. Fragments fragments(fragmentCompare);
  542. // Identify fragments on disk.
  543. cmsys::Directory launchDir;
  544. launchDir.Load(this->CTestLaunchDir.c_str());
  545. unsigned long n = launchDir.GetNumberOfFiles();
  546. for(unsigned long i=0; i < n; ++i)
  547. {
  548. const char* fname = launchDir.GetFile(i);
  549. if(this->IsLaunchedErrorFile(fname))
  550. {
  551. fragments.insert(this->CTestLaunchDir + "/" + fname);
  552. ++this->TotalErrors;
  553. }
  554. else if(this->IsLaunchedWarningFile(fname))
  555. {
  556. fragments.insert(this->CTestLaunchDir + "/" + fname);
  557. ++this->TotalWarnings;
  558. }
  559. }
  560. // Copy the fragments into the final XML file.
  561. for(Fragments::const_iterator fi = fragments.begin();
  562. fi != fragments.end(); ++fi)
  563. {
  564. this->GenerateXMLLaunchedFragment(os, fi->c_str());
  565. }
  566. }
  567. //----------------------------------------------------------------------------
  568. void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
  569. {
  570. std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
  571. std::vector<cmCTestBuildErrorWarning>::iterator it;
  572. // only report the first 50 warnings and first 50 errors
  573. int numErrorsAllowed = this->MaxErrors;
  574. int numWarningsAllowed = this->MaxWarnings;
  575. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  576. // make sure the source dir is in the correct case on windows
  577. // via a call to collapse full path.
  578. srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str());
  579. srcdir += "/";
  580. for ( it = ew.begin();
  581. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
  582. {
  583. cmCTestBuildErrorWarning *cm = &(*it);
  584. if ((cm->Error && numErrorsAllowed) ||
  585. (!cm->Error && numWarningsAllowed))
  586. {
  587. if (cm->Error)
  588. {
  589. numErrorsAllowed--;
  590. }
  591. else
  592. {
  593. numWarningsAllowed--;
  594. }
  595. os << "\t<" << (cm->Error ? "Error" : "Warning") << ">\n"
  596. << "\t\t<BuildLogLine>" << cm->LogLine << "</BuildLogLine>\n"
  597. << "\t\t<Text>" << cmXMLSafe(cm->Text).Quotes(false)
  598. << "\n</Text>" << std::endl;
  599. std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
  600. for ( rit = this->ErrorWarningFileLineRegex.begin();
  601. rit != this->ErrorWarningFileLineRegex.end(); ++ rit )
  602. {
  603. cmsys::RegularExpression* re = &rit->RegularExpression;
  604. if ( re->find(cm->Text.c_str() ) )
  605. {
  606. cm->SourceFile = re->match(rit->FileIndex);
  607. // At this point we need to make this->SourceFile relative to
  608. // the source root of the project, so cvs links will work
  609. cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
  610. if(cm->SourceFile.find("/.../") != cm->SourceFile.npos)
  611. {
  612. cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
  613. std::string::size_type p = cm->SourceFile.find("/");
  614. if(p != cm->SourceFile.npos)
  615. {
  616. cm->SourceFile = cm->SourceFile.substr(
  617. p+1, cm->SourceFile.size()-p);
  618. }
  619. }
  620. else
  621. {
  622. // make sure it is a full path with the correct case
  623. cm->SourceFile = cmSystemTools::CollapseFullPath(
  624. cm->SourceFile.c_str());
  625. cmSystemTools::ReplaceString(
  626. cm->SourceFile, srcdir.c_str(), "");
  627. }
  628. cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
  629. break;
  630. }
  631. }
  632. if ( !cm->SourceFile.empty() && cm->LineNumber >= 0 )
  633. {
  634. if ( cm->SourceFile.size() > 0 )
  635. {
  636. os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>"
  637. << std::endl;
  638. }
  639. if ( cm->SourceFileTail.size() > 0 )
  640. {
  641. os << "\t\t<SourceFileTail>" << cm->SourceFileTail
  642. << "</SourceFileTail>" << std::endl;
  643. }
  644. if ( cm->LineNumber >= 0 )
  645. {
  646. os << "\t\t<SourceLineNumber>" << cm->LineNumber
  647. << "</SourceLineNumber>" << std::endl;
  648. }
  649. }
  650. os << "\t\t<PreContext>" << cmXMLSafe(cm->PreContext).Quotes(false)
  651. << "</PreContext>\n"
  652. << "\t\t<PostContext>" << cmXMLSafe(cm->PostContext).Quotes(false);
  653. // is this the last warning or error, if so notify
  654. if ((cm->Error && !numErrorsAllowed) ||
  655. (!cm->Error && !numWarningsAllowed))
  656. {
  657. os << "\nThe maximum number of reported warnings or errors has been "
  658. "reached!!!\n";
  659. }
  660. os << "</PostContext>\n"
  661. << "\t\t<RepeatCount>0</RepeatCount>\n"
  662. << "</" << (cm->Error ? "Error" : "Warning") << ">\n\n"
  663. << std::endl;
  664. }
  665. }
  666. }
  667. //----------------------------------------------------------------------------
  668. void cmCTestBuildHandler::GenerateXMLFooter(std::ostream& os,
  669. double elapsed_build_time)
  670. {
  671. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  672. << "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n"
  673. << "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime)
  674. << "</EndBuildTime>\n"
  675. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  676. << "</ElapsedMinutes>"
  677. << "</Build>" << std::endl;
  678. this->CTest->EndXML(os);
  679. }
  680. //----------------------------------------------------------------------------
  681. void cmCTestBuildHandler::GenerateXMLLaunchedFragment(std::ostream& os,
  682. const char* fname)
  683. {
  684. std::ifstream fin(fname, std::ios::in | std::ios::binary);
  685. std::string line;
  686. while(cmSystemTools::GetLineFromStream(fin, line))
  687. {
  688. os << line << "\n";
  689. }
  690. }
  691. //----------------------------------------------------------------------------
  692. bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
  693. {
  694. // error-{hash}.xml
  695. return (strncmp(fname, "error-", 6) == 0 &&
  696. strcmp(fname+strlen(fname)-4, ".xml") == 0);
  697. }
  698. //----------------------------------------------------------------------------
  699. bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
  700. {
  701. // warning-{hash}.xml
  702. return (strncmp(fname, "warning-", 8) == 0 &&
  703. strcmp(fname+strlen(fname)-4, ".xml") == 0);
  704. }
  705. //######################################################################
  706. //######################################################################
  707. //######################################################################
  708. //######################################################################
  709. //----------------------------------------------------------------------------
  710. class cmCTestBuildHandler::LaunchHelper
  711. {
  712. public:
  713. LaunchHelper(cmCTestBuildHandler* handler);
  714. ~LaunchHelper();
  715. private:
  716. cmCTestBuildHandler* Handler;
  717. cmCTest* CTest;
  718. void WriteLauncherConfig();
  719. void WriteScrapeMatchers(const char* purpose,
  720. std::vector<std::string> const& matchers);
  721. };
  722. //----------------------------------------------------------------------------
  723. cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler):
  724. Handler(handler), CTest(handler->CTest)
  725. {
  726. std::string tag = this->CTest->GetCurrentTag();
  727. if(tag.empty())
  728. {
  729. // This is not for a dashboard submission, so there is no XML.
  730. // Skip enabling the launchers.
  731. this->Handler->UseCTestLaunch = false;
  732. }
  733. else
  734. {
  735. // Compute a directory in which to store launcher fragments.
  736. std::string& launchDir = this->Handler->CTestLaunchDir;
  737. launchDir = this->CTest->GetBinaryDir();
  738. launchDir += "/Testing/";
  739. launchDir += tag;
  740. launchDir += "/Build";
  741. // Clean out any existing launcher fragments.
  742. cmSystemTools::RemoveADirectory(launchDir.c_str());
  743. if(this->Handler->UseCTestLaunch)
  744. {
  745. // Enable launcher fragments.
  746. cmSystemTools::MakeDirectory(launchDir.c_str());
  747. this->WriteLauncherConfig();
  748. std::string launchEnv = "CTEST_LAUNCH_LOGS=";
  749. launchEnv += launchDir;
  750. cmSystemTools::PutEnv(launchEnv.c_str());
  751. }
  752. }
  753. // If not using launchers, make sure they passthru.
  754. if(!this->Handler->UseCTestLaunch)
  755. {
  756. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  757. }
  758. }
  759. //----------------------------------------------------------------------------
  760. cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
  761. {
  762. if(this->Handler->UseCTestLaunch)
  763. {
  764. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  765. }
  766. }
  767. //----------------------------------------------------------------------------
  768. void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
  769. {
  770. this->WriteScrapeMatchers("Warning",
  771. this->Handler->ReallyCustomWarningMatches);
  772. this->WriteScrapeMatchers("WarningSuppress",
  773. this->Handler->ReallyCustomWarningExceptions);
  774. // Give some testing configuration information to the launcher.
  775. std::string fname = this->Handler->CTestLaunchDir;
  776. fname += "/CTestLaunchConfig.cmake";
  777. cmGeneratedFileStream fout(fname.c_str());
  778. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  779. fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
  780. }
  781. //----------------------------------------------------------------------------
  782. void
  783. cmCTestBuildHandler::LaunchHelper
  784. ::WriteScrapeMatchers(const char* purpose,
  785. std::vector<std::string> const& matchers)
  786. {
  787. if(matchers.empty())
  788. {
  789. return;
  790. }
  791. std::string fname = this->Handler->CTestLaunchDir;
  792. fname += "/Custom";
  793. fname += purpose;
  794. fname += ".txt";
  795. cmGeneratedFileStream fout(fname.c_str());
  796. for(std::vector<std::string>::const_iterator mi = matchers.begin();
  797. mi != matchers.end(); ++mi)
  798. {
  799. fout << *mi << "\n";
  800. }
  801. }
  802. //----------------------------------------------------------------------
  803. int cmCTestBuildHandler::RunMakeCommand(const char* command,
  804. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  805. {
  806. // First generate the command and arguments
  807. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  808. if(args.size() < 1)
  809. {
  810. return false;
  811. }
  812. std::vector<const char*> argv;
  813. for(std::vector<cmStdString>::const_iterator a = args.begin();
  814. a != args.end(); ++a)
  815. {
  816. argv.push_back(a->c_str());
  817. }
  818. argv.push_back(0);
  819. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:");
  820. std::vector<const char*>::iterator ait;
  821. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  822. {
  823. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  824. }
  825. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  826. // Optionally use make rule launchers to record errors and warnings.
  827. LaunchHelper launchHelper(this);
  828. static_cast<void>(launchHelper);
  829. // Now create process object
  830. cmsysProcess* cp = cmsysProcess_New();
  831. cmsysProcess_SetCommand(cp, &*argv.begin());
  832. cmsysProcess_SetWorkingDirectory(cp, dir);
  833. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  834. cmsysProcess_SetTimeout(cp, timeout);
  835. cmsysProcess_Execute(cp);
  836. // Initialize tick's
  837. std::string::size_type tick = 0;
  838. const std::string::size_type tick_len = 1024;
  839. char* data;
  840. int length;
  841. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  842. " Each symbol represents " << tick_len << " bytes of output."
  843. << std::endl
  844. << (this->UseCTestLaunch? "" :
  845. " '!' represents an error and '*' a warning.\n")
  846. << " " << std::flush);
  847. // Initialize building structures
  848. this->BuildProcessingQueue.clear();
  849. this->OutputLineCounter = 0;
  850. this->ErrorsAndWarnings.clear();
  851. this->TotalErrors = 0;
  852. this->TotalWarnings = 0;
  853. this->BuildOutputLogSize = 0;
  854. this->LastTickChar = '.';
  855. this->WarningQuotaReached = false;
  856. this->ErrorQuotaReached = false;
  857. // For every chunk of data
  858. int res;
  859. while((res = cmsysProcess_WaitForData(cp, &data, &length, 0)))
  860. {
  861. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  862. // for Visual Studio output
  863. for(int cc =0; cc < length; ++cc)
  864. {
  865. if(data[cc] == 0)
  866. {
  867. data[cc] = '\n';
  868. }
  869. }
  870. // Process the chunk of data
  871. if ( res == cmsysProcess_Pipe_STDERR )
  872. {
  873. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  874. &this->BuildProcessingErrorQueue);
  875. }
  876. else
  877. {
  878. this->ProcessBuffer(data, length, tick, tick_len, ofs,
  879. &this->BuildProcessingQueue);
  880. }
  881. }
  882. this->ProcessBuffer(0, 0, tick, tick_len, ofs, &this->BuildProcessingQueue);
  883. this->ProcessBuffer(0, 0, tick, tick_len, ofs,
  884. &this->BuildProcessingErrorQueue);
  885. cmCTestLog(this->CTest, OUTPUT, " Size of output: "
  886. << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl);
  887. // Properly handle output of the build command
  888. cmsysProcess_WaitForExit(cp, 0);
  889. int result = cmsysProcess_GetState(cp);
  890. if(result == cmsysProcess_State_Exited)
  891. {
  892. if (retVal)
  893. {
  894. *retVal = cmsysProcess_GetExitValue(cp);
  895. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  896. "Command exited with the value: " << *retVal << std::endl);
  897. // if a non zero return value
  898. if (*retVal)
  899. {
  900. // If there was an error running command, report that on the
  901. // dashboard.
  902. cmCTestBuildErrorWarning errorwarning;
  903. errorwarning.LogLine = 1;
  904. errorwarning.Text
  905. = "*** WARNING non-zero return value in ctest from: ";
  906. errorwarning.Text += argv[0];
  907. errorwarning.PreContext = "";
  908. errorwarning.PostContext = "";
  909. errorwarning.Error = false;
  910. this->ErrorsAndWarnings.push_back(errorwarning);
  911. this->TotalWarnings ++;
  912. }
  913. }
  914. }
  915. else if(result == cmsysProcess_State_Exception)
  916. {
  917. if (retVal)
  918. {
  919. *retVal = cmsysProcess_GetExitException(cp);
  920. cmCTestLog(this->CTest, WARNING, "There was an exception: " << *retVal
  921. << std::endl);
  922. }
  923. }
  924. else if(result == cmsysProcess_State_Expired)
  925. {
  926. cmCTestLog(this->CTest, WARNING, "There was a timeout" << std::endl);
  927. }
  928. else if(result == cmsysProcess_State_Error)
  929. {
  930. // If there was an error running command, report that on the dashboard.
  931. cmCTestBuildErrorWarning errorwarning;
  932. errorwarning.LogLine = 1;
  933. errorwarning.Text = "*** ERROR executing: ";
  934. errorwarning.Text += cmsysProcess_GetErrorString(cp);
  935. errorwarning.PreContext = "";
  936. errorwarning.PostContext = "";
  937. errorwarning.Error = true;
  938. this->ErrorsAndWarnings.push_back(errorwarning);
  939. this->TotalErrors ++;
  940. cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
  941. << cmsysProcess_GetErrorString(cp) << std::endl);
  942. }
  943. cmsysProcess_Delete(cp);
  944. return result;
  945. }
  946. //######################################################################
  947. //######################################################################
  948. //######################################################################
  949. //######################################################################
  950. //----------------------------------------------------------------------
  951. void cmCTestBuildHandler::ProcessBuffer(const char* data, int length,
  952. size_t& tick, size_t tick_len, std::ofstream& ofs,
  953. t_BuildProcessingQueueType* queue)
  954. {
  955. const std::string::size_type tick_line_len = 50;
  956. const char* ptr;
  957. for ( ptr = data; ptr < data+length; ptr ++ )
  958. {
  959. queue->push_back(*ptr);
  960. }
  961. this->BuildOutputLogSize += length;
  962. // until there are any lines left in the buffer
  963. while ( 1 )
  964. {
  965. // Find the end of line
  966. t_BuildProcessingQueueType::iterator it;
  967. for ( it = queue->begin();
  968. it != queue->end();
  969. ++ it )
  970. {
  971. if ( *it == '\n' )
  972. {
  973. break;
  974. }
  975. }
  976. // Once certain number of errors or warnings reached, ignore future errors
  977. // or warnings.
  978. if ( this->TotalWarnings >= this->MaxWarnings )
  979. {
  980. this->WarningQuotaReached = true;
  981. }
  982. if ( this->TotalErrors >= this->MaxErrors )
  983. {
  984. this->ErrorQuotaReached = true;
  985. }
  986. // If the end of line was found
  987. if ( it != queue->end() )
  988. {
  989. // Create a contiguous array for the line
  990. this->CurrentProcessingLine.clear();
  991. t_BuildProcessingQueueType::iterator cit;
  992. for ( cit = queue->begin(); cit != it; ++cit )
  993. {
  994. this->CurrentProcessingLine.push_back(*cit);
  995. }
  996. this->CurrentProcessingLine.push_back(0);
  997. const char* line = &*this->CurrentProcessingLine.begin();
  998. // Process the line
  999. int lineType = this->ProcessSingleLine(line);
  1000. // Erase the line from the queue
  1001. queue->erase(queue->begin(), it+1);
  1002. // Depending on the line type, produce error or warning, or nothing
  1003. cmCTestBuildErrorWarning errorwarning;
  1004. bool found = false;
  1005. switch ( lineType )
  1006. {
  1007. case b_WARNING_LINE:
  1008. this->LastTickChar = '*';
  1009. errorwarning.Error = false;
  1010. found = true;
  1011. this->TotalWarnings ++;
  1012. break;
  1013. case b_ERROR_LINE:
  1014. this->LastTickChar = '!';
  1015. errorwarning.Error = true;
  1016. found = true;
  1017. this->TotalErrors ++;
  1018. break;
  1019. }
  1020. if ( found )
  1021. {
  1022. // This is an error or warning, so generate report
  1023. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter+1);
  1024. errorwarning.Text = line;
  1025. errorwarning.PreContext = "";
  1026. errorwarning.PostContext = "";
  1027. // Copy pre-context to report
  1028. std::deque<cmStdString>::iterator pcit;
  1029. for ( pcit = this->PreContext.begin();
  1030. pcit != this->PreContext.end();
  1031. ++pcit )
  1032. {
  1033. errorwarning.PreContext += *pcit + "\n";
  1034. }
  1035. this->PreContext.clear();
  1036. // Store report
  1037. this->ErrorsAndWarnings.push_back(errorwarning);
  1038. this->LastErrorOrWarning = this->ErrorsAndWarnings.end()-1;
  1039. this->PostContextCount = 0;
  1040. }
  1041. else
  1042. {
  1043. // This is not an error or warning.
  1044. // So, figure out if this is a post-context line
  1045. if ( this->ErrorsAndWarnings.size() &&
  1046. this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  1047. this->PostContextCount < this->MaxPostContext )
  1048. {
  1049. this->PostContextCount ++;
  1050. this->LastErrorOrWarning->PostContext += line;
  1051. if ( this->PostContextCount < this->MaxPostContext )
  1052. {
  1053. this->LastErrorOrWarning->PostContext += "\n";
  1054. }
  1055. }
  1056. else
  1057. {
  1058. // Otherwise store pre-context for the next error
  1059. this->PreContext.push_back(line);
  1060. if ( this->PreContext.size() > this->MaxPreContext )
  1061. {
  1062. this->PreContext.erase(this->PreContext.begin(),
  1063. this->PreContext.end()-this->MaxPreContext);
  1064. }
  1065. }
  1066. }
  1067. this->OutputLineCounter ++;
  1068. }
  1069. else
  1070. {
  1071. break;
  1072. }
  1073. }
  1074. // Now that the buffer is processed, display missing ticks
  1075. int tickDisplayed = false;
  1076. while ( this->BuildOutputLogSize > (tick * tick_len) )
  1077. {
  1078. tick ++;
  1079. cmCTestLog(this->CTest, HANDLER_OUTPUT, this->LastTickChar);
  1080. tickDisplayed = true;
  1081. if ( tick % tick_line_len == 0 && tick > 0 )
  1082. {
  1083. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Size: "
  1084. << ((this->BuildOutputLogSize + 512) / 1024) << "K" << std::endl
  1085. << " ");
  1086. }
  1087. }
  1088. if ( tickDisplayed )
  1089. {
  1090. this->LastTickChar = '.';
  1091. }
  1092. // And if this is verbose output, display the content of the chunk
  1093. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1094. cmCTestLogWrite(data, length));
  1095. // Always store the chunk to the file
  1096. ofs << cmCTestLogWrite(data, length);
  1097. }
  1098. //----------------------------------------------------------------------
  1099. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  1100. {
  1101. if(this->UseCTestLaunch)
  1102. {
  1103. // No log scraping when using launchers.
  1104. return b_REGULAR_LINE;
  1105. }
  1106. cmCTestLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl);
  1107. std::vector<cmsys::RegularExpression>::iterator it;
  1108. int warningLine = 0;
  1109. int errorLine = 0;
  1110. // Check for regular expressions
  1111. if ( !this->ErrorQuotaReached )
  1112. {
  1113. // Errors
  1114. int wrxCnt = 0;
  1115. for ( it = this->ErrorMatchRegex.begin();
  1116. it != this->ErrorMatchRegex.end();
  1117. ++ it )
  1118. {
  1119. if ( it->find(data) )
  1120. {
  1121. errorLine = 1;
  1122. cmCTestLog(this->CTest, DEBUG, " Error Line: " << data
  1123. << " (matches: " << this->CustomErrorMatches[wrxCnt] << ")"
  1124. << std::endl);
  1125. break;
  1126. }
  1127. wrxCnt ++;
  1128. }
  1129. // Error exceptions
  1130. wrxCnt = 0;
  1131. for ( it = this->ErrorExceptionRegex.begin();
  1132. it != this->ErrorExceptionRegex.end();
  1133. ++ it )
  1134. {
  1135. if ( it->find(data) )
  1136. {
  1137. errorLine = 0;
  1138. cmCTestLog(this->CTest, DEBUG, " Not an error Line: " << data
  1139. << " (matches: " << this->CustomErrorExceptions[wrxCnt] << ")"
  1140. << std::endl);
  1141. break;
  1142. }
  1143. wrxCnt ++;
  1144. }
  1145. }
  1146. if ( !this->WarningQuotaReached )
  1147. {
  1148. // Warnings
  1149. int wrxCnt = 0;
  1150. for ( it = this->WarningMatchRegex.begin();
  1151. it != this->WarningMatchRegex.end();
  1152. ++ it )
  1153. {
  1154. if ( it->find(data) )
  1155. {
  1156. warningLine = 1;
  1157. cmCTestLog(this->CTest, DEBUG,
  1158. " Warning Line: " << data
  1159. << " (matches: " << this->CustomWarningMatches[wrxCnt] << ")"
  1160. << std::endl);
  1161. break;
  1162. }
  1163. wrxCnt ++;
  1164. }
  1165. wrxCnt = 0;
  1166. // Warning exceptions
  1167. for ( it = this->WarningExceptionRegex.begin();
  1168. it != this->WarningExceptionRegex.end();
  1169. ++ it )
  1170. {
  1171. if ( it->find(data) )
  1172. {
  1173. warningLine = 0;
  1174. cmCTestLog(this->CTest, DEBUG, " Not a warning Line: " << data
  1175. << " (matches: " << this->CustomWarningExceptions[wrxCnt] << ")"
  1176. << std::endl);
  1177. break;
  1178. }
  1179. wrxCnt ++;
  1180. }
  1181. }
  1182. if ( errorLine )
  1183. {
  1184. return b_ERROR_LINE;
  1185. }
  1186. if ( warningLine )
  1187. {
  1188. return b_WARNING_LINE;
  1189. }
  1190. return b_REGULAR_LINE;
  1191. }