cmCTestGenericHandler.cxx 3.9 KB

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