cmCTestGenericHandler.cxx 4.6 KB

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