cmCTestGenericHandler.cxx 3.8 KB

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