cmCTestSubmitCommand.cxx 8.1 KB

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