cmCTestHandlerCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 "cmCTestHandlerCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. cmCTestHandlerCommand::cmCTestHandlerCommand()
  17. {
  18. const size_t INIT_SIZE = 100;
  19. size_t cc;
  20. this->Arguments.reserve(INIT_SIZE);
  21. for ( cc = 0; cc < INIT_SIZE; ++ cc )
  22. {
  23. this->Arguments.push_back(0);
  24. }
  25. this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
  26. this->Arguments[ct_SOURCE] = "SOURCE";
  27. this->Arguments[ct_BUILD] = "BUILD";
  28. this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
  29. this->Last = ct_LAST;
  30. }
  31. bool cmCTestHandlerCommand
  32. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  33. {
  34. if ( !this->ProcessArguments(args, (unsigned int)this->Last,
  35. &*this->Arguments.begin(),this->Values) )
  36. {
  37. return false;
  38. }
  39. cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
  40. cmCTestGenericHandler* handler = this->InitializeHandler();
  41. if ( !handler )
  42. {
  43. cmCTestLog(this->CTest, ERROR_MESSAGE,
  44. "Cannot instantiate test handler " << this->GetName()
  45. << std::endl);
  46. return false;
  47. }
  48. handler->PopulateCustomVectors(this->Makefile);
  49. if ( this->Values[ct_BUILD] )
  50. {
  51. this->CTest->SetCTestConfiguration("BuildDirectory",
  52. cmSystemTools::CollapseFullPath(
  53. this->Values[ct_BUILD]).c_str());
  54. }
  55. else
  56. {
  57. const char* bdir =
  58. this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
  59. if(bdir)
  60. {
  61. this->
  62. CTest->SetCTestConfiguration("BuildDirectory",
  63. cmSystemTools::CollapseFullPath(bdir).c_str());
  64. }
  65. else
  66. {
  67. cmCTestLog(this->CTest, ERROR_MESSAGE,
  68. "CTEST_BINARY_DIRECTORY not set" << std::endl;);
  69. }
  70. }
  71. if ( this->Values[ct_SOURCE] )
  72. {
  73. cmCTestLog(this->CTest, DEBUG,
  74. "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
  75. this->CTest->SetCTestConfiguration("SourceDirectory",
  76. cmSystemTools::CollapseFullPath(
  77. this->Values[ct_SOURCE]).c_str());
  78. }
  79. else
  80. {
  81. this->CTest->SetCTestConfiguration("SourceDirectory",
  82. cmSystemTools::CollapseFullPath(
  83. this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
  84. }
  85. if ( this->Values[ct_SUBMIT_INDEX] )
  86. {
  87. if ( this->CTest->GetDartVersion() <= 1 )
  88. {
  89. cmCTestLog(this->CTest, ERROR_MESSAGE,
  90. "Dart before version 2.0 does not support collecting submissions."
  91. << std::endl
  92. << "Please upgrade the server to Dart 2 or higher, or do not use "
  93. "SUBMIT_INDEX." << std::endl);
  94. }
  95. else
  96. {
  97. handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
  98. }
  99. }
  100. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  101. cmSystemTools::ChangeDirectory(
  102. this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
  103. int res = handler->ProcessHandler();
  104. if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
  105. {
  106. cmOStringStream str;
  107. str << res;
  108. this->Makefile->AddDefinition(
  109. this->Values[ct_RETURN_VALUE], str.str().c_str());
  110. }
  111. cmSystemTools::ChangeDirectory(current_dir.c_str());
  112. return true;
  113. }
  114. bool cmCTestHandlerCommand::ProcessArguments(
  115. std::vector<std::string> const& args, int last, const char** strings,
  116. std::vector<const char*>& values)
  117. {
  118. int state = 0;
  119. int cc;
  120. values.resize(last);
  121. for ( cc = 0; cc < last; ++ cc )
  122. {
  123. values[cc] = 0;
  124. }
  125. for(size_t i=0; i < args.size(); ++i)
  126. {
  127. if ( state > 0 && state < last )
  128. {
  129. values[state] = args[i].c_str();
  130. cmCTestLog(this->CTest, DEBUG, "Set " << strings[state] << " to "
  131. << args[i].c_str() << std::endl);
  132. state = 0;
  133. }
  134. else
  135. {
  136. bool found = false;
  137. for ( cc = 0; cc < last; ++ cc )
  138. {
  139. if ( strings[cc] && args[i] == strings[cc] )
  140. {
  141. state = cc;
  142. if ( values[state] )
  143. {
  144. cmOStringStream ostr;
  145. ostr << "called with incorrect number of arguments. "
  146. << strings[state] << " specified twice.";
  147. this->SetError(ostr.str().c_str());
  148. return false;
  149. }
  150. found = true;
  151. break;
  152. }
  153. }
  154. if ( !found )
  155. {
  156. cmOStringStream str;
  157. str
  158. << "called with incorrect number of arguments. Extra argument is: "
  159. << args[i].c_str() << ".";
  160. this->SetError(str.str().c_str());
  161. return false;
  162. }
  163. }
  164. }
  165. return true;
  166. }