cmCTestBuildHandler.cxx 40 KB

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