cmCTestHandlerCommand.cxx 6.0 KB

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