cmCTestSubmitCommand.cxx 8.0 KB

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