cmCTestSubmitCommand.cxx 6.6 KB

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