cmCTestHandlerCommand.cxx 5.7 KB

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