cmCTestStartCommand.cxx 4.9 KB

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