cmCTestStartCommand.cxx 5.5 KB

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