cmCTestSubmitCommand.cxx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. cmCTest::VectorOfStrings 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. cmCTest::VectorOfStrings 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("RetryDelay",
  133. this->RetryDelay.c_str());
  134. static_cast<cmCTestSubmitHandler*>(handler)->SetOption("RetryCount",
  135. this->RetryCount.c_str());
  136. static_cast<cmCTestSubmitHandler*>(handler)->SetOption("InternalTest",
  137. this->InternalTest ? "ON" : "OFF");
  138. return handler;
  139. }
  140. //----------------------------------------------------------------------------
  141. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  142. {
  143. // Look for arguments specific to this command.
  144. if(arg == "PARTS")
  145. {
  146. this->ArgumentDoing = ArgumentDoingParts;
  147. this->PartsMentioned = true;
  148. return true;
  149. }
  150. if(arg == "FILES")
  151. {
  152. this->ArgumentDoing = ArgumentDoingFiles;
  153. this->FilesMentioned = true;
  154. return true;
  155. }
  156. if(arg == "RETRY_COUNT")
  157. {
  158. this->ArgumentDoing = ArgumentDoingRetryCount;
  159. return true;
  160. }
  161. if(arg == "RETRY_DELAY")
  162. {
  163. this->ArgumentDoing = ArgumentDoingRetryDelay;
  164. return true;
  165. }
  166. if(arg == "INTERNAL_TEST_CHECKSUM")
  167. {
  168. this->InternalTest = true;
  169. return true;
  170. }
  171. // Look for other arguments.
  172. return this->Superclass::CheckArgumentKeyword(arg);
  173. }
  174. //----------------------------------------------------------------------------
  175. bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
  176. {
  177. // Handle states specific to this command.
  178. if(this->ArgumentDoing == ArgumentDoingParts)
  179. {
  180. cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
  181. if(p != cmCTest::PartCount)
  182. {
  183. this->Parts.insert(p);
  184. }
  185. else
  186. {
  187. cmOStringStream e;
  188. e << "Part name \"" << arg << "\" is invalid.";
  189. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  190. this->ArgumentDoing = ArgumentDoingError;
  191. }
  192. return true;
  193. }
  194. if(this->ArgumentDoing == ArgumentDoingFiles)
  195. {
  196. std::string filename(arg);
  197. if(cmSystemTools::FileExists(filename.c_str()))
  198. {
  199. this->Files.insert(filename);
  200. }
  201. else
  202. {
  203. cmOStringStream e;
  204. e << "File \"" << filename << "\" does not exist. Cannot submit "
  205. << "a non-existent file.";
  206. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  207. this->ArgumentDoing = ArgumentDoingError;
  208. }
  209. return true;
  210. }
  211. if(this->ArgumentDoing == ArgumentDoingRetryCount)
  212. {
  213. this->RetryCount = arg;
  214. return true;
  215. }
  216. if(this->ArgumentDoing == ArgumentDoingRetryDelay)
  217. {
  218. this->RetryDelay = arg;
  219. return true;
  220. }
  221. // Look for other arguments.
  222. return this->Superclass::CheckArgumentValue(arg);
  223. }