cmCTestGenericHandler.cxx 4.8 KB

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