cmCTestBuildHandler.cxx 40 KB

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