cmCTestSubmitCommand.cxx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/string_view>
  9. #include <cm/vector>
  10. #include <cmext/algorithm>
  11. #include <cmext/string_view>
  12. #include "cmCTest.h"
  13. #include "cmCTestSubmitHandler.h"
  14. #include "cmCommand.h"
  15. #include "cmMakefile.h"
  16. #include "cmMessageType.h"
  17. #include "cmRange.h"
  18. #include "cmStringAlgorithms.h"
  19. #include "cmSystemTools.h"
  20. #include "cmValue.h"
  21. class cmExecutionStatus;
  22. /**
  23. * This is a virtual constructor for the command.
  24. */
  25. std::unique_ptr<cmCommand> cmCTestSubmitCommand::Clone()
  26. {
  27. auto ni = cm::make_unique<cmCTestSubmitCommand>();
  28. ni->CTest = this->CTest;
  29. ni->CTestScriptHandler = this->CTestScriptHandler;
  30. return std::unique_ptr<cmCommand>(std::move(ni));
  31. }
  32. cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
  33. {
  34. cmValue submitURL = !this->SubmitURL.empty()
  35. ? cmValue(this->SubmitURL)
  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. this->CTest->SetCTestConfigurationFromCMakeVariable(
  55. this->Makefile, "SubmitInactivityTimeout",
  56. "CTEST_SUBMIT_INACTIVITY_TIMEOUT", this->Quiet);
  57. cmValue notesFilesVariable =
  58. this->Makefile->GetDefinition("CTEST_NOTES_FILES");
  59. if (notesFilesVariable) {
  60. std::vector<std::string> notesFiles = cmExpandedList(*notesFilesVariable);
  61. this->CTest->GenerateNotesFile(notesFiles);
  62. }
  63. cmValue extraFilesVariable =
  64. this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  65. if (extraFilesVariable) {
  66. std::vector<std::string> extraFiles = cmExpandedList(*extraFilesVariable);
  67. if (!this->CTest->SubmitExtraFiles(extraFiles)) {
  68. this->SetError("problem submitting extra files.");
  69. return nullptr;
  70. }
  71. }
  72. cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
  73. handler->Initialize();
  74. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  75. //
  76. // If FILES are given, but not PARTS, only the FILES are submitted
  77. // and *no* PARTS are submitted.
  78. // (This is why we select the empty "noParts" set in the
  79. // FilesMentioned block below...)
  80. //
  81. // If PARTS are given, only the selected PARTS are submitted.
  82. //
  83. // If both PARTS and FILES are given, only the selected PARTS *and*
  84. // all the given FILES are submitted.
  85. // If given explicit FILES to submit, pass them to the handler.
  86. //
  87. if (this->FilesMentioned) {
  88. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  89. // were also explicitly mentioned, they will be selected below...
  90. // But FILES with no PARTS mentioned should just submit the FILES
  91. // without any of the default parts.
  92. //
  93. handler->SelectParts(std::set<cmCTest::Part>());
  94. handler->SelectFiles(
  95. std::set<std::string>(this->Files.begin(), this->Files.end()));
  96. }
  97. // If a PARTS option was given, select only the named parts for submission.
  98. //
  99. if (this->PartsMentioned) {
  100. auto parts =
  101. cmMakeRange(this->Parts).transform([this](std::string const& arg) {
  102. return this->CTest->GetPartFromName(arg);
  103. });
  104. handler->SelectParts(std::set<cmCTest::Part>(parts.begin(), parts.end()));
  105. }
  106. // Pass along any HTTPHEADER to the handler if this option was given.
  107. if (!this->HttpHeaders.empty()) {
  108. handler->SetHttpHeaders(this->HttpHeaders);
  109. }
  110. handler->SetOption("RetryDelay", this->RetryDelay);
  111. handler->SetOption("RetryCount", this->RetryCount);
  112. handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
  113. handler->SetQuiet(this->Quiet);
  114. if (this->CDashUpload) {
  115. handler->SetOption("CDashUploadFile", this->CDashUploadFile);
  116. handler->SetOption("CDashUploadType", this->CDashUploadType);
  117. }
  118. return handler;
  119. }
  120. bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
  121. cmExecutionStatus& status)
  122. {
  123. this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
  124. bool ret = this->cmCTestHandlerCommand::InitialPass(args, status);
  125. if (!this->BuildID.empty()) {
  126. this->Makefile->AddDefinition(this->BuildID, this->CTest->GetBuildID());
  127. }
  128. return ret;
  129. }
  130. void cmCTestSubmitCommand::BindArguments()
  131. {
  132. if (this->CDashUpload) {
  133. // Arguments specific to the CDASH_UPLOAD signature.
  134. this->Bind("CDASH_UPLOAD", this->CDashUploadFile);
  135. this->Bind("CDASH_UPLOAD_TYPE", this->CDashUploadType);
  136. } else {
  137. // Arguments that cannot be used with CDASH_UPLOAD.
  138. this->Bind("PARTS"_s, this->Parts);
  139. this->Bind("FILES"_s, this->Files);
  140. }
  141. // Arguments used by both modes.
  142. this->Bind("BUILD_ID"_s, this->BuildID);
  143. this->Bind("HTTPHEADER"_s, this->HttpHeaders);
  144. this->Bind("RETRY_COUNT"_s, this->RetryCount);
  145. this->Bind("RETRY_DELAY"_s, this->RetryDelay);
  146. this->Bind("SUBMIT_URL"_s, this->SubmitURL);
  147. this->Bind("INTERNAL_TEST_CHECKSUM", this->InternalTest);
  148. // Look for other arguments.
  149. this->cmCTestHandlerCommand::BindArguments();
  150. }
  151. void cmCTestSubmitCommand::CheckArguments(
  152. std::vector<cm::string_view> const& keywords)
  153. {
  154. this->PartsMentioned =
  155. !this->Parts.empty() || cm::contains(keywords, "PARTS"_s);
  156. this->FilesMentioned =
  157. !this->Files.empty() || cm::contains(keywords, "FILES"_s);
  158. cm::erase_if(this->Parts, [this](std::string const& arg) -> bool {
  159. cmCTest::Part p = this->CTest->GetPartFromName(arg);
  160. if (p == cmCTest::PartCount) {
  161. std::ostringstream e;
  162. e << "Part name \"" << arg << "\" is invalid.";
  163. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  164. return true;
  165. }
  166. return false;
  167. });
  168. cm::erase_if(this->Files, [this](std::string const& arg) -> bool {
  169. if (!cmSystemTools::FileExists(arg)) {
  170. std::ostringstream e;
  171. e << "File \"" << arg << "\" does not exist. Cannot submit "
  172. << "a non-existent file.";
  173. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  174. return true;
  175. }
  176. return false;
  177. });
  178. }