cmCTestBuildHandler.h 4.4 KB

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