cmCTestBuildHandler.cxx 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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. this->CTest->GenerateSubprojectsOutput(xml);
  443. xml.StartElement("Build");
  444. xml.Element("StartDateTime", this->StartBuild);
  445. xml.Element("StartBuildTime",
  446. static_cast<unsigned int>(this->StartBuildTime));
  447. xml.Element("BuildCommand", this->GetMakeCommand());
  448. }
  449. class cmCTestBuildHandler::FragmentCompare
  450. {
  451. public:
  452. FragmentCompare(cmFileTimeComparison* ftc)
  453. : FTC(ftc)
  454. {
  455. }
  456. FragmentCompare()
  457. : FTC(CM_NULLPTR)
  458. {
  459. }
  460. bool operator()(std::string const& l, std::string const& r) const
  461. {
  462. // Order files by modification time. Use lexicographic order
  463. // among files with the same time.
  464. int result;
  465. if (this->FTC->FileTimeCompare(l.c_str(), r.c_str(), &result) &&
  466. result != 0) {
  467. return result < 0;
  468. }
  469. return l < r;
  470. }
  471. private:
  472. cmFileTimeComparison* FTC;
  473. };
  474. void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
  475. {
  476. if (this->CTestLaunchDir.empty()) {
  477. return;
  478. }
  479. // Sort XML fragments in chronological order.
  480. cmFileTimeComparison ftc;
  481. FragmentCompare fragmentCompare(&ftc);
  482. typedef std::set<std::string, FragmentCompare> Fragments;
  483. Fragments fragments(fragmentCompare);
  484. // only report the first 50 warnings and first 50 errors
  485. int numErrorsAllowed = this->MaxErrors;
  486. int numWarningsAllowed = this->MaxWarnings;
  487. // Identify fragments on disk.
  488. cmsys::Directory launchDir;
  489. launchDir.Load(this->CTestLaunchDir);
  490. unsigned long n = launchDir.GetNumberOfFiles();
  491. for (unsigned long i = 0; i < n; ++i) {
  492. const char* fname = launchDir.GetFile(i);
  493. if (this->IsLaunchedErrorFile(fname) && numErrorsAllowed) {
  494. numErrorsAllowed--;
  495. fragments.insert(this->CTestLaunchDir + "/" + fname);
  496. ++this->TotalErrors;
  497. } else if (this->IsLaunchedWarningFile(fname) && numWarningsAllowed) {
  498. numWarningsAllowed--;
  499. fragments.insert(this->CTestLaunchDir + "/" + fname);
  500. ++this->TotalWarnings;
  501. }
  502. }
  503. // Copy the fragments into the final XML file.
  504. for (Fragments::const_iterator fi = fragments.begin(); fi != fragments.end();
  505. ++fi) {
  506. xml.FragmentFile(fi->c_str());
  507. }
  508. }
  509. void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
  510. {
  511. std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
  512. std::vector<cmCTestBuildErrorWarning>::iterator it;
  513. // only report the first 50 warnings and first 50 errors
  514. int numErrorsAllowed = this->MaxErrors;
  515. int numWarningsAllowed = this->MaxWarnings;
  516. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  517. // make sure the source dir is in the correct case on windows
  518. // via a call to collapse full path.
  519. srcdir = cmSystemTools::CollapseFullPath(srcdir);
  520. srcdir += "/";
  521. for (it = ew.begin();
  522. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++) {
  523. cmCTestBuildErrorWarning* cm = &(*it);
  524. if ((cm->Error && numErrorsAllowed) ||
  525. (!cm->Error && numWarningsAllowed)) {
  526. if (cm->Error) {
  527. numErrorsAllowed--;
  528. } else {
  529. numWarningsAllowed--;
  530. }
  531. xml.StartElement(cm->Error ? "Error" : "Warning");
  532. xml.Element("BuildLogLine", cm->LogLine);
  533. xml.Element("Text", cm->Text);
  534. std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
  535. for (rit = this->ErrorWarningFileLineRegex.begin();
  536. rit != this->ErrorWarningFileLineRegex.end(); ++rit) {
  537. cmsys::RegularExpression* re = &rit->RegularExpression;
  538. if (re->find(cm->Text.c_str())) {
  539. cm->SourceFile = re->match(rit->FileIndex);
  540. // At this point we need to make this->SourceFile relative to
  541. // the source root of the project, so cvs links will work
  542. cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
  543. if (cm->SourceFile.find("/.../") != std::string::npos) {
  544. cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
  545. std::string::size_type p = cm->SourceFile.find('/');
  546. if (p != std::string::npos) {
  547. cm->SourceFile =
  548. cm->SourceFile.substr(p + 1, cm->SourceFile.size() - p);
  549. }
  550. } else {
  551. // make sure it is a full path with the correct case
  552. cm->SourceFile = cmSystemTools::CollapseFullPath(cm->SourceFile);
  553. cmSystemTools::ReplaceString(cm->SourceFile, srcdir.c_str(), "");
  554. }
  555. cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
  556. break;
  557. }
  558. }
  559. if (!cm->SourceFile.empty() && cm->LineNumber >= 0) {
  560. if (!cm->SourceFile.empty()) {
  561. xml.Element("SourceFile", cm->SourceFile);
  562. }
  563. if (!cm->SourceFileTail.empty()) {
  564. xml.Element("SourceFileTail", cm->SourceFileTail);
  565. }
  566. if (cm->LineNumber >= 0) {
  567. xml.Element("SourceLineNumber", cm->LineNumber);
  568. }
  569. }
  570. xml.Element("PreContext", cm->PreContext);
  571. xml.StartElement("PostContext");
  572. xml.Content(cm->PostContext);
  573. // is this the last warning or error, if so notify
  574. if ((cm->Error && !numErrorsAllowed) ||
  575. (!cm->Error && !numWarningsAllowed)) {
  576. xml.Content("\nThe maximum number of reported warnings or errors "
  577. "has been reached!!!\n");
  578. }
  579. xml.EndElement(); // PostContext
  580. xml.Element("RepeatCount", "0");
  581. xml.EndElement(); // "Error" / "Warning"
  582. }
  583. }
  584. }
  585. void cmCTestBuildHandler::GenerateXMLFooter(cmXMLWriter& xml,
  586. double elapsed_build_time)
  587. {
  588. xml.StartElement("Log");
  589. xml.Attribute("Encoding", "base64");
  590. xml.Attribute("Compression", "bin/gzip");
  591. xml.EndElement(); // Log
  592. xml.Element("EndDateTime", this->EndBuild);
  593. xml.Element("EndBuildTime", static_cast<unsigned int>(this->EndBuildTime));
  594. xml.Element("ElapsedMinutes",
  595. static_cast<int>(elapsed_build_time / 6) / 10.0);
  596. xml.EndElement(); // Build
  597. this->CTest->EndXML(xml);
  598. }
  599. bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
  600. {
  601. // error-{hash}.xml
  602. return (cmHasLiteralPrefix(fname, "error-") &&
  603. strcmp(fname + strlen(fname) - 4, ".xml") == 0);
  604. }
  605. bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
  606. {
  607. // warning-{hash}.xml
  608. return (cmHasLiteralPrefix(fname, "warning-") &&
  609. strcmp(fname + strlen(fname) - 4, ".xml") == 0);
  610. }
  611. //######################################################################
  612. //######################################################################
  613. //######################################################################
  614. //######################################################################
  615. class cmCTestBuildHandler::LaunchHelper
  616. {
  617. public:
  618. LaunchHelper(cmCTestBuildHandler* handler);
  619. ~LaunchHelper();
  620. private:
  621. cmCTestBuildHandler* Handler;
  622. cmCTest* CTest;
  623. void WriteLauncherConfig();
  624. void WriteScrapeMatchers(const char* purpose,
  625. std::vector<std::string> const& matchers);
  626. };
  627. cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler)
  628. : Handler(handler)
  629. , CTest(handler->CTest)
  630. {
  631. std::string tag = this->CTest->GetCurrentTag();
  632. if (tag.empty()) {
  633. // This is not for a dashboard submission, so there is no XML.
  634. // Skip enabling the launchers.
  635. this->Handler->UseCTestLaunch = false;
  636. } else {
  637. // Compute a directory in which to store launcher fragments.
  638. std::string& launchDir = this->Handler->CTestLaunchDir;
  639. launchDir = this->CTest->GetBinaryDir();
  640. launchDir += "/Testing/";
  641. launchDir += tag;
  642. launchDir += "/Build";
  643. // Clean out any existing launcher fragments.
  644. cmSystemTools::RemoveADirectory(launchDir);
  645. if (this->Handler->UseCTestLaunch) {
  646. // Enable launcher fragments.
  647. cmSystemTools::MakeDirectory(launchDir.c_str());
  648. this->WriteLauncherConfig();
  649. std::string launchEnv = "CTEST_LAUNCH_LOGS=";
  650. launchEnv += launchDir;
  651. cmSystemTools::PutEnv(launchEnv);
  652. }
  653. }
  654. // If not using launchers, make sure they passthru.
  655. if (!this->Handler->UseCTestLaunch) {
  656. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  657. }
  658. }
  659. cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
  660. {
  661. if (this->Handler->UseCTestLaunch) {
  662. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  663. }
  664. }
  665. void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
  666. {
  667. this->WriteScrapeMatchers("Warning",
  668. this->Handler->ReallyCustomWarningMatches);
  669. this->WriteScrapeMatchers("WarningSuppress",
  670. this->Handler->ReallyCustomWarningExceptions);
  671. // Give some testing configuration information to the launcher.
  672. std::string fname = this->Handler->CTestLaunchDir;
  673. fname += "/CTestLaunchConfig.cmake";
  674. cmGeneratedFileStream fout(fname.c_str());
  675. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  676. fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
  677. }
  678. void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers(
  679. const char* purpose, std::vector<std::string> const& matchers)
  680. {
  681. if (matchers.empty()) {
  682. return;
  683. }
  684. std::string fname = this->Handler->CTestLaunchDir;
  685. fname += "/Custom";
  686. fname += purpose;
  687. fname += ".txt";
  688. cmGeneratedFileStream fout(fname.c_str());
  689. for (std::vector<std::string>::const_iterator mi = matchers.begin();
  690. mi != matchers.end(); ++mi) {
  691. fout << *mi << "\n";
  692. }
  693. }
  694. int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
  695. const char* dir, int timeout,
  696. std::ostream& ofs, Encoding encoding)
  697. {
  698. // First generate the command and arguments
  699. std::vector<std::string> args = cmSystemTools::ParseArguments(command);
  700. if (args.empty()) {
  701. return false;
  702. }
  703. std::vector<const char*> argv;
  704. for (std::vector<std::string>::const_iterator a = args.begin();
  705. a != args.end(); ++a) {
  706. argv.push_back(a->c_str());
  707. }
  708. argv.push_back(CM_NULLPTR);
  709. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:",
  710. this->Quiet);
  711. std::vector<const char*>::iterator ait;
  712. for (ait = argv.begin(); ait != argv.end() && *ait; ++ait) {
  713. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  714. " \"" << *ait << "\"", this->Quiet);
  715. }
  716. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
  717. this->Quiet);
  718. // Optionally use make rule launchers to record errors and warnings.
  719. LaunchHelper launchHelper(this);
  720. static_cast<void>(launchHelper);
  721. // Now create process object
  722. cmsysProcess* cp = cmsysProcess_New();
  723. cmsysProcess_SetCommand(cp, &*argv.begin());
  724. cmsysProcess_SetWorkingDirectory(cp, dir);
  725. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  726. cmsysProcess_SetTimeout(cp, timeout);
  727. cmsysProcess_Execute(cp);
  728. // Initialize tick's
  729. std::string::size_type tick = 0;
  730. const std::string::size_type tick_len = 1024;
  731. char* data;
  732. int length;
  733. cmProcessOutput processOutput(encoding);
  734. std::string strdata;
  735. cmCTestOptionalLog(
  736. this->CTest, HANDLER_PROGRESS_OUTPUT, " Each symbol represents "
  737. << tick_len << " bytes of output." << std::endl
  738. << (this->UseCTestLaunch
  739. ? ""
  740. : " '!' represents an error and '*' a warning.\n")
  741. << " " << std::flush,
  742. this->Quiet);
  743. // Initialize building structures
  744. this->BuildProcessingQueue.clear();
  745. this->OutputLineCounter = 0;
  746. this->ErrorsAndWarnings.clear();
  747. this->TotalErrors = 0;
  748. this->TotalWarnings = 0;
  749. this->BuildOutputLogSize = 0;
  750. this->LastTickChar = '.';
  751. this->WarningQuotaReached = false;
  752. this->ErrorQuotaReached = false;
  753. // For every chunk of data
  754. int res;
  755. while ((res = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR))) {
  756. // Replace '\0' with '\n', since '\0' does not really make sense. This is
  757. // for Visual Studio output
  758. for (int cc = 0; cc < length; ++cc) {
  759. if (data[cc] == 0) {
  760. data[cc] = '\n';
  761. }
  762. }
  763. // Process the chunk of data
  764. if (res == cmsysProcess_Pipe_STDERR) {
  765. processOutput.DecodeText(data, length, strdata, 1);
  766. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len, ofs,
  767. &this->BuildProcessingErrorQueue);
  768. } else {
  769. processOutput.DecodeText(data, length, strdata, 2);
  770. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len, ofs,
  771. &this->BuildProcessingQueue);
  772. }
  773. }
  774. processOutput.DecodeText(std::string(), strdata, 1);
  775. if (!strdata.empty()) {
  776. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len, ofs,
  777. &this->BuildProcessingErrorQueue);
  778. }
  779. processOutput.DecodeText(std::string(), strdata, 2);
  780. if (!strdata.empty()) {
  781. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len, ofs,
  782. &this->BuildProcessingQueue);
  783. }
  784. this->ProcessBuffer(CM_NULLPTR, 0, tick, tick_len, ofs,
  785. &this->BuildProcessingQueue);
  786. this->ProcessBuffer(CM_NULLPTR, 0, tick, tick_len, ofs,
  787. &this->BuildProcessingErrorQueue);
  788. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, " Size of output: "
  789. << ((this->BuildOutputLogSize + 512) / 1024) << "K"
  790. << std::endl,
  791. this->Quiet);
  792. // Properly handle output of the build command
  793. cmsysProcess_WaitForExit(cp, CM_NULLPTR);
  794. int result = cmsysProcess_GetState(cp);
  795. if (result == cmsysProcess_State_Exited) {
  796. if (retVal) {
  797. *retVal = cmsysProcess_GetExitValue(cp);
  798. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  799. "Command exited with the value: " << *retVal
  800. << std::endl,
  801. this->Quiet);
  802. // if a non zero return value
  803. if (*retVal) {
  804. // If there was an error running command, report that on the
  805. // dashboard.
  806. cmCTestBuildErrorWarning errorwarning;
  807. errorwarning.LogLine = 1;
  808. errorwarning.Text =
  809. "*** WARNING non-zero return value in ctest from: ";
  810. errorwarning.Text += argv[0];
  811. errorwarning.PreContext = "";
  812. errorwarning.PostContext = "";
  813. errorwarning.Error = false;
  814. this->ErrorsAndWarnings.push_back(errorwarning);
  815. this->TotalWarnings++;
  816. }
  817. }
  818. } else if (result == cmsysProcess_State_Exception) {
  819. if (retVal) {
  820. *retVal = cmsysProcess_GetExitException(cp);
  821. cmCTestOptionalLog(this->CTest, WARNING,
  822. "There was an exception: " << *retVal << std::endl,
  823. this->Quiet);
  824. }
  825. } else if (result == cmsysProcess_State_Expired) {
  826. cmCTestOptionalLog(this->CTest, WARNING,
  827. "There was a timeout" << std::endl, this->Quiet);
  828. } else if (result == cmsysProcess_State_Error) {
  829. // If there was an error running command, report that on the dashboard.
  830. cmCTestBuildErrorWarning errorwarning;
  831. errorwarning.LogLine = 1;
  832. errorwarning.Text = "*** ERROR executing: ";
  833. errorwarning.Text += cmsysProcess_GetErrorString(cp);
  834. errorwarning.PreContext = "";
  835. errorwarning.PostContext = "";
  836. errorwarning.Error = true;
  837. this->ErrorsAndWarnings.push_back(errorwarning);
  838. this->TotalErrors++;
  839. cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
  840. << cmsysProcess_GetErrorString(cp) << std::endl);
  841. }
  842. cmsysProcess_Delete(cp);
  843. return result;
  844. }
  845. //######################################################################
  846. //######################################################################
  847. //######################################################################
  848. //######################################################################
  849. void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
  850. size_t& tick, size_t tick_len,
  851. std::ostream& ofs,
  852. t_BuildProcessingQueueType* queue)
  853. {
  854. const std::string::size_type tick_line_len = 50;
  855. const char* ptr;
  856. for (ptr = data; ptr < data + length; ptr++) {
  857. queue->push_back(*ptr);
  858. }
  859. this->BuildOutputLogSize += length;
  860. // until there are any lines left in the buffer
  861. while (true) {
  862. // Find the end of line
  863. t_BuildProcessingQueueType::iterator it;
  864. for (it = queue->begin(); it != queue->end(); ++it) {
  865. if (*it == '\n') {
  866. break;
  867. }
  868. }
  869. // Once certain number of errors or warnings reached, ignore future errors
  870. // or warnings.
  871. if (this->TotalWarnings >= this->MaxWarnings) {
  872. this->WarningQuotaReached = true;
  873. }
  874. if (this->TotalErrors >= this->MaxErrors) {
  875. this->ErrorQuotaReached = true;
  876. }
  877. // If the end of line was found
  878. if (it != queue->end()) {
  879. // Create a contiguous array for the line
  880. this->CurrentProcessingLine.clear();
  881. this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(),
  882. queue->begin(), it);
  883. this->CurrentProcessingLine.push_back(0);
  884. const char* line = &*this->CurrentProcessingLine.begin();
  885. // Process the line
  886. int lineType = this->ProcessSingleLine(line);
  887. // Erase the line from the queue
  888. queue->erase(queue->begin(), it + 1);
  889. // Depending on the line type, produce error or warning, or nothing
  890. cmCTestBuildErrorWarning errorwarning;
  891. bool found = false;
  892. switch (lineType) {
  893. case b_WARNING_LINE:
  894. this->LastTickChar = '*';
  895. errorwarning.Error = false;
  896. found = true;
  897. this->TotalWarnings++;
  898. break;
  899. case b_ERROR_LINE:
  900. this->LastTickChar = '!';
  901. errorwarning.Error = true;
  902. found = true;
  903. this->TotalErrors++;
  904. break;
  905. }
  906. if (found) {
  907. // This is an error or warning, so generate report
  908. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter + 1);
  909. errorwarning.Text = line;
  910. errorwarning.PreContext = "";
  911. errorwarning.PostContext = "";
  912. // Copy pre-context to report
  913. std::deque<std::string>::iterator pcit;
  914. for (pcit = this->PreContext.begin(); pcit != this->PreContext.end();
  915. ++pcit) {
  916. errorwarning.PreContext += *pcit + "\n";
  917. }
  918. this->PreContext.clear();
  919. // Store report
  920. this->ErrorsAndWarnings.push_back(errorwarning);
  921. this->LastErrorOrWarning = this->ErrorsAndWarnings.end() - 1;
  922. this->PostContextCount = 0;
  923. } else {
  924. // This is not an error or warning.
  925. // So, figure out if this is a post-context line
  926. if (!this->ErrorsAndWarnings.empty() &&
  927. this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  928. this->PostContextCount < this->MaxPostContext) {
  929. this->PostContextCount++;
  930. this->LastErrorOrWarning->PostContext += line;
  931. if (this->PostContextCount < this->MaxPostContext) {
  932. this->LastErrorOrWarning->PostContext += "\n";
  933. }
  934. } else {
  935. // Otherwise store pre-context for the next error
  936. this->PreContext.push_back(line);
  937. if (this->PreContext.size() > this->MaxPreContext) {
  938. this->PreContext.erase(this->PreContext.begin(),
  939. this->PreContext.end() -
  940. this->MaxPreContext);
  941. }
  942. }
  943. }
  944. this->OutputLineCounter++;
  945. } else {
  946. break;
  947. }
  948. }
  949. // Now that the buffer is processed, display missing ticks
  950. int tickDisplayed = false;
  951. while (this->BuildOutputLogSize > (tick * tick_len)) {
  952. tick++;
  953. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
  954. this->LastTickChar, this->Quiet);
  955. tickDisplayed = true;
  956. if (tick % tick_line_len == 0 && tick > 0) {
  957. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, " Size: "
  958. << ((this->BuildOutputLogSize + 512) / 1024) << "K"
  959. << std::endl
  960. << " ",
  961. this->Quiet);
  962. }
  963. }
  964. if (tickDisplayed) {
  965. this->LastTickChar = '.';
  966. }
  967. // And if this is verbose output, display the content of the chunk
  968. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  969. cmCTestLogWrite(data, length));
  970. // Always store the chunk to the file
  971. ofs << cmCTestLogWrite(data, length);
  972. }
  973. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  974. {
  975. if (this->UseCTestLaunch) {
  976. // No log scraping when using launchers.
  977. return b_REGULAR_LINE;
  978. }
  979. cmCTestOptionalLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl,
  980. this->Quiet);
  981. std::vector<cmsys::RegularExpression>::iterator it;
  982. int warningLine = 0;
  983. int errorLine = 0;
  984. // Check for regular expressions
  985. if (!this->ErrorQuotaReached) {
  986. // Errors
  987. int wrxCnt = 0;
  988. for (it = this->ErrorMatchRegex.begin(); it != this->ErrorMatchRegex.end();
  989. ++it) {
  990. if (it->find(data)) {
  991. errorLine = 1;
  992. cmCTestOptionalLog(this->CTest, DEBUG,
  993. " Error Line: " << data << " (matches: "
  994. << this->CustomErrorMatches[wrxCnt]
  995. << ")" << std::endl,
  996. this->Quiet);
  997. break;
  998. }
  999. wrxCnt++;
  1000. }
  1001. // Error exceptions
  1002. wrxCnt = 0;
  1003. for (it = this->ErrorExceptionRegex.begin();
  1004. it != this->ErrorExceptionRegex.end(); ++it) {
  1005. if (it->find(data)) {
  1006. errorLine = 0;
  1007. cmCTestOptionalLog(this->CTest, DEBUG, " Not an error Line: "
  1008. << data << " (matches: "
  1009. << this->CustomErrorExceptions[wrxCnt] << ")"
  1010. << std::endl,
  1011. this->Quiet);
  1012. break;
  1013. }
  1014. wrxCnt++;
  1015. }
  1016. }
  1017. if (!this->WarningQuotaReached) {
  1018. // Warnings
  1019. int wrxCnt = 0;
  1020. for (it = this->WarningMatchRegex.begin();
  1021. it != this->WarningMatchRegex.end(); ++it) {
  1022. if (it->find(data)) {
  1023. warningLine = 1;
  1024. cmCTestOptionalLog(this->CTest, DEBUG, " Warning Line: "
  1025. << data << " (matches: "
  1026. << this->CustomWarningMatches[wrxCnt] << ")"
  1027. << std::endl,
  1028. this->Quiet);
  1029. break;
  1030. }
  1031. wrxCnt++;
  1032. }
  1033. wrxCnt = 0;
  1034. // Warning exceptions
  1035. for (it = this->WarningExceptionRegex.begin();
  1036. it != this->WarningExceptionRegex.end(); ++it) {
  1037. if (it->find(data)) {
  1038. warningLine = 0;
  1039. cmCTestOptionalLog(this->CTest, DEBUG, " Not a warning Line: "
  1040. << data << " (matches: "
  1041. << this->CustomWarningExceptions[wrxCnt] << ")"
  1042. << std::endl,
  1043. this->Quiet);
  1044. break;
  1045. }
  1046. wrxCnt++;
  1047. }
  1048. }
  1049. if (errorLine) {
  1050. return b_ERROR_LINE;
  1051. }
  1052. if (warningLine) {
  1053. return b_WARNING_LINE;
  1054. }
  1055. return b_REGULAR_LINE;
  1056. }