cmCTestSubmitCommand.cxx 6.7 KB

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