cmCTestSubmitCommand.cxx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 "cmCTestSubmitCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmCTestSubmitHandler.h"
  14. cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
  15. {
  16. const char* ctestDropMethod
  17. = this->Makefile->GetDefinition("CTEST_DROP_METHOD");
  18. const char* ctestDropSite
  19. = this->Makefile->GetDefinition("CTEST_DROP_SITE");
  20. const char* ctestDropLocation
  21. = this->Makefile->GetDefinition("CTEST_DROP_LOCATION");
  22. const char* ctestTriggerSite
  23. = this->Makefile->GetDefinition("CTEST_TRIGGER_SITE");
  24. bool ctestDropSiteCDash
  25. = this->Makefile->IsOn("CTEST_DROP_SITE_CDASH");
  26. if ( !ctestDropMethod )
  27. {
  28. ctestDropMethod = "http";
  29. }
  30. if ( !ctestDropSite )
  31. {
  32. // error: CDash requires CTEST_DROP_SITE definition
  33. // in CTestConfig.cmake
  34. }
  35. if ( !ctestDropLocation )
  36. {
  37. // error: CDash requires CTEST_DROP_LOCATION definition
  38. // in CTestConfig.cmake
  39. }
  40. this->CTest->SetCTestConfiguration("DropMethod", ctestDropMethod);
  41. this->CTest->SetCTestConfiguration("DropSite", ctestDropSite);
  42. this->CTest->SetCTestConfiguration("DropLocation", ctestDropLocation);
  43. this->CTest->SetCTestConfiguration("IsCDash",
  44. ctestDropSiteCDash ? "TRUE" : "FALSE");
  45. // Only propagate TriggerSite for non-CDash projects:
  46. //
  47. if ( !ctestDropSiteCDash )
  48. {
  49. this->CTest->SetCTestConfiguration("TriggerSite", ctestTriggerSite);
  50. }
  51. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  52. "CurlOptions", "CTEST_CURL_OPTIONS");
  53. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  54. "DropSiteUser", "CTEST_DROP_SITE_USER");
  55. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  56. "DropSitePassword", "CTEST_DROP_SITE_PASSWORD");
  57. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  58. "ScpCommand", "CTEST_SCP_COMMAND");
  59. const char* notesFilesVariable
  60. = this->Makefile->GetDefinition("CTEST_NOTES_FILES");
  61. if (notesFilesVariable)
  62. {
  63. std::vector<std::string> notesFiles;
  64. std::vector<cmStdString> newNotesFiles;
  65. cmSystemTools::ExpandListArgument(notesFilesVariable,notesFiles);
  66. std::vector<std::string>::iterator it;
  67. for ( it = notesFiles.begin();
  68. it != notesFiles.end();
  69. ++ it )
  70. {
  71. newNotesFiles.push_back(*it);
  72. }
  73. this->CTest->GenerateNotesFile(newNotesFiles);
  74. }
  75. const char* extraFilesVariable
  76. = this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  77. if (extraFilesVariable)
  78. {
  79. std::vector<std::string> extraFiles;
  80. std::vector<cmStdString> newExtraFiles;
  81. cmSystemTools::ExpandListArgument(extraFilesVariable,extraFiles);
  82. std::vector<std::string>::iterator it;
  83. for ( it = extraFiles.begin();
  84. it != extraFiles.end();
  85. ++ it )
  86. {
  87. newExtraFiles.push_back(*it);
  88. }
  89. if ( !this->CTest->SubmitExtraFiles(newExtraFiles))
  90. {
  91. this->SetError("problem submitting extra files.");
  92. return 0;
  93. }
  94. }
  95. cmCTestGenericHandler* handler
  96. = this->CTest->GetInitializedHandler("submit");
  97. if ( !handler )
  98. {
  99. this->SetError("internal CTest error. Cannot instantiate submit handler");
  100. return 0;
  101. }
  102. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  103. //
  104. // If FILES are given, but not PARTS, only the FILES are submitted
  105. // and *no* PARTS are submitted.
  106. // (This is why we select the empty "noParts" set in the
  107. // FilesMentioned block below...)
  108. //
  109. // If PARTS are given, only the selected PARTS are submitted.
  110. //
  111. // If both PARTS and FILES are given, only the selected PARTS *and*
  112. // all the given FILES are submitted.
  113. // If given explicit FILES to submit, pass them to the handler.
  114. //
  115. if(this->FilesMentioned)
  116. {
  117. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  118. // were also explicitly mentioned, they will be selected below...
  119. // But FILES with no PARTS mentioned should just submit the FILES
  120. // without any of the default parts.
  121. //
  122. std::set<cmCTest::Part> noParts;
  123. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(noParts);
  124. static_cast<cmCTestSubmitHandler*>(handler)->SelectFiles(this->Files);
  125. }
  126. // If a PARTS option was given, select only the named parts for submission.
  127. //
  128. if(this->PartsMentioned)
  129. {
  130. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(this->Parts);
  131. }
  132. static_cast<cmCTestSubmitHandler*>(handler)->SetOption("RetryTime",
  133. this->RetryDelay.c_str());
  134. static_cast<cmCTestSubmitHandler*>(handler)->SetOption("RetryCount",
  135. this->RetryCount.c_str());
  136. return handler;
  137. }
  138. //----------------------------------------------------------------------------
  139. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  140. {
  141. // Look for arguments specific to this command.
  142. if(arg == "PARTS")
  143. {
  144. this->ArgumentDoing = ArgumentDoingParts;
  145. this->PartsMentioned = true;
  146. return true;
  147. }
  148. if(arg == "FILES")
  149. {
  150. this->ArgumentDoing = ArgumentDoingFiles;
  151. this->FilesMentioned = true;
  152. return true;
  153. }
  154. if(arg == "RETRY_COUNT")
  155. {
  156. this->ArgumentDoing = ArgumentDoingRetryCount;
  157. return true;
  158. }
  159. if(arg == "RETRY_DELAY")
  160. {
  161. this->ArgumentDoing = ArgumentDoingRetryDelay;
  162. return true;
  163. }
  164. // Look for other arguments.
  165. return this->Superclass::CheckArgumentKeyword(arg);
  166. }
  167. //----------------------------------------------------------------------------
  168. bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
  169. {
  170. // Handle states specific to this command.
  171. if(this->ArgumentDoing == ArgumentDoingParts)
  172. {
  173. cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
  174. if(p != cmCTest::PartCount)
  175. {
  176. this->Parts.insert(p);
  177. }
  178. else
  179. {
  180. cmOStringStream e;
  181. e << "Part name \"" << arg << "\" is invalid.";
  182. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  183. this->ArgumentDoing = ArgumentDoingError;
  184. }
  185. return true;
  186. }
  187. if(this->ArgumentDoing == ArgumentDoingFiles)
  188. {
  189. cmStdString filename(arg);
  190. if(cmSystemTools::FileExists(filename.c_str()))
  191. {
  192. this->Files.insert(filename);
  193. }
  194. else
  195. {
  196. cmOStringStream e;
  197. e << "File \"" << filename << "\" does not exist. Cannot submit "
  198. << "a non-existent file.";
  199. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  200. this->ArgumentDoing = ArgumentDoingError;
  201. }
  202. return true;
  203. }
  204. if(this->ArgumentDoing == ArgumentDoingRetryCount)
  205. {
  206. this->RetryCount = arg;
  207. }
  208. if(this->ArgumentDoing == ArgumentDoingRetryDelay)
  209. {
  210. this->RetryDelay = arg;
  211. }
  212. // Look for other arguments.
  213. return this->Superclass::CheckArgumentValue(arg);
  214. }