cmCTestBuildHandler.cxx 41 KB

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