cmCTestGenericHandler.cxx 4.8 KB

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