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