cmCTestSubmitCommand.cxx 8.0 KB

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