cmCTestSubmitCommand.cxx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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;
  62. cmExpandList(notesFilesVariable, notesFiles);
  63. this->CTest->GenerateNotesFile(notesFiles);
  64. }
  65. const char* extraFilesVariable =
  66. this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  67. if (extraFilesVariable) {
  68. std::vector<std::string> extraFiles;
  69. cmExpandList(extraFilesVariable, extraFiles);
  70. if (!this->CTest->SubmitExtraFiles(extraFiles)) {
  71. this->SetError("problem submitting extra files.");
  72. return nullptr;
  73. }
  74. }
  75. cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
  76. handler->Initialize();
  77. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  78. //
  79. // If FILES are given, but not PARTS, only the FILES are submitted
  80. // and *no* PARTS are submitted.
  81. // (This is why we select the empty "noParts" set in the
  82. // FilesMentioned block below...)
  83. //
  84. // If PARTS are given, only the selected PARTS are submitted.
  85. //
  86. // If both PARTS and FILES are given, only the selected PARTS *and*
  87. // all the given FILES are submitted.
  88. // If given explicit FILES to submit, pass them to the handler.
  89. //
  90. if (this->FilesMentioned) {
  91. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  92. // were also explicitly mentioned, they will be selected below...
  93. // But FILES with no PARTS mentioned should just submit the FILES
  94. // without any of the default parts.
  95. //
  96. handler->SelectParts(std::set<cmCTest::Part>());
  97. handler->SelectFiles(this->Files);
  98. }
  99. // If a PARTS option was given, select only the named parts for submission.
  100. //
  101. if (this->PartsMentioned) {
  102. handler->SelectParts(this->Parts);
  103. }
  104. // Pass along any HTTPHEADER to the handler if this option was given.
  105. if (!this->HttpHeaders.empty()) {
  106. handler->SetHttpHeaders(this->HttpHeaders);
  107. }
  108. handler->SetOption("RetryDelay", this->RetryDelay.c_str());
  109. handler->SetOption("RetryCount", this->RetryCount.c_str());
  110. handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
  111. handler->SetQuiet(this->Quiet);
  112. if (this->CDashUpload) {
  113. handler->SetOption("CDashUploadFile", this->CDashUploadFile.c_str());
  114. handler->SetOption("CDashUploadType", this->CDashUploadType.c_str());
  115. }
  116. return handler;
  117. }
  118. bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
  119. cmExecutionStatus& status)
  120. {
  121. this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
  122. bool ret = this->cmCTestHandlerCommand::InitialPass(args, status);
  123. if (this->Values[cts_BUILD_ID] && *this->Values[cts_BUILD_ID]) {
  124. this->Makefile->AddDefinition(this->Values[cts_BUILD_ID],
  125. this->CTest->GetBuildID());
  126. }
  127. return ret;
  128. }
  129. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  130. {
  131. if (this->CDashUpload) {
  132. // Arguments specific to the CDASH_UPLOAD signature.
  133. if (arg == "CDASH_UPLOAD") {
  134. this->ArgumentDoing = ArgumentDoingCDashUpload;
  135. return true;
  136. }
  137. if (arg == "CDASH_UPLOAD_TYPE") {
  138. this->ArgumentDoing = ArgumentDoingCDashUploadType;
  139. return true;
  140. }
  141. } else {
  142. // Arguments that cannot be used with CDASH_UPLOAD.
  143. if (arg == "PARTS") {
  144. this->ArgumentDoing = ArgumentDoingParts;
  145. this->PartsMentioned = true;
  146. return true;
  147. }
  148. if (arg == "FILES") {
  149. this->ArgumentDoing = ArgumentDoingFiles;
  150. this->FilesMentioned = true;
  151. return true;
  152. }
  153. }
  154. // Arguments used by both modes.
  155. if (arg == "HTTPHEADER") {
  156. this->ArgumentDoing = ArgumentDoingHttpHeader;
  157. return true;
  158. }
  159. if (arg == "RETRY_COUNT") {
  160. this->ArgumentDoing = ArgumentDoingRetryCount;
  161. return true;
  162. }
  163. if (arg == "RETRY_DELAY") {
  164. this->ArgumentDoing = ArgumentDoingRetryDelay;
  165. return true;
  166. }
  167. if (arg == "SUBMIT_URL") {
  168. this->ArgumentDoing = ArgumentDoingSubmitURL;
  169. return true;
  170. }
  171. if (arg == "INTERNAL_TEST_CHECKSUM") {
  172. this->InternalTest = true;
  173. return true;
  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(MessageType::FATAL_ERROR, e.str());
  189. this->ArgumentDoing = ArgumentDoingError;
  190. }
  191. return true;
  192. }
  193. if (this->ArgumentDoing == ArgumentDoingFiles) {
  194. if (cmSystemTools::FileExists(arg)) {
  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(MessageType::FATAL_ERROR, e.str());
  201. this->ArgumentDoing = ArgumentDoingError;
  202. }
  203. return true;
  204. }
  205. if (this->ArgumentDoing == ArgumentDoingHttpHeader) {
  206. this->HttpHeaders.push_back(arg);
  207. return true;
  208. }
  209. if (this->ArgumentDoing == ArgumentDoingRetryCount) {
  210. this->RetryCount = arg;
  211. return true;
  212. }
  213. if (this->ArgumentDoing == ArgumentDoingRetryDelay) {
  214. this->RetryDelay = arg;
  215. return true;
  216. }
  217. if (this->ArgumentDoing == ArgumentDoingCDashUpload) {
  218. this->ArgumentDoing = ArgumentDoingNone;
  219. this->CDashUploadFile = arg;
  220. return true;
  221. }
  222. if (this->ArgumentDoing == ArgumentDoingCDashUploadType) {
  223. this->ArgumentDoing = ArgumentDoingNone;
  224. this->CDashUploadType = arg;
  225. return true;
  226. }
  227. if (this->ArgumentDoing == ArgumentDoingSubmitURL) {
  228. this->ArgumentDoing = ArgumentDoingNone;
  229. this->SubmitURL = arg;
  230. return true;
  231. }
  232. // Look for other arguments.
  233. return this->Superclass::CheckArgumentValue(arg);
  234. }