1
0

cmCTestSubmitCommand.cxx 6.7 KB

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