cmCTestHandlerCommand.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 "cmCTestHandlerCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. cmCTestHandlerCommand::cmCTestHandlerCommand()
  14. {
  15. const size_t INIT_SIZE = 100;
  16. size_t cc;
  17. this->Arguments.reserve(INIT_SIZE);
  18. for ( cc = 0; cc < INIT_SIZE; ++ cc )
  19. {
  20. this->Arguments.push_back(0);
  21. }
  22. this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
  23. this->Arguments[ct_SOURCE] = "SOURCE";
  24. this->Arguments[ct_BUILD] = "BUILD";
  25. this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
  26. this->Last = ct_LAST;
  27. this->AppendXML = false;
  28. this->Quiet = false;
  29. }
  30. bool cmCTestHandlerCommand
  31. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  32. {
  33. // Allocate space for argument values.
  34. this->Values.clear();
  35. this->Values.resize(this->Last, 0);
  36. // Process input arguments.
  37. this->ArgumentDoing = ArgumentDoingNone;
  38. for(unsigned int i=0; i < args.size(); ++i)
  39. {
  40. // Check this argument.
  41. if(!this->CheckArgumentKeyword(args[i]) &&
  42. !this->CheckArgumentValue(args[i]))
  43. {
  44. std::ostringstream e;
  45. e << "called with unknown argument \"" << args[i] << "\".";
  46. this->SetError(e.str());
  47. return false;
  48. }
  49. // Quit if an argument is invalid.
  50. if(this->ArgumentDoing == ArgumentDoingError)
  51. {
  52. return false;
  53. }
  54. }
  55. // Set the config type of this ctest to the current value of the
  56. // CTEST_CONFIGURATION_TYPE script variable if it is defined.
  57. // The current script value trumps the -C argument on the command
  58. // line.
  59. const char* ctestConfigType =
  60. this->Makefile->GetDefinition("CTEST_CONFIGURATION_TYPE");
  61. if (ctestConfigType)
  62. {
  63. this->CTest->SetConfigType(ctestConfigType);
  64. }
  65. if ( this->Values[ct_BUILD] )
  66. {
  67. this->CTest->SetCTestConfiguration("BuildDirectory",
  68. cmSystemTools::CollapseFullPath(
  69. this->Values[ct_BUILD]).c_str(), this->Quiet);
  70. }
  71. else
  72. {
  73. const char* bdir =
  74. this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
  75. if(bdir)
  76. {
  77. this->
  78. CTest->SetCTestConfiguration("BuildDirectory",
  79. cmSystemTools::CollapseFullPath(bdir).c_str(), this->Quiet);
  80. }
  81. else
  82. {
  83. cmCTestLog(this->CTest, ERROR_MESSAGE,
  84. "CTEST_BINARY_DIRECTORY not set" << std::endl;);
  85. }
  86. }
  87. if ( this->Values[ct_SOURCE] )
  88. {
  89. cmCTestLog(this->CTest, DEBUG,
  90. "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
  91. this->CTest->SetCTestConfiguration("SourceDirectory",
  92. cmSystemTools::CollapseFullPath(
  93. this->Values[ct_SOURCE]).c_str(), this->Quiet);
  94. }
  95. else
  96. {
  97. this->CTest->SetCTestConfiguration("SourceDirectory",
  98. cmSystemTools::CollapseFullPath(
  99. this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY")).c_str(),
  100. this->Quiet);
  101. }
  102. if(const char* changeId =
  103. this->Makefile->GetDefinition("CTEST_CHANGE_ID"))
  104. {
  105. this->CTest->SetCTestConfiguration("ChangeId", changeId, this->Quiet);
  106. }
  107. cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
  108. cmCTestGenericHandler* handler = this->InitializeHandler();
  109. if ( !handler )
  110. {
  111. cmCTestLog(this->CTest, ERROR_MESSAGE,
  112. "Cannot instantiate test handler " << this->GetName()
  113. << std::endl);
  114. return false;
  115. }
  116. handler->SetAppendXML(this->AppendXML);
  117. handler->PopulateCustomVectors(this->Makefile);
  118. if ( this->Values[ct_SUBMIT_INDEX] )
  119. {
  120. if(!this->CTest->GetDropSiteCDash() && this->CTest->GetDartVersion() <= 1)
  121. {
  122. cmCTestLog(this->CTest, ERROR_MESSAGE,
  123. "Dart before version 2.0 does not support collecting submissions."
  124. << std::endl
  125. << "Please upgrade the server to Dart 2 or higher, or do not use "
  126. "SUBMIT_INDEX." << std::endl);
  127. }
  128. else
  129. {
  130. handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
  131. }
  132. }
  133. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  134. cmSystemTools::ChangeDirectory(
  135. this->CTest->GetCTestConfiguration("BuildDirectory"));
  136. int res = handler->ProcessHandler();
  137. if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
  138. {
  139. std::ostringstream str;
  140. str << res;
  141. this->Makefile->AddDefinition(
  142. this->Values[ct_RETURN_VALUE], str.str().c_str());
  143. }
  144. cmSystemTools::ChangeDirectory(current_dir);
  145. return true;
  146. }
  147. //----------------------------------------------------------------------------
  148. bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
  149. {
  150. // Look for non-value arguments common to all commands.
  151. if(arg == "APPEND")
  152. {
  153. this->ArgumentDoing = ArgumentDoingNone;
  154. this->AppendXML = true;
  155. return true;
  156. }
  157. if(arg == "QUIET")
  158. {
  159. this->ArgumentDoing = ArgumentDoingNone;
  160. this->Quiet = true;
  161. return true;
  162. }
  163. // Check for a keyword in our argument/value table.
  164. for(unsigned int k=0; k < this->Arguments.size(); ++k)
  165. {
  166. if(this->Arguments[k] && arg == this->Arguments[k])
  167. {
  168. this->ArgumentDoing = ArgumentDoingKeyword;
  169. this->ArgumentIndex = k;
  170. return true;
  171. }
  172. }
  173. return false;
  174. }
  175. //----------------------------------------------------------------------------
  176. bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
  177. {
  178. if(this->ArgumentDoing == ArgumentDoingKeyword)
  179. {
  180. this->ArgumentDoing = ArgumentDoingNone;
  181. unsigned int k = this->ArgumentIndex;
  182. if(this->Values[k])
  183. {
  184. std::ostringstream e;
  185. e << "Called with more than one value for " << this->Arguments[k];
  186. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  187. this->ArgumentDoing = ArgumentDoingError;
  188. return true;
  189. }
  190. this->Values[k] = arg.c_str();
  191. cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
  192. << " to " << arg << "\n");
  193. return true;
  194. }
  195. return false;
  196. }