cmCTestSubmitCommand.cxx 8.0 KB

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