cmCTestStartCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "cmCTestStartCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestVC.h"
  13. #include "cmGeneratedFileStream.h"
  14. #include "cmMakefile.h"
  15. #include "cmSystemTools.h"
  16. #include <sstream>
  17. #include <stddef.h>
  18. class cmExecutionStatus;
  19. cmCTestStartCommand::cmCTestStartCommand()
  20. {
  21. this->CreateNewTag = true;
  22. this->Quiet = false;
  23. }
  24. bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
  25. cmExecutionStatus& /*unused*/)
  26. {
  27. if (args.empty()) {
  28. this->SetError("called with incorrect number of arguments");
  29. return false;
  30. }
  31. size_t cnt = 0;
  32. const char* smodel = args[cnt].c_str();
  33. const char* src_dir = CM_NULLPTR;
  34. const char* bld_dir = CM_NULLPTR;
  35. cnt++;
  36. this->CTest->SetSpecificTrack(CM_NULLPTR);
  37. if (cnt < args.size() - 1) {
  38. if (args[cnt] == "TRACK") {
  39. cnt++;
  40. this->CTest->SetSpecificTrack(args[cnt].c_str());
  41. cnt++;
  42. }
  43. }
  44. if (cnt < args.size()) {
  45. if (args[cnt] == "APPEND") {
  46. cnt++;
  47. this->CreateNewTag = false;
  48. }
  49. }
  50. if (cnt < args.size()) {
  51. if (args[cnt] == "QUIET") {
  52. cnt++;
  53. this->Quiet = true;
  54. }
  55. }
  56. if (cnt < args.size()) {
  57. src_dir = args[cnt].c_str();
  58. cnt++;
  59. if (cnt < args.size()) {
  60. bld_dir = args[cnt].c_str();
  61. }
  62. }
  63. if (!src_dir) {
  64. src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  65. }
  66. if (!bld_dir) {
  67. bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  68. }
  69. if (!src_dir) {
  70. this->SetError("source directory not specified. Specify source directory "
  71. "as an argument or set CTEST_SOURCE_DIRECTORY");
  72. return false;
  73. }
  74. if (!bld_dir) {
  75. this->SetError("binary directory not specified. Specify binary directory "
  76. "as an argument or set CTEST_BINARY_DIRECTORY");
  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. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
  89. << smodel << std::endl
  90. << " Source directory: " << src_dir << std::endl
  91. << " Build directory: " << bld_dir << std::endl,
  92. this->Quiet);
  93. const char* track = this->CTest->GetSpecificTrack();
  94. if (track) {
  95. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  96. " Track: " << track << std::endl, this->Quiet);
  97. }
  98. // Log startup actions.
  99. std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
  100. cmGeneratedFileStream ofs(startLogFile.c_str());
  101. if (!ofs) {
  102. cmCTestLog(this->CTest, ERROR_MESSAGE,
  103. "Cannot create log file: LastStart.log" << std::endl);
  104. return false;
  105. }
  106. // Make sure the source directory exists.
  107. if (!this->InitialCheckout(ofs, sourceDir)) {
  108. return false;
  109. }
  110. if (!cmSystemTools::FileIsDirectory(sourceDir)) {
  111. std::ostringstream e;
  112. e << "given source path\n"
  113. << " " << sourceDir << "\n"
  114. << "which is not an existing directory. "
  115. << "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
  116. this->SetError(e.str());
  117. return false;
  118. }
  119. this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
  120. this->CTest->SetSuppressUpdatingCTestConfiguration(true);
  121. int model = this->CTest->GetTestModelFromString(smodel);
  122. this->CTest->SetTestModel(model);
  123. this->CTest->SetProduceXML(true);
  124. return this->CTest->InitializeFromCommand(this);
  125. }
  126. bool cmCTestStartCommand::InitialCheckout(std::ostream& ofs,
  127. std::string const& sourceDir)
  128. {
  129. // Use the user-provided command to create the source tree.
  130. const char* initialCheckoutCommand =
  131. this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  132. if (!initialCheckoutCommand) {
  133. initialCheckoutCommand =
  134. this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  135. }
  136. if (initialCheckoutCommand) {
  137. // Use a generic VC object to run and log the command.
  138. cmCTestVC vc(this->CTest, ofs);
  139. vc.SetSourceDirectory(sourceDir);
  140. if (!vc.InitialCheckout(initialCheckoutCommand)) {
  141. return false;
  142. }
  143. }
  144. return true;
  145. }