cmCTestHandlerCommand.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
  55. cmCTestGenericHandler* handler = this->InitializeHandler();
  56. if ( !handler )
  57. {
  58. cmCTestLog(this->CTest, ERROR_MESSAGE,
  59. "Cannot instantiate test handler " << this->GetName()
  60. << std::endl);
  61. return false;
  62. }
  63. handler->SetAppendXML(this->AppendXML);
  64. handler->PopulateCustomVectors(this->Makefile);
  65. if ( this->Values[ct_BUILD] )
  66. {
  67. this->CTest->SetCTestConfiguration("BuildDirectory",
  68. cmSystemTools::CollapseFullPath(
  69. this->Values[ct_BUILD]).c_str());
  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());
  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());
  94. }
  95. else
  96. {
  97. this->CTest->SetCTestConfiguration("SourceDirectory",
  98. cmSystemTools::CollapseFullPath(
  99. this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
  100. }
  101. if ( this->Values[ct_SUBMIT_INDEX] )
  102. {
  103. if ( this->CTest->GetDartVersion() <= 1 )
  104. {
  105. cmCTestLog(this->CTest, ERROR_MESSAGE,
  106. "Dart before version 2.0 does not support collecting submissions."
  107. << std::endl
  108. << "Please upgrade the server to Dart 2 or higher, or do not use "
  109. "SUBMIT_INDEX." << std::endl);
  110. }
  111. else
  112. {
  113. handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
  114. }
  115. }
  116. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  117. cmSystemTools::ChangeDirectory(
  118. this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
  119. int res = handler->ProcessHandler();
  120. if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
  121. {
  122. cmOStringStream str;
  123. str << res;
  124. this->Makefile->AddDefinition(
  125. this->Values[ct_RETURN_VALUE], str.str().c_str());
  126. }
  127. cmSystemTools::ChangeDirectory(current_dir.c_str());
  128. return true;
  129. }
  130. //----------------------------------------------------------------------------
  131. bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
  132. {
  133. // Look for non-value arguments common to all commands.
  134. if(arg == "APPEND")
  135. {
  136. this->ArgumentDoing = ArgumentDoingNone;
  137. this->AppendXML = true;
  138. return true;
  139. }
  140. // Check for a keyword in our argument/value table.
  141. for(unsigned int k=0; k < this->Arguments.size(); ++k)
  142. {
  143. if(this->Arguments[k] && arg == this->Arguments[k])
  144. {
  145. this->ArgumentDoing = ArgumentDoingKeyword;
  146. this->ArgumentIndex = k;
  147. return true;
  148. }
  149. }
  150. return false;
  151. }
  152. //----------------------------------------------------------------------------
  153. bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
  154. {
  155. if(this->ArgumentDoing == ArgumentDoingKeyword)
  156. {
  157. this->ArgumentDoing = ArgumentDoingNone;
  158. unsigned int k = this->ArgumentIndex;
  159. if(this->Values[k])
  160. {
  161. cmOStringStream e;
  162. e << "Called with more than one value for " << this->Arguments[k];
  163. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  164. this->ArgumentDoing = ArgumentDoingError;
  165. return true;
  166. }
  167. this->Values[k] = arg.c_str();
  168. cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
  169. << " to " << arg << "\n");
  170. return true;
  171. }
  172. return false;
  173. }