cmCTestSubmitCommand.cxx 8.0 KB

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