cmCTestGenericHandler.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "cmCTestGenericHandler.h"
  4. #include <sstream>
  5. #include <utility>
  6. #include "cmCTest.h"
  7. #include "cmStringAlgorithms.h"
  8. #include "cmSystemTools.h"
  9. cmCTestGenericHandler::cmCTestGenericHandler()
  10. {
  11. this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
  12. this->CTest = nullptr;
  13. this->SubmitIndex = 0;
  14. this->AppendXML = false;
  15. this->Quiet = false;
  16. this->TestLoad = 0;
  17. }
  18. cmCTestGenericHandler::~cmCTestGenericHandler() = default;
  19. void cmCTestGenericHandler::SetOption(const std::string& op, const char* value)
  20. {
  21. if (!value) {
  22. auto remit = this->Options.find(op);
  23. if (remit != this->Options.end()) {
  24. this->Options.erase(remit);
  25. }
  26. return;
  27. }
  28. this->Options[op] = value;
  29. }
  30. void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
  31. const char* value)
  32. {
  33. this->SetOption(op, value);
  34. if (!value) {
  35. auto remit = this->PersistentOptions.find(op);
  36. if (remit != this->PersistentOptions.end()) {
  37. this->PersistentOptions.erase(remit);
  38. }
  39. return;
  40. }
  41. this->PersistentOptions[op] = value;
  42. }
  43. void cmCTestGenericHandler::Initialize()
  44. {
  45. this->AppendXML = false;
  46. this->TestLoad = 0;
  47. this->Options.clear();
  48. for (auto const& po : this->PersistentOptions) {
  49. this->Options[po.first] = po.second;
  50. }
  51. }
  52. const char* cmCTestGenericHandler::GetOption(const std::string& op)
  53. {
  54. auto remit = this->Options.find(op);
  55. if (remit == this->Options.end()) {
  56. return nullptr;
  57. }
  58. return remit->second.c_str();
  59. }
  60. bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
  61. const char* name,
  62. cmGeneratedFileStream& xofs)
  63. {
  64. if (!name) {
  65. cmCTestLog(this->CTest, ERROR_MESSAGE,
  66. "Cannot create resulting XML file without providing the name"
  67. << std::endl;);
  68. return false;
  69. }
  70. std::ostringstream ostr;
  71. ostr << name;
  72. if (this->SubmitIndex > 0) {
  73. ostr << "_" << this->SubmitIndex;
  74. }
  75. ostr << ".xml";
  76. if (this->CTest->GetCurrentTag().empty()) {
  77. cmCTestLog(this->CTest, ERROR_MESSAGE,
  78. "Current Tag empty, this may mean NightlyStartTime / "
  79. "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
  80. "maybe you forgot to call ctest_start() before calling "
  81. "ctest_configure()."
  82. << std::endl);
  83. cmSystemTools::SetFatalErrorOccured();
  84. return false;
  85. }
  86. if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), ostr.str(),
  87. xofs, true)) {
  88. cmCTestLog(this->CTest, ERROR_MESSAGE,
  89. "Cannot create resulting XML file: " << ostr.str()
  90. << std::endl);
  91. return false;
  92. }
  93. this->CTest->AddSubmitFile(part, ostr.str());
  94. return true;
  95. }
  96. bool cmCTestGenericHandler::StartLogFile(const char* name,
  97. cmGeneratedFileStream& xofs)
  98. {
  99. if (!name) {
  100. cmCTestLog(this->CTest, ERROR_MESSAGE,
  101. "Cannot create log file without providing the name"
  102. << std::endl;);
  103. return false;
  104. }
  105. std::ostringstream ostr;
  106. ostr << "Last" << name;
  107. if (this->SubmitIndex > 0) {
  108. ostr << "_" << this->SubmitIndex;
  109. }
  110. if (!this->CTest->GetCurrentTag().empty()) {
  111. ostr << "_" << this->CTest->GetCurrentTag();
  112. }
  113. ostr << ".log";
  114. this->LogFileNames[name] =
  115. cmStrCat(this->CTest->GetBinaryDir(), "/Testing/Temporary/", ostr.str());
  116. if (!this->CTest->OpenOutputFile("Temporary", ostr.str(), xofs)) {
  117. cmCTestLog(this->CTest, ERROR_MESSAGE,
  118. "Cannot create log file: " << ostr.str() << std::endl);
  119. return false;
  120. }
  121. return true;
  122. }