cmCTestGenericHandler.cxx 4.7 KB

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