cmCTestBuildHandler.cxx 40 KB

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