cmCTestSubmitCommand.cxx 8.6 KB

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