cmCTestBuildHandler.cxx 40 KB

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