cmCTestBuildHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <chrono>
  6. #include <cstddef>
  7. #include <deque>
  8. #include <iosfwd>
  9. #include <string>
  10. #include <vector>
  11. #include "cmsys/RegularExpression.hxx"
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmDuration.h"
  14. #include "cmProcessOutput.h"
  15. class cmStringReplaceHelper;
  16. class cmXMLWriter;
  17. class cmCTest;
  18. /** \class cmCTestBuildHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. */
  22. class cmCTestBuildHandler : public cmCTestGenericHandler
  23. {
  24. public:
  25. using Superclass = cmCTestGenericHandler;
  26. using Encoding = cmProcessOutput::Encoding;
  27. /*
  28. * The main entry point for this class
  29. */
  30. int ProcessHandler() override;
  31. cmCTestBuildHandler(cmCTest* ctest);
  32. void PopulateCustomVectors(cmMakefile* mf) override;
  33. int GetTotalErrors() const { return this->TotalErrors; }
  34. int GetTotalWarnings() const { return this->TotalWarnings; }
  35. private:
  36. std::string GetMakeCommand();
  37. //! Run command specialized for make and configure. Returns process status
  38. // and retVal is return value or exception.
  39. bool RunMakeCommand(std::string const& command, int* retVal, char const* dir,
  40. int timeout, std::ostream& ofs,
  41. Encoding encoding = cmProcessOutput::Auto);
  42. enum
  43. {
  44. b_REGULAR_LINE,
  45. b_WARNING_LINE,
  46. b_ERROR_LINE
  47. };
  48. class cmCTestCompileErrorWarningRex
  49. {
  50. public:
  51. cmCTestCompileErrorWarningRex() {}
  52. int FileIndex;
  53. int LineIndex;
  54. cmsys::RegularExpression RegularExpression;
  55. };
  56. struct cmCTestBuildErrorWarning
  57. {
  58. bool Error;
  59. int LogLine;
  60. std::string Text;
  61. std::string SourceFile;
  62. std::string SourceFileTail;
  63. int LineNumber;
  64. std::string PreContext;
  65. std::string PostContext;
  66. };
  67. // generate the XML output
  68. void GenerateXMLHeader(cmXMLWriter& xml);
  69. void GenerateXMLLaunched(cmXMLWriter& xml);
  70. void GenerateXMLLogScraped(cmXMLWriter& xml);
  71. void GenerateInstrumentationXML(cmXMLWriter& xml);
  72. void GenerateXMLFooter(cmXMLWriter& xml, cmDuration elapsed_build_time);
  73. bool IsLaunchedErrorFile(char const* fname);
  74. bool IsLaunchedWarningFile(char const* fname);
  75. std::string StartBuild;
  76. std::string EndBuild;
  77. std::chrono::system_clock::time_point StartBuildTime;
  78. std::chrono::system_clock::time_point EndBuildTime;
  79. std::vector<std::string> CustomErrorMatches;
  80. std::vector<std::string> CustomErrorExceptions;
  81. std::vector<std::string> CustomWarningMatches;
  82. std::vector<std::string> CustomWarningExceptions;
  83. std::vector<std::string> ReallyCustomWarningMatches;
  84. std::vector<std::string> ReallyCustomWarningExceptions;
  85. std::vector<cmCTestCompileErrorWarningRex> ErrorWarningFileLineRegex;
  86. std::vector<cmsys::RegularExpression> ErrorMatchRegex;
  87. std::vector<cmsys::RegularExpression> ErrorExceptionRegex;
  88. std::vector<cmsys::RegularExpression> WarningMatchRegex;
  89. std::vector<cmsys::RegularExpression> WarningExceptionRegex;
  90. using t_BuildProcessingQueueType = std::deque<char>;
  91. void ProcessBuffer(char const* data, size_t length, size_t& tick,
  92. size_t tick_len, std::ostream& ofs,
  93. t_BuildProcessingQueueType* queue);
  94. int ProcessSingleLine(char const* data);
  95. t_BuildProcessingQueueType BuildProcessingQueue;
  96. t_BuildProcessingQueueType BuildProcessingErrorQueue;
  97. size_t BuildOutputLogSize = 0;
  98. std::vector<char> CurrentProcessingLine;
  99. std::string SimplifySourceDir;
  100. std::string SimplifyBuildDir;
  101. size_t OutputLineCounter = 0;
  102. using t_ErrorsAndWarningsVector = std::vector<cmCTestBuildErrorWarning>;
  103. t_ErrorsAndWarningsVector ErrorsAndWarnings;
  104. t_ErrorsAndWarningsVector::iterator LastErrorOrWarning;
  105. size_t PostContextCount = 0;
  106. size_t MaxPreContext = 10;
  107. size_t MaxPostContext = 10;
  108. std::deque<std::string> PreContext;
  109. int TotalErrors = 0;
  110. int TotalWarnings = 0;
  111. char LastTickChar = '\0';
  112. bool ErrorQuotaReached = false;
  113. bool WarningQuotaReached = false;
  114. int MaxErrors = 50;
  115. int MaxWarnings = 50;
  116. // Used to remove ANSI color codes before checking for errors and warnings.
  117. cmStringReplaceHelper* ColorRemover;
  118. bool UseCTestLaunch = false;
  119. std::string CTestLaunchDir;
  120. std::string LogFileName;
  121. class LaunchHelper;
  122. friend class LaunchHelper;
  123. class FragmentCompare;
  124. };