cmCTestBuildHandler.cxx 40 KB

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