cmCTestGenericHandler.cxx 3.7 KB

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