cmCTestStartCommand.cxx 4.6 KB

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