cmCTestStartCommand.cxx 5.0 KB

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