cmCTestStartCommand.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 "cmLocalGenerator.h"
  13. #include "cmGlobalGenerator.h"
  14. #include "cmCTestVC.h"
  15. #include "cmGeneratedFileStream.h"
  16. cmCTestStartCommand::cmCTestStartCommand()
  17. {
  18. this->CreateNewTag = true;
  19. this->Quiet = false;
  20. }
  21. bool cmCTestStartCommand
  22. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  23. {
  24. if (args.size() < 1)
  25. {
  26. this->SetError("called with incorrect number of arguments");
  27. return false;
  28. }
  29. size_t cnt = 0;
  30. const char* smodel = args[cnt].c_str();
  31. const char* src_dir = 0;
  32. const char* bld_dir = 0;
  33. cnt++;
  34. this->CTest->SetSpecificTrack(0);
  35. if ( cnt < args.size() -1 )
  36. {
  37. if ( args[cnt] == "TRACK" )
  38. {
  39. cnt ++;
  40. this->CTest->SetSpecificTrack(args[cnt].c_str());
  41. cnt ++;
  42. }
  43. }
  44. if (cnt < args.size())
  45. {
  46. if (args[cnt] == "APPEND")
  47. {
  48. cnt ++;
  49. this->CreateNewTag = false;
  50. }
  51. }
  52. if (cnt < args.size())
  53. {
  54. if (args[cnt] == "QUIET")
  55. {
  56. cnt ++;
  57. this->Quiet = true;
  58. }
  59. }
  60. if ( cnt < args.size() )
  61. {
  62. src_dir = args[cnt].c_str();
  63. cnt ++;
  64. if ( cnt < args.size() )
  65. {
  66. bld_dir = args[cnt].c_str();
  67. }
  68. }
  69. if ( !src_dir )
  70. {
  71. src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  72. }
  73. if ( !bld_dir)
  74. {
  75. bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  76. }
  77. if ( !src_dir )
  78. {
  79. this->SetError("source directory not specified. Specify source directory "
  80. "as an argument or set CTEST_SOURCE_DIRECTORY");
  81. return false;
  82. }
  83. if ( !bld_dir)
  84. {
  85. this->SetError("binary directory not specified. Specify binary directory "
  86. "as an argument or set CTEST_BINARY_DIRECTORY");
  87. return false;
  88. }
  89. cmSystemTools::AddKeepPath(src_dir);
  90. cmSystemTools::AddKeepPath(bld_dir);
  91. this->CTest->EmptyCTestConfiguration();
  92. std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
  93. std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
  94. this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str(),
  95. this->Quiet);
  96. this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str(),
  97. this->Quiet);
  98. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
  99. << smodel << std::endl
  100. << " Source directory: " << src_dir << std::endl
  101. << " Build directory: " << bld_dir << std::endl, this->Quiet);
  102. const char* track = this->CTest->GetSpecificTrack();
  103. if ( track )
  104. {
  105. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  106. " Track: " << track << std::endl, this->Quiet);
  107. }
  108. // Log startup actions.
  109. std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
  110. cmGeneratedFileStream ofs(startLogFile.c_str());
  111. if(!ofs)
  112. {
  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. {
  120. return false;
  121. }
  122. if(!cmSystemTools::FileIsDirectory(sourceDir))
  123. {
  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->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
  133. this->CTest->SetSuppressUpdatingCTestConfiguration(true);
  134. int model = this->CTest->GetTestModelFromString(smodel);
  135. this->CTest->SetTestModel(model);
  136. this->CTest->SetProduceXML(true);
  137. return this->CTest->InitializeFromCommand(this);
  138. }
  139. //----------------------------------------------------------------------------
  140. bool cmCTestStartCommand::InitialCheckout(
  141. std::ostream& ofs, std::string const& sourceDir)
  142. {
  143. // Use the user-provided command to create the source tree.
  144. const char* initialCheckoutCommand
  145. = this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  146. if(!initialCheckoutCommand)
  147. {
  148. initialCheckoutCommand =
  149. this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  150. }
  151. if(initialCheckoutCommand)
  152. {
  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. {
  158. return false;
  159. }
  160. }
  161. return true;
  162. }