cmCTestHandlerCommand.cxx 6.2 KB

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