cmCTestGenericHandler.cxx 4.2 KB

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