cmCTestSubmitCommand.cxx 6.5 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/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. this->CTest->SetCTestConfigurationFromCMakeVariable(
  51. this->Makefile, "CurlOptions", "CTEST_CURL_OPTIONS", this->Quiet);
  52. this->CTest->SetCTestConfigurationFromCMakeVariable(
  53. this->Makefile, "SubmitInactivityTimeout",
  54. "CTEST_SUBMIT_INACTIVITY_TIMEOUT", this->Quiet);
  55. cmValue notesFilesVariable =
  56. this->Makefile->GetDefinition("CTEST_NOTES_FILES");
  57. if (notesFilesVariable) {
  58. cmList notesFiles{ *notesFilesVariable };
  59. this->CTest->GenerateNotesFile(notesFiles);
  60. }
  61. cmValue extraFilesVariable =
  62. this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  63. if (extraFilesVariable) {
  64. cmList extraFiles{ *extraFilesVariable };
  65. if (!this->CTest->SubmitExtraFiles(extraFiles)) {
  66. this->SetError("problem submitting extra files.");
  67. return nullptr;
  68. }
  69. }
  70. cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
  71. handler->Initialize();
  72. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  73. //
  74. // If FILES are given, but not PARTS, only the FILES are submitted
  75. // and *no* PARTS are submitted.
  76. // (This is why we select the empty "noParts" set in the
  77. // if(this->Files) block below...)
  78. //
  79. // If PARTS are given, only the selected PARTS are submitted.
  80. //
  81. // If both PARTS and FILES are given, only the selected PARTS *and*
  82. // all the given FILES are submitted.
  83. // If given explicit FILES to submit, pass them to the handler.
  84. //
  85. if (this->Files) {
  86. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  87. // were also explicitly mentioned, they will be selected below...
  88. // But FILES with no PARTS mentioned should just submit the FILES
  89. // without any of the default parts.
  90. //
  91. handler->SelectParts(std::set<cmCTest::Part>());
  92. handler->SelectFiles(
  93. std::set<std::string>(this->Files->begin(), this->Files->end()));
  94. }
  95. // If a PARTS option was given, select only the named parts for submission.
  96. //
  97. if (this->Parts) {
  98. auto parts =
  99. cmMakeRange(*(this->Parts)).transform([this](std::string const& arg) {
  100. return this->CTest->GetPartFromName(arg);
  101. });
  102. handler->SelectParts(std::set<cmCTest::Part>(parts.begin(), parts.end()));
  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);
  109. handler->SetOption("RetryCount", this->RetryCount);
  110. handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
  111. handler->SetQuiet(this->Quiet);
  112. if (this->CDashUpload) {
  113. handler->SetOption("CDashUploadFile", this->CDashUploadFile);
  114. handler->SetOption("CDashUploadType", this->CDashUploadType);
  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->BuildID.empty()) {
  124. this->Makefile->AddDefinition(this->BuildID, this->CTest->GetBuildID());
  125. }
  126. return ret;
  127. }
  128. void cmCTestSubmitCommand::BindArguments()
  129. {
  130. if (this->CDashUpload) {
  131. // Arguments specific to the CDASH_UPLOAD signature.
  132. this->Bind("CDASH_UPLOAD", this->CDashUploadFile);
  133. this->Bind("CDASH_UPLOAD_TYPE", this->CDashUploadType);
  134. } else {
  135. // Arguments that cannot be used with CDASH_UPLOAD.
  136. this->Bind("PARTS"_s, this->Parts);
  137. this->Bind("FILES"_s, this->Files);
  138. }
  139. // Arguments used by both modes.
  140. this->Bind("BUILD_ID"_s, this->BuildID);
  141. this->Bind("HTTPHEADER"_s, this->HttpHeaders);
  142. this->Bind("RETRY_COUNT"_s, this->RetryCount);
  143. this->Bind("RETRY_DELAY"_s, this->RetryDelay);
  144. this->Bind("SUBMIT_URL"_s, this->SubmitURL);
  145. this->Bind("INTERNAL_TEST_CHECKSUM", this->InternalTest);
  146. // Look for other arguments.
  147. this->cmCTestHandlerCommand::BindArguments();
  148. }
  149. void cmCTestSubmitCommand::CheckArguments()
  150. {
  151. if (this->Parts) {
  152. cm::erase_if(*(this->Parts), [this](std::string const& arg) -> bool {
  153. cmCTest::Part p = this->CTest->GetPartFromName(arg);
  154. if (p == cmCTest::PartCount) {
  155. std::ostringstream e;
  156. e << "Part name \"" << arg << "\" is invalid.";
  157. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  158. return true;
  159. }
  160. return false;
  161. });
  162. }
  163. if (this->Files) {
  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. }
  175. }