cmCTestStartCommand.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. }
  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. src_dir = args[cnt].c_str();
  54. cnt ++;
  55. if ( cnt < args.size() )
  56. {
  57. bld_dir = args[cnt].c_str();
  58. }
  59. }
  60. if ( !src_dir )
  61. {
  62. src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  63. }
  64. if ( !bld_dir)
  65. {
  66. bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  67. }
  68. if ( !src_dir )
  69. {
  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. {
  76. this->SetError("binary directory not specified. Specify binary directory "
  77. "as an argument or set CTEST_BINARY_DIRECTORY");
  78. return false;
  79. }
  80. cmSystemTools::AddKeepPath(src_dir);
  81. cmSystemTools::AddKeepPath(bld_dir);
  82. this->CTest->EmptyCTestConfiguration();
  83. std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
  84. std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
  85. this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str());
  86. this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str());
  87. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
  88. << smodel << std::endl
  89. << " Source directory: " << src_dir << std::endl
  90. << " Build directory: " << bld_dir << std::endl);
  91. const char* track = this->CTest->GetSpecificTrack();
  92. if ( track )
  93. {
  94. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  95. " Track: " << track << std::endl);
  96. }
  97. // Log startup actions.
  98. std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
  99. cmGeneratedFileStream ofs(startLogFile.c_str());
  100. if(!ofs)
  101. {
  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. {
  109. return false;
  110. }
  111. if(!cmSystemTools::FileIsDirectory(sourceDir.c_str()))
  112. {
  113. cmOStringStream e;
  114. e << "given source path\n"
  115. << " " << sourceDir << "\n"
  116. << "which is not an existing directory. "
  117. << "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
  118. this->SetError(e.str());
  119. return false;
  120. }
  121. this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
  122. this->CTest->SetSuppressUpdatingCTestConfiguration(true);
  123. int model = this->CTest->GetTestModelFromString(smodel);
  124. this->CTest->SetTestModel(model);
  125. this->CTest->SetProduceXML(true);
  126. return this->CTest->InitializeFromCommand(this);
  127. }
  128. //----------------------------------------------------------------------------
  129. bool cmCTestStartCommand::InitialCheckout(
  130. std::ostream& ofs, std::string const& sourceDir)
  131. {
  132. // Use the user-provided command to create the source tree.
  133. const char* initialCheckoutCommand
  134. = this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  135. if(!initialCheckoutCommand)
  136. {
  137. initialCheckoutCommand =
  138. this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  139. }
  140. if(initialCheckoutCommand)
  141. {
  142. // Use a generic VC object to run and log the command.
  143. cmCTestVC vc(this->CTest, ofs);
  144. vc.SetSourceDirectory(sourceDir);
  145. if(!vc.InitialCheckout(initialCheckoutCommand))
  146. {
  147. return false;
  148. }
  149. }
  150. return true;
  151. }