cmCTestGenericHandler.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestGenericHandler.h"
  11. #include "cmCTest.h"
  12. #include "cmSystemTools.h"
  13. #include <sstream>
  14. #include <utility>
  15. cmCTestGenericHandler::cmCTestGenericHandler()
  16. {
  17. this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
  18. this->CTest = CM_NULLPTR;
  19. this->SubmitIndex = 0;
  20. this->AppendXML = false;
  21. this->Quiet = false;
  22. this->TestLoad = 0;
  23. }
  24. cmCTestGenericHandler::~cmCTestGenericHandler()
  25. {
  26. }
  27. void cmCTestGenericHandler::SetOption(const std::string& op, const char* value)
  28. {
  29. if (!value) {
  30. cmCTestGenericHandler::t_StringToString::iterator remit =
  31. this->Options.find(op);
  32. if (remit != this->Options.end()) {
  33. this->Options.erase(remit);
  34. }
  35. return;
  36. }
  37. this->Options[op] = value;
  38. }
  39. void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
  40. const char* value)
  41. {
  42. this->SetOption(op, value);
  43. if (!value) {
  44. cmCTestGenericHandler::t_StringToString::iterator remit =
  45. this->PersistentOptions.find(op);
  46. if (remit != this->PersistentOptions.end()) {
  47. this->PersistentOptions.erase(remit);
  48. }
  49. return;
  50. }
  51. this->PersistentOptions[op] = value;
  52. }
  53. void cmCTestGenericHandler::Initialize()
  54. {
  55. this->AppendXML = false;
  56. this->TestLoad = 0;
  57. this->Options.clear();
  58. t_StringToString::iterator it;
  59. for (it = this->PersistentOptions.begin();
  60. it != this->PersistentOptions.end(); ++it) {
  61. this->Options[it->first] = it->second;
  62. }
  63. }
  64. const char* cmCTestGenericHandler::GetOption(const std::string& op)
  65. {
  66. cmCTestGenericHandler::t_StringToString::iterator remit =
  67. this->Options.find(op);
  68. if (remit == this->Options.end()) {
  69. return CM_NULLPTR;
  70. }
  71. return remit->second.c_str();
  72. }
  73. bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
  74. const char* name,
  75. cmGeneratedFileStream& xofs)
  76. {
  77. if (!name) {
  78. cmCTestLog(this->CTest, ERROR_MESSAGE,
  79. "Cannot create resulting XML file without providing the name"
  80. << std::endl;);
  81. return false;
  82. }
  83. std::ostringstream ostr;
  84. ostr << name;
  85. if (this->SubmitIndex > 0) {
  86. ostr << "_" << this->SubmitIndex;
  87. }
  88. ostr << ".xml";
  89. if (this->CTest->GetCurrentTag().empty()) {
  90. cmCTestLog(this->CTest, ERROR_MESSAGE,
  91. "Current Tag empty, this may mean NightlyStartTime / "
  92. "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
  93. "maybe you forgot to call ctest_start() before calling "
  94. "ctest_configure()."
  95. << std::endl);
  96. cmSystemTools::SetFatalErrorOccured();
  97. return false;
  98. }
  99. if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), ostr.str(),
  100. xofs, true)) {
  101. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create resulting XML file: "
  102. << ostr.str() << std::endl);
  103. return false;
  104. }
  105. this->CTest->AddSubmitFile(part, ostr.str().c_str());
  106. return true;
  107. }
  108. bool cmCTestGenericHandler::StartLogFile(const char* name,
  109. cmGeneratedFileStream& xofs)
  110. {
  111. if (!name) {
  112. cmCTestLog(this->CTest, ERROR_MESSAGE,
  113. "Cannot create log file without providing the name"
  114. << std::endl;);
  115. return false;
  116. }
  117. std::ostringstream ostr;
  118. ostr << "Last" << name;
  119. if (this->SubmitIndex > 0) {
  120. ostr << "_" << this->SubmitIndex;
  121. }
  122. if (!this->CTest->GetCurrentTag().empty()) {
  123. ostr << "_" << this->CTest->GetCurrentTag();
  124. }
  125. ostr << ".log";
  126. if (!this->CTest->OpenOutputFile("Temporary", ostr.str(), xofs)) {
  127. cmCTestLog(this->CTest, ERROR_MESSAGE,
  128. "Cannot create log file: " << ostr.str() << std::endl);
  129. return false;
  130. }
  131. return true;
  132. }