cmCTestBuildHandler.cxx 39 KB

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