cmCTestBuildHandler.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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(const std::string& command, int* retVal, const char* 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 GenerateXMLFooter(cmXMLWriter& xml, cmDuration elapsed_build_time);
  73. bool IsLaunchedErrorFile(const char* fname);
  74. bool IsLaunchedWarningFile(const char* 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(const char* data, size_t length, size_t& tick,
  92. size_t tick_len, std::ostream& ofs,
  93. t_BuildProcessingQueueType* queue);
  94. int ProcessSingleLine(const char* data);
  95. t_BuildProcessingQueueType BuildProcessingQueue;
  96. t_BuildProcessingQueueType BuildProcessingErrorQueue;
  97. size_t BuildOutputLogSize;
  98. std::vector<char> CurrentProcessingLine;
  99. std::string SimplifySourceDir;
  100. std::string SimplifyBuildDir;
  101. size_t OutputLineCounter;
  102. using t_ErrorsAndWarningsVector = std::vector<cmCTestBuildErrorWarning>;
  103. t_ErrorsAndWarningsVector ErrorsAndWarnings;
  104. t_ErrorsAndWarningsVector::iterator LastErrorOrWarning;
  105. size_t PostContextCount;
  106. size_t MaxPreContext;
  107. size_t MaxPostContext;
  108. std::deque<std::string> PreContext;
  109. int TotalErrors;
  110. int TotalWarnings;
  111. char LastTickChar;
  112. bool ErrorQuotaReached;
  113. bool WarningQuotaReached;
  114. int MaxErrors;
  115. int MaxWarnings;
  116. // Used to remove ANSI color codes before checking for errors and warnings.
  117. cmStringReplaceHelper* ColorRemover;
  118. bool UseCTestLaunch;
  119. std::string CTestLaunchDir;
  120. class LaunchHelper;
  121. friend class LaunchHelper;
  122. class FragmentCompare;
  123. };