1
0

cmCTestBuildHandler.cxx 40 KB

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