1
0

cmCTestBuildHandler.h 4.3 KB

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