cmCTestStartCommand.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestStartCommand.h"
  4. #include <cstddef>
  5. #include <sstream>
  6. #include "cmCTest.h"
  7. #include "cmCTestVC.h"
  8. #include "cmGeneratedFileStream.h"
  9. #include "cmMakefile.h"
  10. #include "cmSystemTools.h"
  11. class cmExecutionStatus;
  12. cmCTestStartCommand::cmCTestStartCommand()
  13. {
  14. this->CreateNewTag = true;
  15. this->Quiet = false;
  16. }
  17. bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
  18. cmExecutionStatus& /*unused*/)
  19. {
  20. if (args.empty()) {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. size_t cnt = 0;
  25. const char* smodel = nullptr;
  26. const char* src_dir = nullptr;
  27. const char* bld_dir = nullptr;
  28. while (cnt < args.size()) {
  29. if (args[cnt] == "GROUP" || args[cnt] == "TRACK") {
  30. cnt++;
  31. if (cnt >= args.size() || args[cnt] == "APPEND" ||
  32. args[cnt] == "QUIET") {
  33. std::ostringstream e;
  34. e << args[cnt - 1] << " argument missing group name";
  35. this->SetError(e.str());
  36. return false;
  37. }
  38. this->CTest->SetSpecificGroup(args[cnt].c_str());
  39. cnt++;
  40. } else if (args[cnt] == "APPEND") {
  41. cnt++;
  42. this->CreateNewTag = false;
  43. } else if (args[cnt] == "QUIET") {
  44. cnt++;
  45. this->Quiet = true;
  46. } else if (!smodel) {
  47. smodel = args[cnt].c_str();
  48. cnt++;
  49. } else if (!src_dir) {
  50. src_dir = args[cnt].c_str();
  51. cnt++;
  52. } else if (!bld_dir) {
  53. bld_dir = args[cnt].c_str();
  54. cnt++;
  55. } else {
  56. this->SetError("Too many arguments");
  57. return false;
  58. }
  59. }
  60. if (!src_dir) {
  61. src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  62. }
  63. if (!bld_dir) {
  64. bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  65. }
  66. if (!src_dir) {
  67. this->SetError("source directory not specified. Specify source directory "
  68. "as an argument or set CTEST_SOURCE_DIRECTORY");
  69. return false;
  70. }
  71. if (!bld_dir) {
  72. this->SetError("binary directory not specified. Specify binary directory "
  73. "as an argument or set CTEST_BINARY_DIRECTORY");
  74. return false;
  75. }
  76. if (!smodel && this->CreateNewTag) {
  77. this->SetError("no test model specified and APPEND not specified. Specify "
  78. "either a test model or the APPEND argument");
  79. return false;
  80. }
  81. cmSystemTools::AddKeepPath(src_dir);
  82. cmSystemTools::AddKeepPath(bld_dir);
  83. this->CTest->EmptyCTestConfiguration();
  84. std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
  85. std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
  86. this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str(),
  87. this->Quiet);
  88. this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str(),
  89. this->Quiet);
  90. if (smodel) {
  91. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  92. "Run dashboard with model "
  93. << smodel << std::endl
  94. << " Source directory: " << src_dir << std::endl
  95. << " Build directory: " << bld_dir << std::endl,
  96. this->Quiet);
  97. } else {
  98. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  99. "Run dashboard with "
  100. "to-be-determined model"
  101. << std::endl
  102. << " Source directory: " << src_dir << std::endl
  103. << " Build directory: " << bld_dir << std::endl,
  104. this->Quiet);
  105. }
  106. const char* group = this->CTest->GetSpecificGroup();
  107. if (group) {
  108. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  109. " Group: " << group << std::endl, this->Quiet);
  110. }
  111. // Log startup actions.
  112. std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
  113. cmGeneratedFileStream ofs(startLogFile);
  114. if (!ofs) {
  115. cmCTestLog(this->CTest, ERROR_MESSAGE,
  116. "Cannot create log file: LastStart.log" << std::endl);
  117. return false;
  118. }
  119. // Make sure the source directory exists.
  120. if (!this->InitialCheckout(ofs, sourceDir)) {
  121. return false;
  122. }
  123. if (!cmSystemTools::FileIsDirectory(sourceDir)) {
  124. std::ostringstream e;
  125. e << "given source path\n"
  126. << " " << sourceDir << "\n"
  127. << "which is not an existing directory. "
  128. << "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
  129. this->SetError(e.str());
  130. return false;
  131. }
  132. this->CTest->SetRunCurrentScript(false);
  133. this->CTest->SetSuppressUpdatingCTestConfiguration(true);
  134. int model;
  135. if (smodel) {
  136. model = cmCTest::GetTestModelFromString(smodel);
  137. } else {
  138. model = cmCTest::UNKNOWN;
  139. }
  140. this->CTest->SetTestModel(model);
  141. this->CTest->SetProduceXML(true);
  142. return this->CTest->InitializeFromCommand(this);
  143. }
  144. bool cmCTestStartCommand::InitialCheckout(std::ostream& ofs,
  145. std::string const& sourceDir)
  146. {
  147. // Use the user-provided command to create the source tree.
  148. const char* initialCheckoutCommand =
  149. this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  150. if (!initialCheckoutCommand) {
  151. initialCheckoutCommand =
  152. this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  153. }
  154. if (initialCheckoutCommand) {
  155. // Use a generic VC object to run and log the command.
  156. cmCTestVC vc(this->CTest, ofs);
  157. vc.SetSourceDirectory(sourceDir);
  158. if (!vc.InitialCheckout(initialCheckoutCommand)) {
  159. return false;
  160. }
  161. }
  162. return true;
  163. }