cmCTestGenericHandler.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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->Options.clear();
  72. t_StringToString::iterator it;
  73. for ( it = this->PersistentOptions.begin();
  74. it != this->PersistentOptions.end();
  75. ++ it )
  76. {
  77. this->Options[it->first.c_str()] = it->second.c_str();
  78. }
  79. }
  80. //----------------------------------------------------------------------
  81. const char* cmCTestGenericHandler::GetOption(const char* op)
  82. {
  83. cmCTestGenericHandler::t_StringToString::iterator remit
  84. = this->Options.find(op);
  85. if ( remit == this->Options.end() )
  86. {
  87. return 0;
  88. }
  89. return remit->second.c_str();
  90. }
  91. //----------------------------------------------------------------------
  92. bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
  93. const char* name,
  94. cmGeneratedFileStream& xofs)
  95. {
  96. if ( !name )
  97. {
  98. cmCTestLog(this->CTest, ERROR_MESSAGE,
  99. "Cannot create resulting XML file without providing the name"
  100. << std::endl;);
  101. return false;
  102. }
  103. cmOStringStream ostr;
  104. ostr << name;
  105. if ( this->SubmitIndex > 0 )
  106. {
  107. ostr << "_" << this->SubmitIndex;
  108. }
  109. ostr << ".xml";
  110. if(this->CTest->GetCurrentTag().empty())
  111. {
  112. cmCTestLog(this->CTest, ERROR_MESSAGE,
  113. "Current Tag empty, this may mean NightlyStartTime / "
  114. "CTEST_NIGHTLY_START_TIME was not set correctly. Or "
  115. "maybe you forgot to call ctest_start() before calling "
  116. "ctest_configure()." << std::endl);
  117. cmSystemTools::SetFatalErrorOccured();
  118. return false;
  119. }
  120. if( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
  121. ostr.str().c_str(), xofs, true) )
  122. {
  123. cmCTestLog(this->CTest, ERROR_MESSAGE,
  124. "Cannot create resulting XML file: " << ostr.str().c_str()
  125. << std::endl);
  126. return false;
  127. }
  128. this->CTest->AddSubmitFile(part, ostr.str().c_str());
  129. return true;
  130. }
  131. //----------------------------------------------------------------------
  132. bool cmCTestGenericHandler::StartLogFile(const char* name,
  133. cmGeneratedFileStream& xofs)
  134. {
  135. if ( !name )
  136. {
  137. cmCTestLog(this->CTest, ERROR_MESSAGE,
  138. "Cannot create log file without providing the name" << std::endl;);
  139. return false;
  140. }
  141. cmOStringStream ostr;
  142. ostr << "Last" << name;
  143. if ( this->SubmitIndex > 0 )
  144. {
  145. ostr << "_" << this->SubmitIndex;
  146. }
  147. if ( !this->CTest->GetCurrentTag().empty() )
  148. {
  149. ostr << "_" << this->CTest->GetCurrentTag();
  150. }
  151. ostr << ".log";
  152. // if this is a parallel subprocess then add the id to the
  153. // file so they don't clobber each other
  154. if(this->CTest->GetParallelSubprocess())
  155. {
  156. ostr << "." << this->CTest->GetParallelSubprocessId();
  157. }
  158. if( !this->CTest->OpenOutputFile("Temporary", ostr.str().c_str(), xofs) )
  159. {
  160. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create log file: "
  161. << ostr.str().c_str() << std::endl);
  162. return false;
  163. }
  164. return true;
  165. }