cmCTestBuildHandler.cxx 40 KB

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