cmCTestGenericHandler.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestGenericHandler.h"
  14. #include "cmSystemTools.h"
  15. #include "cmCTest.h"
  16. //----------------------------------------------------------------------
  17. cmCTestGenericHandler::cmCTestGenericHandler()
  18. {
  19. this->HandlerVerbose = false;
  20. this->CTest = 0;
  21. this->SubmitIndex = 0;
  22. this->AppendXML = false;
  23. }
  24. //----------------------------------------------------------------------
  25. cmCTestGenericHandler::~cmCTestGenericHandler()
  26. {
  27. }
  28. //----------------------------------------------------------------------
  29. void cmCTestGenericHandler::SetOption(const char* op, const char* value)
  30. {
  31. if ( !op )
  32. {
  33. return;
  34. }
  35. if ( !value )
  36. {
  37. cmCTestGenericHandler::t_StringToString::iterator remit
  38. = this->Options.find(op);
  39. if ( remit != this->Options.end() )
  40. {
  41. this->Options.erase(remit);
  42. }
  43. return;
  44. }
  45. this->Options[op] = value;
  46. }
  47. //----------------------------------------------------------------------
  48. void cmCTestGenericHandler::SetPersistentOption(const char* op,
  49. const char* value)
  50. {
  51. this->SetOption(op, value);
  52. if ( !op )
  53. {
  54. return;
  55. }
  56. if ( !value )
  57. {
  58. cmCTestGenericHandler::t_StringToString::iterator remit
  59. = this->PersistentOptions.find(op);
  60. if ( remit != this->PersistentOptions.end() )
  61. {
  62. this->PersistentOptions.erase(remit);
  63. }
  64. return;
  65. }
  66. this->PersistentOptions[op] = value;
  67. }
  68. //----------------------------------------------------------------------
  69. void cmCTestGenericHandler::Initialize()
  70. {
  71. this->AppendXML = false;
  72. this->Options.clear();
  73. t_StringToString::iterator it;
  74. for ( it = this->PersistentOptions.begin();
  75. it != this->PersistentOptions.end();
  76. ++ it )
  77. {
  78. this->Options[it->first.c_str()] = it->second.c_str();
  79. }
  80. }
  81. //----------------------------------------------------------------------
  82. const char* cmCTestGenericHandler::GetOption(const char* op)
  83. {
  84. cmCTestGenericHandler::t_StringToString::iterator remit
  85. = this->Options.find(op);
  86. if ( remit == this->Options.end() )
  87. {
  88. return 0;
  89. }
  90. return remit->second.c_str();
  91. }
  92. //----------------------------------------------------------------------
  93. bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
  94. const char* name,
  95. cmGeneratedFileStream& xofs)
  96. {
  97. if ( !name )
  98. {
  99. cmCTestLog(this->CTest, ERROR_MESSAGE,
  100. "Cannot create resulting XML file without providing the name"
  101. << std::endl;);
  102. return false;
  103. }
  104. cmOStringStream ostr;
  105. ostr << name;
  106. if ( this->SubmitIndex > 0 )
  107. {
  108. ostr << "_" << this->SubmitIndex;
  109. }
  110. ostr << ".xml";
  111. if(this->CTest->GetCurrentTag().empty())
  112. {
  113. cmCTestLog(this->CTest, ERROR_MESSAGE,
  114. "Current Tag empty, this may mean NightlyStartTime / "
  115. "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
  116. "maybe you forgot to call ctest_start() before calling "
  117. "ctest_configure()." << std::endl);
  118. cmSystemTools::SetFatalErrorOccured();
  119. return false;
  120. }
  121. if( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
  122. ostr.str().c_str(), xofs, true) )
  123. {
  124. cmCTestLog(this->CTest, ERROR_MESSAGE,
  125. "Cannot create resulting XML file: " << ostr.str().c_str()
  126. << std::endl);
  127. return false;
  128. }
  129. this->CTest->AddSubmitFile(part, ostr.str().c_str());
  130. return true;
  131. }
  132. //----------------------------------------------------------------------
  133. bool cmCTestGenericHandler::StartLogFile(const char* name,
  134. cmGeneratedFileStream& xofs)
  135. {
  136. if ( !name )
  137. {
  138. cmCTestLog(this->CTest, ERROR_MESSAGE,
  139. "Cannot create log file without providing the name" << std::endl;);
  140. return false;
  141. }
  142. cmOStringStream ostr;
  143. ostr << "Last" << name;
  144. if ( this->SubmitIndex > 0 )
  145. {
  146. ostr << "_" << this->SubmitIndex;
  147. }
  148. if ( !this->CTest->GetCurrentTag().empty() )
  149. {
  150. ostr << "_" << this->CTest->GetCurrentTag();
  151. }
  152. ostr << ".log";
  153. // if this is a parallel subprocess then add the id to the
  154. // file so they don't clobber each other
  155. if(this->CTest->GetParallelSubprocess())
  156. {
  157. ostr << "." << this->CTest->GetParallelSubprocessId();
  158. }
  159. if( !this->CTest->OpenOutputFile("Temporary", ostr.str().c_str(), xofs) )
  160. {
  161. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create log file: "
  162. << ostr.str().c_str() << std::endl);
  163. return false;
  164. }
  165. return true;
  166. }