cmCTestStartCommand.cxx 5.5 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. #include "cmValue.h"
  12. class cmExecutionStatus;
  13. cmCTestStartCommand::cmCTestStartCommand()
  14. {
  15. this->CreateNewTag = true;
  16. this->Quiet = false;
  17. }
  18. bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
  19. cmExecutionStatus& /*unused*/)
  20. {
  21. if (args.empty()) {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. size_t cnt = 0;
  26. const char* smodel = nullptr;
  27. cmValue src_dir;
  28. cmValue bld_dir;
  29. while (cnt < args.size()) {
  30. if (args[cnt] == "GROUP" || args[cnt] == "TRACK") {
  31. cnt++;
  32. if (cnt >= args.size() || args[cnt] == "APPEND" ||
  33. args[cnt] == "QUIET") {
  34. std::ostringstream e;
  35. e << args[cnt - 1] << " argument missing group name";
  36. this->SetError(e.str());
  37. return false;
  38. }
  39. this->CTest->SetSpecificGroup(args[cnt].c_str());
  40. cnt++;
  41. } else if (args[cnt] == "APPEND") {
  42. cnt++;
  43. this->CreateNewTag = false;
  44. } else if (args[cnt] == "QUIET") {
  45. cnt++;
  46. this->Quiet = true;
  47. } else if (!smodel) {
  48. smodel = args[cnt].c_str();
  49. cnt++;
  50. } else if (!src_dir) {
  51. src_dir = cmValue(args[cnt]);
  52. cnt++;
  53. } else if (!bld_dir) {
  54. bld_dir = cmValue(args[cnt]);
  55. cnt++;
  56. } else {
  57. this->SetError("Too many arguments");
  58. return false;
  59. }
  60. }
  61. if (!src_dir) {
  62. src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  63. }
  64. if (!bld_dir) {
  65. bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  66. }
  67. if (!src_dir) {
  68. this->SetError("source directory not specified. Specify source directory "
  69. "as an argument or set CTEST_SOURCE_DIRECTORY");
  70. return false;
  71. }
  72. if (!bld_dir) {
  73. this->SetError("binary directory not specified. Specify binary directory "
  74. "as an argument or set CTEST_BINARY_DIRECTORY");
  75. return false;
  76. }
  77. if (!smodel && this->CreateNewTag) {
  78. this->SetError("no test model specified and APPEND not specified. Specify "
  79. "either a test model or the APPEND argument");
  80. return false;
  81. }
  82. cmSystemTools::AddKeepPath(*src_dir);
  83. cmSystemTools::AddKeepPath(*bld_dir);
  84. this->CTest->EmptyCTestConfiguration();
  85. std::string sourceDir = cmSystemTools::CollapseFullPath(*src_dir);
  86. std::string binaryDir = cmSystemTools::CollapseFullPath(*bld_dir);
  87. this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir,
  88. this->Quiet);
  89. this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir, 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. cmValue 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. }