cmCTestGenericHandler.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "cmCTest.h"
  5. #include "cmSystemTools.h"
  6. #include <sstream>
  7. #include <utility>
  8. cmCTestGenericHandler::cmCTestGenericHandler()
  9. {
  10. this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
  11. this->CTest = CM_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. t_StringToString::iterator it;
  52. for (it = this->PersistentOptions.begin();
  53. it != this->PersistentOptions.end(); ++it) {
  54. this->Options[it->first] = it->second;
  55. }
  56. }
  57. const char* cmCTestGenericHandler::GetOption(const std::string& op)
  58. {
  59. cmCTestGenericHandler::t_StringToString::iterator remit =
  60. this->Options.find(op);
  61. if (remit == this->Options.end()) {
  62. return CM_NULLPTR;
  63. }
  64. return remit->second.c_str();
  65. }
  66. bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
  67. const char* name,
  68. cmGeneratedFileStream& xofs)
  69. {
  70. if (!name) {
  71. cmCTestLog(this->CTest, ERROR_MESSAGE,
  72. "Cannot create resulting XML file without providing the name"
  73. << std::endl;);
  74. return false;
  75. }
  76. std::ostringstream ostr;
  77. ostr << name;
  78. if (this->SubmitIndex > 0) {
  79. ostr << "_" << this->SubmitIndex;
  80. }
  81. ostr << ".xml";
  82. if (this->CTest->GetCurrentTag().empty()) {
  83. cmCTestLog(this->CTest, ERROR_MESSAGE,
  84. "Current Tag empty, this may mean NightlyStartTime / "
  85. "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
  86. "maybe you forgot to call ctest_start() before calling "
  87. "ctest_configure()."
  88. << std::endl);
  89. cmSystemTools::SetFatalErrorOccured();
  90. return false;
  91. }
  92. if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), ostr.str(),
  93. xofs, true)) {
  94. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create resulting XML file: "
  95. << ostr.str() << std::endl);
  96. return false;
  97. }
  98. this->CTest->AddSubmitFile(part, ostr.str().c_str());
  99. return true;
  100. }
  101. bool cmCTestGenericHandler::StartLogFile(const char* name,
  102. cmGeneratedFileStream& xofs)
  103. {
  104. if (!name) {
  105. cmCTestLog(this->CTest, ERROR_MESSAGE,
  106. "Cannot create log file without providing the name"
  107. << std::endl;);
  108. return false;
  109. }
  110. std::ostringstream ostr;
  111. ostr << "Last" << name;
  112. if (this->SubmitIndex > 0) {
  113. ostr << "_" << this->SubmitIndex;
  114. }
  115. if (!this->CTest->GetCurrentTag().empty()) {
  116. ostr << "_" << this->CTest->GetCurrentTag();
  117. }
  118. ostr << ".log";
  119. if (!this->CTest->OpenOutputFile("Temporary", ostr.str(), xofs)) {
  120. cmCTestLog(this->CTest, ERROR_MESSAGE,
  121. "Cannot create log file: " << ostr.str() << std::endl);
  122. return false;
  123. }
  124. return true;
  125. }