cmCTestBuildHandler.cxx 39 KB

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