cmCTestBuildHandler.cxx 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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",
  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()
  168. {
  169. this->MaxPreContext = 10;
  170. this->MaxPostContext = 10;
  171. this->MaxErrors = 50;
  172. this->MaxWarnings = 50;
  173. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  174. this->UseCTestLaunch = false;
  175. }
  176. void cmCTestBuildHandler::Initialize()
  177. {
  178. this->Superclass::Initialize();
  179. this->StartBuild.clear();
  180. this->EndBuild.clear();
  181. this->CustomErrorMatches.clear();
  182. this->CustomErrorExceptions.clear();
  183. this->CustomWarningMatches.clear();
  184. this->CustomWarningExceptions.clear();
  185. this->ReallyCustomWarningMatches.clear();
  186. this->ReallyCustomWarningExceptions.clear();
  187. this->ErrorWarningFileLineRegex.clear();
  188. this->ErrorMatchRegex.clear();
  189. this->ErrorExceptionRegex.clear();
  190. this->WarningMatchRegex.clear();
  191. this->WarningExceptionRegex.clear();
  192. this->BuildProcessingQueue.clear();
  193. this->BuildProcessingErrorQueue.clear();
  194. this->BuildOutputLogSize = 0;
  195. this->CurrentProcessingLine.clear();
  196. this->SimplifySourceDir.clear();
  197. this->SimplifyBuildDir.clear();
  198. this->OutputLineCounter = 0;
  199. this->ErrorsAndWarnings.clear();
  200. this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
  201. this->PostContextCount = 0;
  202. this->MaxPreContext = 10;
  203. this->MaxPostContext = 10;
  204. this->PreContext.clear();
  205. this->TotalErrors = 0;
  206. this->TotalWarnings = 0;
  207. this->LastTickChar = 0;
  208. this->ErrorQuotaReached = false;
  209. this->WarningQuotaReached = false;
  210. this->MaxErrors = 50;
  211. this->MaxWarnings = 50;
  212. this->UseCTestLaunch = false;
  213. }
  214. void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile* mf)
  215. {
  216. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH",
  217. this->CustomErrorMatches);
  218. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION",
  219. this->CustomErrorExceptions);
  220. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH",
  221. this->CustomWarningMatches);
  222. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION",
  223. this->CustomWarningExceptions);
  224. this->CTest->PopulateCustomInteger(
  225. mf, "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS", this->MaxErrors);
  226. this->CTest->PopulateCustomInteger(
  227. mf, "CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS", this->MaxWarnings);
  228. int n = -1;
  229. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_PRE_CONTEXT", n);
  230. if (n != -1) {
  231. this->MaxPreContext = static_cast<size_t>(n);
  232. }
  233. n = -1;
  234. this->CTest->PopulateCustomInteger(mf, "CTEST_CUSTOM_ERROR_POST_CONTEXT", n);
  235. if (n != -1) {
  236. this->MaxPostContext = static_cast<size_t>(n);
  237. }
  238. // Record the user-specified custom warning rules.
  239. if (cmValue customWarningMatchers =
  240. mf->GetDefinition("CTEST_CUSTOM_WARNING_MATCH")) {
  241. cmExpandList(*customWarningMatchers, this->ReallyCustomWarningMatches);
  242. }
  243. if (cmValue customWarningExceptions =
  244. mf->GetDefinition("CTEST_CUSTOM_WARNING_EXCEPTION")) {
  245. cmExpandList(*customWarningExceptions,
  246. this->ReallyCustomWarningExceptions);
  247. }
  248. }
  249. std::string cmCTestBuildHandler::GetMakeCommand()
  250. {
  251. std::string makeCommand = this->CTest->GetCTestConfiguration("MakeCommand");
  252. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  253. "MakeCommand:" << makeCommand << "\n", this->Quiet);
  254. std::string configType = this->CTest->GetConfigType();
  255. if (configType.empty()) {
  256. configType =
  257. this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
  258. }
  259. if (configType.empty()) {
  260. configType = "Release";
  261. }
  262. cmSystemTools::ReplaceString(makeCommand, "${CTEST_CONFIGURATION_TYPE}",
  263. configType.c_str());
  264. return makeCommand;
  265. }
  266. // clearly it would be nice if this were broken up into a few smaller
  267. // functions and commented...
  268. int cmCTestBuildHandler::ProcessHandler()
  269. {
  270. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl,
  271. this->Quiet);
  272. // do we have time for this
  273. if (this->CTest->GetRemainingTimeAllowed() < std::chrono::minutes(2)) {
  274. return 0;
  275. }
  276. int entry;
  277. for (entry = 0; cmCTestWarningErrorFileLine[entry].RegularExpressionString;
  278. ++entry) {
  279. cmCTestBuildHandler::cmCTestCompileErrorWarningRex r;
  280. if (r.RegularExpression.compile(
  281. cmCTestWarningErrorFileLine[entry].RegularExpressionString)) {
  282. r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
  283. r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
  284. this->ErrorWarningFileLineRegex.push_back(std::move(r));
  285. } else {
  286. cmCTestLog(
  287. this->CTest, ERROR_MESSAGE,
  288. "Problem Compiling regular expression: "
  289. << cmCTestWarningErrorFileLine[entry].RegularExpressionString
  290. << std::endl);
  291. }
  292. }
  293. // Determine build command and build directory
  294. std::string makeCommand = this->GetMakeCommand();
  295. if (makeCommand.empty()) {
  296. cmCTestLog(this->CTest, ERROR_MESSAGE,
  297. "Cannot find MakeCommand key in the DartConfiguration.tcl"
  298. << std::endl);
  299. return -1;
  300. }
  301. const std::string& buildDirectory =
  302. this->CTest->GetCTestConfiguration("BuildDirectory");
  303. if (buildDirectory.empty()) {
  304. cmCTestLog(this->CTest, ERROR_MESSAGE,
  305. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  306. << std::endl);
  307. return -1;
  308. }
  309. std::string const& useLaunchers =
  310. this->CTest->GetCTestConfiguration("UseLaunchers");
  311. this->UseCTestLaunch = cmIsOn(useLaunchers);
  312. // Create a last build log
  313. cmGeneratedFileStream ofs;
  314. auto elapsed_time_start = std::chrono::steady_clock::now();
  315. if (!this->StartLogFile("Build", ofs)) {
  316. cmCTestLog(this->CTest, ERROR_MESSAGE,
  317. "Cannot create build log file" << std::endl);
  318. }
  319. // Create lists of regular expression strings for errors, error exceptions,
  320. // warnings and warning exceptions.
  321. std::vector<std::string>::size_type cc;
  322. for (cc = 0; cmCTestErrorMatches[cc]; cc++) {
  323. this->CustomErrorMatches.emplace_back(cmCTestErrorMatches[cc]);
  324. }
  325. for (cc = 0; cmCTestErrorExceptions[cc]; cc++) {
  326. this->CustomErrorExceptions.emplace_back(cmCTestErrorExceptions[cc]);
  327. }
  328. for (cc = 0; cmCTestWarningMatches[cc]; cc++) {
  329. this->CustomWarningMatches.emplace_back(cmCTestWarningMatches[cc]);
  330. }
  331. for (cc = 0; cmCTestWarningExceptions[cc]; cc++) {
  332. this->CustomWarningExceptions.emplace_back(cmCTestWarningExceptions[cc]);
  333. }
  334. // Pre-compile regular expressions objects for all regular expressions
  335. #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
  336. do { \
  337. regexes.clear(); \
  338. cmCTestOptionalLog(this->CTest, DEBUG, \
  339. this << "Add " #regexes << std::endl, this->Quiet); \
  340. for (std::string const& s : (strings)) { \
  341. cmCTestOptionalLog(this->CTest, DEBUG, \
  342. "Add " #strings ": " << s << std::endl, \
  343. this->Quiet); \
  344. (regexes).emplace_back(s); \
  345. } \
  346. } while (false)
  347. cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorMatches,
  348. this->ErrorMatchRegex);
  349. cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorExceptions,
  350. this->ErrorExceptionRegex);
  351. cmCTestBuildHandlerPopulateRegexVector(this->CustomWarningMatches,
  352. this->WarningMatchRegex);
  353. cmCTestBuildHandlerPopulateRegexVector(this->CustomWarningExceptions,
  354. this->WarningExceptionRegex);
  355. // Determine source and binary tree substitutions to simplify the output.
  356. this->SimplifySourceDir.clear();
  357. this->SimplifyBuildDir.clear();
  358. if (this->CTest->GetCTestConfiguration("SourceDirectory").size() > 20) {
  359. std::string srcdir =
  360. this->CTest->GetCTestConfiguration("SourceDirectory") + "/";
  361. cc = srcdir.rfind('/', srcdir.size() - 2);
  362. if (cc != std::string::npos) {
  363. srcdir.resize(cc + 1);
  364. this->SimplifySourceDir = std::move(srcdir);
  365. }
  366. }
  367. if (this->CTest->GetCTestConfiguration("BuildDirectory").size() > 20) {
  368. std::string bindir =
  369. this->CTest->GetCTestConfiguration("BuildDirectory") + "/";
  370. cc = bindir.rfind('/', bindir.size() - 2);
  371. if (cc != std::string::npos) {
  372. bindir.resize(cc + 1);
  373. this->SimplifyBuildDir = std::move(bindir);
  374. }
  375. }
  376. // Ok, let's do the build
  377. // Remember start build time
  378. this->StartBuild = this->CTest->CurrentTime();
  379. this->StartBuildTime = std::chrono::system_clock::now();
  380. cmStringReplaceHelper colorRemover("\x1b\\[[0-9;]*m", "", nullptr);
  381. this->ColorRemover = &colorRemover;
  382. int retVal = 0;
  383. bool res = true;
  384. if (!this->CTest->GetShowOnly()) {
  385. res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0,
  386. ofs);
  387. } else {
  388. cmCTestOptionalLog(this->CTest, DEBUG,
  389. "Build with command: " << makeCommand << std::endl,
  390. this->Quiet);
  391. }
  392. // Remember end build time and calculate elapsed time
  393. this->EndBuild = this->CTest->CurrentTime();
  394. this->EndBuildTime = std::chrono::system_clock::now();
  395. auto elapsed_build_time =
  396. std::chrono::steady_clock::now() - elapsed_time_start;
  397. // Cleanups strings in the errors and warnings list.
  398. if (!this->SimplifySourceDir.empty()) {
  399. for (cmCTestBuildErrorWarning& evit : this->ErrorsAndWarnings) {
  400. cmSystemTools::ReplaceString(evit.Text, this->SimplifySourceDir.c_str(),
  401. "/.../");
  402. cmSystemTools::ReplaceString(evit.PreContext,
  403. this->SimplifySourceDir.c_str(), "/.../");
  404. cmSystemTools::ReplaceString(evit.PostContext,
  405. this->SimplifySourceDir.c_str(), "/.../");
  406. }
  407. }
  408. if (!this->SimplifyBuildDir.empty()) {
  409. for (cmCTestBuildErrorWarning& evit : this->ErrorsAndWarnings) {
  410. cmSystemTools::ReplaceString(evit.Text, this->SimplifyBuildDir.c_str(),
  411. "/.../");
  412. cmSystemTools::ReplaceString(evit.PreContext,
  413. this->SimplifyBuildDir.c_str(), "/.../");
  414. cmSystemTools::ReplaceString(evit.PostContext,
  415. this->SimplifyBuildDir.c_str(), "/.../");
  416. }
  417. }
  418. // Generate XML output
  419. cmGeneratedFileStream xofs;
  420. if (!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs)) {
  421. cmCTestLog(this->CTest, ERROR_MESSAGE,
  422. "Cannot create build XML file" << std::endl);
  423. return -1;
  424. }
  425. cmXMLWriter xml(xofs);
  426. this->GenerateXMLHeader(xml);
  427. if (this->UseCTestLaunch) {
  428. this->GenerateXMLLaunched(xml);
  429. } else {
  430. this->GenerateXMLLogScraped(xml);
  431. }
  432. this->GenerateXMLFooter(xml, elapsed_build_time);
  433. if (!res || retVal || this->TotalErrors > 0) {
  434. cmCTestLog(this->CTest, ERROR_MESSAGE,
  435. "Error(s) when building project" << std::endl);
  436. }
  437. // Display message about number of errors and warnings
  438. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  439. " " << this->TotalErrors
  440. << (this->TotalErrors >= this->MaxErrors ? " or more" : "")
  441. << " Compiler errors" << std::endl);
  442. cmCTestLog(
  443. this->CTest, HANDLER_OUTPUT,
  444. " " << this->TotalWarnings
  445. << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "")
  446. << " Compiler warnings" << std::endl);
  447. return retVal;
  448. }
  449. void cmCTestBuildHandler::GenerateXMLHeader(cmXMLWriter& xml)
  450. {
  451. this->CTest->StartXML(xml, this->AppendXML);
  452. this->CTest->GenerateSubprojectsOutput(xml);
  453. xml.StartElement("Build");
  454. xml.Element("StartDateTime", this->StartBuild);
  455. xml.Element("StartBuildTime", this->StartBuildTime);
  456. xml.Element("BuildCommand", this->GetMakeCommand());
  457. }
  458. class cmCTestBuildHandler::FragmentCompare
  459. {
  460. public:
  461. FragmentCompare(cmFileTimeCache* ftc)
  462. : FTC(ftc)
  463. {
  464. }
  465. FragmentCompare() = default;
  466. bool operator()(std::string const& l, std::string const& r) const
  467. {
  468. // Order files by modification time. Use lexicographic order
  469. // among files with the same time.
  470. int result;
  471. if (this->FTC->Compare(l, r, &result) && result != 0) {
  472. return result < 0;
  473. }
  474. return l < r;
  475. }
  476. private:
  477. cmFileTimeCache* FTC = nullptr;
  478. };
  479. void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
  480. {
  481. if (this->CTestLaunchDir.empty()) {
  482. return;
  483. }
  484. // Sort XML fragments in chronological order.
  485. cmFileTimeCache ftc;
  486. FragmentCompare fragmentCompare(&ftc);
  487. using Fragments = std::set<std::string, FragmentCompare>;
  488. Fragments fragments(fragmentCompare);
  489. // only report the first 50 warnings and first 50 errors
  490. int numErrorsAllowed = this->MaxErrors;
  491. int numWarningsAllowed = this->MaxWarnings;
  492. // Identify fragments on disk.
  493. cmsys::Directory launchDir;
  494. launchDir.Load(this->CTestLaunchDir);
  495. unsigned long n = launchDir.GetNumberOfFiles();
  496. for (unsigned long i = 0; i < n; ++i) {
  497. const char* fname = launchDir.GetFile(i);
  498. if (this->IsLaunchedErrorFile(fname) && numErrorsAllowed) {
  499. numErrorsAllowed--;
  500. fragments.insert(this->CTestLaunchDir + '/' + fname);
  501. ++this->TotalErrors;
  502. } else if (this->IsLaunchedWarningFile(fname) && numWarningsAllowed) {
  503. numWarningsAllowed--;
  504. fragments.insert(this->CTestLaunchDir + '/' + fname);
  505. ++this->TotalWarnings;
  506. }
  507. }
  508. // Copy the fragments into the final XML file.
  509. for (std::string const& f : fragments) {
  510. xml.FragmentFile(f.c_str());
  511. }
  512. }
  513. void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
  514. {
  515. std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
  516. std::vector<cmCTestBuildErrorWarning>::iterator it;
  517. // only report the first 50 warnings and first 50 errors
  518. int numErrorsAllowed = this->MaxErrors;
  519. int numWarningsAllowed = this->MaxWarnings;
  520. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  521. for (it = ew.begin();
  522. it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++) {
  523. cmCTestBuildErrorWarning* cm = &(*it);
  524. if ((cm->Error && numErrorsAllowed) ||
  525. (!cm->Error && numWarningsAllowed)) {
  526. if (cm->Error) {
  527. numErrorsAllowed--;
  528. } else {
  529. numWarningsAllowed--;
  530. }
  531. xml.StartElement(cm->Error ? "Error" : "Warning");
  532. xml.Element("BuildLogLine", cm->LogLine);
  533. xml.Element("Text", cm->Text);
  534. for (cmCTestCompileErrorWarningRex& rit :
  535. this->ErrorWarningFileLineRegex) {
  536. cmsys::RegularExpression* re = &rit.RegularExpression;
  537. if (re->find(cm->Text)) {
  538. cm->SourceFile = re->match(rit.FileIndex);
  539. // At this point we need to make this->SourceFile relative to
  540. // the source root of the project, so cvs links will work
  541. cmSystemTools::ConvertToUnixSlashes(cm->SourceFile);
  542. if (cm->SourceFile.find("/.../") != std::string::npos) {
  543. cmSystemTools::ReplaceString(cm->SourceFile, "/.../", "");
  544. std::string::size_type p = cm->SourceFile.find('/');
  545. if (p != std::string::npos) {
  546. cm->SourceFile =
  547. cm->SourceFile.substr(p + 1, cm->SourceFile.size() - p);
  548. }
  549. } else {
  550. // make sure it is a full path with the correct case
  551. cm->SourceFile =
  552. cmSystemTools::ToNormalizedPathOnDisk(cm->SourceFile);
  553. cmSystemTools::ReplaceString(cm->SourceFile, srcdir, "");
  554. }
  555. cm->LineNumber = atoi(re->match(rit.LineIndex).c_str());
  556. break;
  557. }
  558. }
  559. if (!cm->SourceFile.empty() && cm->LineNumber >= 0) {
  560. if (!cm->SourceFile.empty()) {
  561. xml.Element("SourceFile", cm->SourceFile);
  562. }
  563. if (!cm->SourceFileTail.empty()) {
  564. xml.Element("SourceFileTail", cm->SourceFileTail);
  565. }
  566. if (cm->LineNumber >= 0) {
  567. xml.Element("SourceLineNumber", cm->LineNumber);
  568. }
  569. }
  570. xml.Element("PreContext", cm->PreContext);
  571. xml.StartElement("PostContext");
  572. xml.Content(cm->PostContext);
  573. // is this the last warning or error, if so notify
  574. if ((cm->Error && !numErrorsAllowed) ||
  575. (!cm->Error && !numWarningsAllowed)) {
  576. xml.Content("\nThe maximum number of reported warnings or errors "
  577. "has been reached!!!\n");
  578. }
  579. xml.EndElement(); // PostContext
  580. xml.Element("RepeatCount", "0");
  581. xml.EndElement(); // "Error" / "Warning"
  582. }
  583. }
  584. }
  585. void cmCTestBuildHandler::GenerateXMLFooter(cmXMLWriter& xml,
  586. cmDuration elapsed_build_time)
  587. {
  588. xml.StartElement("Log");
  589. xml.Attribute("Encoding", "base64");
  590. xml.Attribute("Compression", "bin/gzip");
  591. xml.EndElement(); // Log
  592. xml.Element("EndDateTime", this->EndBuild);
  593. xml.Element("EndBuildTime", this->EndBuildTime);
  594. xml.Element(
  595. "ElapsedMinutes",
  596. std::chrono::duration_cast<std::chrono::minutes>(elapsed_build_time)
  597. .count());
  598. xml.EndElement(); // Build
  599. this->CTest->EndXML(xml);
  600. }
  601. bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname)
  602. {
  603. // error-{hash}.xml
  604. return (cmHasLiteralPrefix(fname, "error-") &&
  605. cmHasLiteralSuffix(fname, ".xml"));
  606. }
  607. bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname)
  608. {
  609. // warning-{hash}.xml
  610. return (cmHasLiteralPrefix(fname, "warning-") &&
  611. cmHasLiteralSuffix(fname, ".xml"));
  612. }
  613. // ######################################################################
  614. // ######################################################################
  615. // ######################################################################
  616. // ######################################################################
  617. class cmCTestBuildHandler::LaunchHelper
  618. {
  619. public:
  620. LaunchHelper(cmCTestBuildHandler* handler);
  621. ~LaunchHelper();
  622. LaunchHelper(const LaunchHelper&) = delete;
  623. LaunchHelper& operator=(const LaunchHelper&) = delete;
  624. private:
  625. cmCTestBuildHandler* Handler;
  626. cmCTest* CTest;
  627. void WriteLauncherConfig();
  628. void WriteScrapeMatchers(const char* purpose,
  629. std::vector<std::string> const& matchers);
  630. };
  631. cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler)
  632. : Handler(handler)
  633. , CTest(handler->CTest)
  634. {
  635. std::string tag = this->CTest->GetCurrentTag();
  636. if (tag.empty()) {
  637. // This is not for a dashboard submission, so there is no XML.
  638. // Skip enabling the launchers.
  639. this->Handler->UseCTestLaunch = false;
  640. } else {
  641. // Compute a directory in which to store launcher fragments.
  642. std::string& launchDir = this->Handler->CTestLaunchDir;
  643. launchDir =
  644. cmStrCat(this->CTest->GetBinaryDir(), "/Testing/", tag, "/Build");
  645. // Clean out any existing launcher fragments.
  646. cmSystemTools::RemoveADirectory(launchDir);
  647. if (this->Handler->UseCTestLaunch) {
  648. // Enable launcher fragments.
  649. cmSystemTools::MakeDirectory(launchDir);
  650. this->WriteLauncherConfig();
  651. std::string launchEnv = cmStrCat("CTEST_LAUNCH_LOGS=", launchDir);
  652. cmSystemTools::PutEnv(launchEnv);
  653. }
  654. }
  655. // If not using launchers, make sure they passthru.
  656. if (!this->Handler->UseCTestLaunch) {
  657. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  658. }
  659. }
  660. cmCTestBuildHandler::LaunchHelper::~LaunchHelper()
  661. {
  662. if (this->Handler->UseCTestLaunch) {
  663. cmSystemTools::UnsetEnv("CTEST_LAUNCH_LOGS");
  664. }
  665. }
  666. void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
  667. {
  668. this->WriteScrapeMatchers("Warning",
  669. this->Handler->ReallyCustomWarningMatches);
  670. this->WriteScrapeMatchers("WarningSuppress",
  671. this->Handler->ReallyCustomWarningExceptions);
  672. // Give some testing configuration information to the launcher.
  673. std::string fname =
  674. cmStrCat(this->Handler->CTestLaunchDir, "/CTestLaunchConfig.cmake");
  675. cmGeneratedFileStream fout(fname);
  676. std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
  677. fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
  678. }
  679. void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers(
  680. const char* purpose, std::vector<std::string> const& matchers)
  681. {
  682. if (matchers.empty()) {
  683. return;
  684. }
  685. std::string fname =
  686. cmStrCat(this->Handler->CTestLaunchDir, "/Custom", purpose, ".txt");
  687. cmGeneratedFileStream fout(fname);
  688. for (std::string const& m : matchers) {
  689. fout << m << "\n";
  690. }
  691. }
  692. bool cmCTestBuildHandler::RunMakeCommand(const std::string& command,
  693. int* retVal, const char* dir,
  694. int timeout, std::ostream& ofs,
  695. Encoding encoding)
  696. {
  697. // First generate the command and arguments
  698. std::vector<std::string> args = cmSystemTools::ParseArguments(command);
  699. if (args.empty()) {
  700. return false;
  701. }
  702. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  703. "Run command:", this->Quiet);
  704. for (auto const& arg : args) {
  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. cmUVProcessChainBuilder builder;
  715. builder.AddCommand(args)
  716. .SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT)
  717. .SetBuiltinStream(cmUVProcessChainBuilder::Stream_ERROR);
  718. if (dir) {
  719. builder.SetWorkingDirectory(dir);
  720. }
  721. auto chain = builder.Start();
  722. // Initialize tick's
  723. std::string::size_type tick = 0;
  724. static constexpr std::string::size_type tick_len = 1024;
  725. cmProcessOutput processOutput(encoding);
  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. cm::uv_timer_ptr timer;
  746. bool timedOut = false;
  747. timer.init(chain.GetLoop(), &timedOut);
  748. if (timeout > 0) {
  749. timer.start(
  750. [](uv_timer_t* t) {
  751. auto* timedOutPtr = static_cast<bool*>(t->data);
  752. *timedOutPtr = true;
  753. },
  754. timeout * 1000, 0);
  755. }
  756. // For every chunk of data
  757. cm::uv_pipe_ptr outputStream;
  758. bool outFinished = false;
  759. cm::uv_pipe_ptr errorStream;
  760. bool errFinished = false;
  761. auto startRead = [this, &chain, &processOutput, &tick,
  762. &ofs](cm::uv_pipe_ptr& pipe, int stream,
  763. t_BuildProcessingQueueType& queue, bool& finished,
  764. int id) -> std::unique_ptr<cmUVStreamReadHandle> {
  765. pipe.init(chain.GetLoop(), 0);
  766. uv_pipe_open(pipe, stream);
  767. return cmUVStreamRead(
  768. pipe,
  769. [this, &processOutput, &queue, id, &tick, &ofs](std::vector<char> data) {
  770. // Replace '\0' with '\n', since '\0' does not really make sense. This
  771. // is for Visual Studio output
  772. for (auto& c : data) {
  773. if (c == 0) {
  774. c = '\n';
  775. }
  776. }
  777. // Process the chunk of data
  778. std::string strdata;
  779. processOutput.DecodeText(data.data(), data.size(), strdata, id);
  780. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len,
  781. ofs, &queue);
  782. },
  783. [this, &processOutput, &queue, id, &tick, &ofs, &finished]() {
  784. std::string strdata;
  785. processOutput.DecodeText(std::string(), strdata, id);
  786. if (!strdata.empty()) {
  787. this->ProcessBuffer(strdata.c_str(), strdata.size(), tick, tick_len,
  788. ofs, &queue);
  789. }
  790. finished = true;
  791. });
  792. };
  793. auto outputHandle = startRead(outputStream, chain.OutputStream(),
  794. this->BuildProcessingQueue, outFinished, 1);
  795. auto errorHandle =
  796. startRead(errorStream, chain.ErrorStream(),
  797. this->BuildProcessingErrorQueue, errFinished, 2);
  798. while (!timedOut && !(outFinished && errFinished && chain.Finished())) {
  799. uv_run(&chain.GetLoop(), UV_RUN_ONCE);
  800. }
  801. this->ProcessBuffer(nullptr, 0, tick, tick_len, ofs,
  802. &this->BuildProcessingQueue);
  803. this->ProcessBuffer(nullptr, 0, tick, tick_len, ofs,
  804. &this->BuildProcessingErrorQueue);
  805. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
  806. " Size of output: "
  807. << ((this->BuildOutputLogSize + 512) / 1024) << "K"
  808. << std::endl,
  809. this->Quiet);
  810. if (chain.Finished()) {
  811. auto const& status = chain.GetStatus(0);
  812. auto exception = status.GetException();
  813. switch (exception.first) {
  814. case cmUVProcessChain::ExceptionCode::None:
  815. if (retVal) {
  816. *retVal = static_cast<int>(status.ExitStatus);
  817. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  818. "Command exited with the value: " << *retVal
  819. << std::endl,
  820. this->Quiet);
  821. // if a non zero return value
  822. if (*retVal) {
  823. // If there was an error running command, report that on the
  824. // dashboard.
  825. if (this->UseCTestLaunch) {
  826. // For launchers, do not record this top-level error if other
  827. // more granular build errors have already been captured.
  828. bool launcherXMLFound = false;
  829. cmsys::Directory launchDir;
  830. launchDir.Load(this->CTestLaunchDir);
  831. unsigned long n = launchDir.GetNumberOfFiles();
  832. for (unsigned long i = 0; i < n; ++i) {
  833. const char* fname = launchDir.GetFile(i);
  834. if (cmHasLiteralSuffix(fname, ".xml")) {
  835. launcherXMLFound = true;
  836. break;
  837. }
  838. }
  839. if (!launcherXMLFound) {
  840. cmCTestLaunchReporter reporter;
  841. reporter.RealArgs = args;
  842. reporter.ComputeFileNames();
  843. reporter.ExitCode = *retVal;
  844. reporter.Status = status;
  845. // Use temporary BuildLog file to populate this error for
  846. // CDash.
  847. ofs.flush();
  848. reporter.LogOut = this->LogFileNames["Build"];
  849. reporter.LogOut += ".tmp";
  850. reporter.WriteXML();
  851. }
  852. } else {
  853. cmCTestBuildErrorWarning errorwarning;
  854. errorwarning.LineNumber = 0;
  855. errorwarning.LogLine = 1;
  856. errorwarning.Text = cmStrCat(
  857. "*** WARNING non-zero return value in ctest from: ", args[0]);
  858. errorwarning.PreContext.clear();
  859. errorwarning.PostContext.clear();
  860. errorwarning.Error = false;
  861. this->ErrorsAndWarnings.push_back(std::move(errorwarning));
  862. this->TotalWarnings++;
  863. }
  864. }
  865. }
  866. break;
  867. case cmUVProcessChain::ExceptionCode::Spawn: {
  868. // If there was an error running command, report that on the dashboard.
  869. cmCTestBuildErrorWarning errorwarning;
  870. errorwarning.LineNumber = 0;
  871. errorwarning.LogLine = 1;
  872. errorwarning.Text =
  873. cmStrCat("*** ERROR executing: ", exception.second);
  874. errorwarning.PreContext.clear();
  875. errorwarning.PostContext.clear();
  876. errorwarning.Error = true;
  877. this->ErrorsAndWarnings.push_back(std::move(errorwarning));
  878. this->TotalErrors++;
  879. cmCTestLog(this->CTest, ERROR_MESSAGE,
  880. "There was an error: " << exception.second << std::endl);
  881. } break;
  882. default:
  883. if (retVal) {
  884. *retVal = status.TermSignal;
  885. cmCTestOptionalLog(
  886. this->CTest, WARNING,
  887. "There was an exception: " << *retVal << std::endl, this->Quiet);
  888. }
  889. break;
  890. }
  891. } else {
  892. cmCTestOptionalLog(this->CTest, WARNING,
  893. "There was a timeout" << std::endl, this->Quiet);
  894. }
  895. return true;
  896. }
  897. // ######################################################################
  898. // ######################################################################
  899. // ######################################################################
  900. // ######################################################################
  901. void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
  902. size_t& tick, size_t tick_len,
  903. std::ostream& ofs,
  904. t_BuildProcessingQueueType* queue)
  905. {
  906. const std::string::size_type tick_line_len = 50;
  907. const char* ptr;
  908. for (ptr = data; ptr < data + length; ptr++) {
  909. queue->push_back(*ptr);
  910. }
  911. this->BuildOutputLogSize += length;
  912. // until there are any lines left in the buffer
  913. while (true) {
  914. // Find the end of line
  915. t_BuildProcessingQueueType::iterator it;
  916. for (it = queue->begin(); it != queue->end(); ++it) {
  917. if (*it == '\n') {
  918. break;
  919. }
  920. }
  921. // Once certain number of errors or warnings reached, ignore future errors
  922. // or warnings.
  923. if (this->TotalWarnings >= this->MaxWarnings) {
  924. this->WarningQuotaReached = true;
  925. }
  926. if (this->TotalErrors >= this->MaxErrors) {
  927. this->ErrorQuotaReached = true;
  928. }
  929. // If the end of line was found
  930. if (it != queue->end()) {
  931. // Create a contiguous array for the line
  932. this->CurrentProcessingLine.clear();
  933. cm::append(this->CurrentProcessingLine, queue->begin(), it);
  934. this->CurrentProcessingLine.push_back(0);
  935. const char* line = this->CurrentProcessingLine.data();
  936. // Process the line
  937. int lineType = this->ProcessSingleLine(line);
  938. // Erase the line from the queue
  939. queue->erase(queue->begin(), it + 1);
  940. // Depending on the line type, produce error or warning, or nothing
  941. cmCTestBuildErrorWarning errorwarning;
  942. bool found = false;
  943. switch (lineType) {
  944. case b_WARNING_LINE:
  945. this->LastTickChar = '*';
  946. errorwarning.Error = false;
  947. found = true;
  948. this->TotalWarnings++;
  949. break;
  950. case b_ERROR_LINE:
  951. this->LastTickChar = '!';
  952. errorwarning.Error = true;
  953. found = true;
  954. this->TotalErrors++;
  955. break;
  956. }
  957. if (found) {
  958. // This is an error or warning, so generate report
  959. errorwarning.LogLine = static_cast<int>(this->OutputLineCounter + 1);
  960. errorwarning.Text = line;
  961. errorwarning.PreContext.clear();
  962. errorwarning.PostContext.clear();
  963. // Copy pre-context to report
  964. for (std::string const& pc : this->PreContext) {
  965. errorwarning.PreContext += pc + "\n";
  966. }
  967. this->PreContext.clear();
  968. // Store report
  969. this->ErrorsAndWarnings.push_back(std::move(errorwarning));
  970. this->LastErrorOrWarning = this->ErrorsAndWarnings.end() - 1;
  971. this->PostContextCount = 0;
  972. } else {
  973. // This is not an error or warning.
  974. // So, figure out if this is a post-context line
  975. if (!this->ErrorsAndWarnings.empty() &&
  976. this->LastErrorOrWarning != this->ErrorsAndWarnings.end() &&
  977. this->PostContextCount < this->MaxPostContext) {
  978. this->PostContextCount++;
  979. this->LastErrorOrWarning->PostContext += line;
  980. if (this->PostContextCount < this->MaxPostContext) {
  981. this->LastErrorOrWarning->PostContext += "\n";
  982. }
  983. } else {
  984. // Otherwise store pre-context for the next error
  985. this->PreContext.emplace_back(line);
  986. if (this->PreContext.size() > this->MaxPreContext) {
  987. this->PreContext.erase(this->PreContext.begin(),
  988. this->PreContext.end() -
  989. this->MaxPreContext);
  990. }
  991. }
  992. }
  993. this->OutputLineCounter++;
  994. } else {
  995. break;
  996. }
  997. }
  998. // Now that the buffer is processed, display missing ticks
  999. int tickDisplayed = false;
  1000. while (this->BuildOutputLogSize > (tick * tick_len)) {
  1001. tick++;
  1002. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
  1003. this->LastTickChar, this->Quiet);
  1004. tickDisplayed = true;
  1005. if (tick % tick_line_len == 0 && tick > 0) {
  1006. cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
  1007. " Size: "
  1008. << ((this->BuildOutputLogSize + 512) / 1024) << "K"
  1009. << std::endl
  1010. << " ",
  1011. this->Quiet);
  1012. }
  1013. }
  1014. if (tickDisplayed) {
  1015. this->LastTickChar = '.';
  1016. }
  1017. // And if this is verbose output, display the content of the chunk
  1018. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1019. cm::string_view(data, length));
  1020. // Always store the chunk to the file
  1021. ofs << cm::string_view(data, length);
  1022. }
  1023. int cmCTestBuildHandler::ProcessSingleLine(const char* data)
  1024. {
  1025. if (this->UseCTestLaunch) {
  1026. // No log scraping when using launchers.
  1027. return b_REGULAR_LINE;
  1028. }
  1029. // Ignore ANSI color codes when checking for errors and warnings.
  1030. std::string input(data);
  1031. std::string line;
  1032. this->ColorRemover->Replace(input, line);
  1033. cmCTestOptionalLog(this->CTest, DEBUG, "Line: [" << line << "]" << std::endl,
  1034. this->Quiet);
  1035. int warningLine = 0;
  1036. int errorLine = 0;
  1037. // Check for regular expressions
  1038. if (!this->ErrorQuotaReached) {
  1039. // Errors
  1040. int wrxCnt = 0;
  1041. for (cmsys::RegularExpression& rx : this->ErrorMatchRegex) {
  1042. if (rx.find(line.c_str())) {
  1043. errorLine = 1;
  1044. cmCTestOptionalLog(this->CTest, DEBUG,
  1045. " Error Line: " << line << " (matches: "
  1046. << this->CustomErrorMatches[wrxCnt]
  1047. << ")" << std::endl,
  1048. this->Quiet);
  1049. break;
  1050. }
  1051. wrxCnt++;
  1052. }
  1053. // Error exceptions
  1054. wrxCnt = 0;
  1055. for (cmsys::RegularExpression& rx : this->ErrorExceptionRegex) {
  1056. if (rx.find(line.c_str())) {
  1057. errorLine = 0;
  1058. cmCTestOptionalLog(this->CTest, DEBUG,
  1059. " Not an error Line: "
  1060. << line << " (matches: "
  1061. << this->CustomErrorExceptions[wrxCnt] << ")"
  1062. << std::endl,
  1063. this->Quiet);
  1064. break;
  1065. }
  1066. wrxCnt++;
  1067. }
  1068. }
  1069. if (!this->WarningQuotaReached) {
  1070. // Warnings
  1071. int wrxCnt = 0;
  1072. for (cmsys::RegularExpression& rx : this->WarningMatchRegex) {
  1073. if (rx.find(line.c_str())) {
  1074. warningLine = 1;
  1075. cmCTestOptionalLog(this->CTest, DEBUG,
  1076. " Warning Line: "
  1077. << line << " (matches: "
  1078. << this->CustomWarningMatches[wrxCnt] << ")"
  1079. << std::endl,
  1080. this->Quiet);
  1081. break;
  1082. }
  1083. wrxCnt++;
  1084. }
  1085. wrxCnt = 0;
  1086. // Warning exceptions
  1087. for (cmsys::RegularExpression& rx : this->WarningExceptionRegex) {
  1088. if (rx.find(line.c_str())) {
  1089. warningLine = 0;
  1090. cmCTestOptionalLog(this->CTest, DEBUG,
  1091. " Not a warning Line: "
  1092. << line << " (matches: "
  1093. << this->CustomWarningExceptions[wrxCnt] << ")"
  1094. << std::endl,
  1095. this->Quiet);
  1096. break;
  1097. }
  1098. wrxCnt++;
  1099. }
  1100. }
  1101. if (errorLine) {
  1102. return b_ERROR_LINE;
  1103. }
  1104. if (warningLine) {
  1105. return b_WARNING_LINE;
  1106. }
  1107. return b_REGULAR_LINE;
  1108. }