cmCTestBuildHandler.cxx 39 KB

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