cmCTestSubmitCommand.cxx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 "cmArgumentParser.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmCTestSubmitHandler.h"
  14. #include "cmExecutionStatus.h"
  15. #include "cmList.h"
  16. #include "cmMakefile.h"
  17. #include "cmMessageType.h"
  18. #include "cmRange.h"
  19. #include "cmSystemTools.h"
  20. #include "cmValue.h"
  21. std::unique_ptr<cmCTestGenericHandler> cmCTestSubmitCommand::InitializeHandler(
  22. HandlerArguments& arguments, cmExecutionStatus& status) const
  23. {
  24. cmMakefile& mf = status.GetMakefile();
  25. auto const& args = static_cast<SubmitArguments&>(arguments);
  26. cmValue submitURL = !args.SubmitURL.empty()
  27. ? cmValue(args.SubmitURL)
  28. : mf.GetDefinition("CTEST_SUBMIT_URL");
  29. if (submitURL) {
  30. this->CTest->SetCTestConfiguration("SubmitURL", *submitURL, args.Quiet);
  31. } else {
  32. this->CTest->SetCTestConfigurationFromCMakeVariable(
  33. &mf, "DropMethod", "CTEST_DROP_METHOD", args.Quiet);
  34. this->CTest->SetCTestConfigurationFromCMakeVariable(
  35. &mf, "DropSiteUser", "CTEST_DROP_SITE_USER", args.Quiet);
  36. this->CTest->SetCTestConfigurationFromCMakeVariable(
  37. &mf, "DropSitePassword", "CTEST_DROP_SITE_PASSWORD", args.Quiet);
  38. this->CTest->SetCTestConfigurationFromCMakeVariable(
  39. &mf, "DropSite", "CTEST_DROP_SITE", args.Quiet);
  40. this->CTest->SetCTestConfigurationFromCMakeVariable(
  41. &mf, "DropLocation", "CTEST_DROP_LOCATION", args.Quiet);
  42. }
  43. if (!this->CTest->SetCTestConfigurationFromCMakeVariable(
  44. &mf, "TLSVersion", "CTEST_TLS_VERSION", args.Quiet)) {
  45. if (cmValue tlsVersionVar = mf.GetDefinition("CMAKE_TLS_VERSION")) {
  46. cmCTestOptionalLog(
  47. this->CTest, HANDLER_VERBOSE_OUTPUT,
  48. "SetCTestConfiguration from CMAKE_TLS_VERSION:TLSVersion:"
  49. << *tlsVersionVar << std::endl,
  50. args.Quiet);
  51. this->CTest->SetCTestConfiguration("TLSVersion", *tlsVersionVar,
  52. args.Quiet);
  53. } else if (cm::optional<std::string> tlsVersionEnv =
  54. cmSystemTools::GetEnvVar("CMAKE_TLS_VERSION")) {
  55. cmCTestOptionalLog(
  56. this->CTest, HANDLER_VERBOSE_OUTPUT,
  57. "SetCTestConfiguration from ENV{CMAKE_TLS_VERSION}:TLSVersion:"
  58. << *tlsVersionEnv << std::endl,
  59. args.Quiet);
  60. this->CTest->SetCTestConfiguration("TLSVersion", *tlsVersionEnv,
  61. args.Quiet);
  62. }
  63. }
  64. if (!this->CTest->SetCTestConfigurationFromCMakeVariable(
  65. &mf, "TLSVerify", "CTEST_TLS_VERIFY", args.Quiet)) {
  66. if (cmValue tlsVerifyVar = mf.GetDefinition("CMAKE_TLS_VERIFY")) {
  67. cmCTestOptionalLog(
  68. this->CTest, HANDLER_VERBOSE_OUTPUT,
  69. "SetCTestConfiguration from CMAKE_TLS_VERIFY:TLSVerify:"
  70. << *tlsVerifyVar << std::endl,
  71. args.Quiet);
  72. this->CTest->SetCTestConfiguration("TLSVerify", *tlsVerifyVar,
  73. args.Quiet);
  74. } else if (cm::optional<std::string> tlsVerifyEnv =
  75. cmSystemTools::GetEnvVar("CMAKE_TLS_VERIFY")) {
  76. cmCTestOptionalLog(
  77. this->CTest, HANDLER_VERBOSE_OUTPUT,
  78. "SetCTestConfiguration from ENV{CMAKE_TLS_VERIFY}:TLSVerify:"
  79. << *tlsVerifyEnv << std::endl,
  80. args.Quiet);
  81. this->CTest->SetCTestConfiguration("TLSVerify", *tlsVerifyEnv,
  82. args.Quiet);
  83. }
  84. }
  85. this->CTest->SetCTestConfigurationFromCMakeVariable(
  86. &mf, "CurlOptions", "CTEST_CURL_OPTIONS", args.Quiet);
  87. this->CTest->SetCTestConfigurationFromCMakeVariable(
  88. &mf, "SubmitInactivityTimeout", "CTEST_SUBMIT_INACTIVITY_TIMEOUT",
  89. args.Quiet);
  90. cmValue notesFilesVariable = mf.GetDefinition("CTEST_NOTES_FILES");
  91. if (notesFilesVariable) {
  92. cmList notesFiles{ *notesFilesVariable };
  93. this->CTest->GenerateNotesFile(mf.GetCMakeInstance(), notesFiles);
  94. }
  95. cmValue extraFilesVariable = mf.GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  96. if (extraFilesVariable) {
  97. cmList extraFiles{ *extraFilesVariable };
  98. if (!this->CTest->SubmitExtraFiles(extraFiles)) {
  99. status.SetError("problem submitting extra files.");
  100. return nullptr;
  101. }
  102. }
  103. auto handler = cm::make_unique<cmCTestSubmitHandler>(this->CTest);
  104. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  105. //
  106. // If FILES are given, but not PARTS, only the FILES are submitted
  107. // and *no* PARTS are submitted.
  108. // (This is why we select the empty "noParts" set in the
  109. // if(args.Files) block below...)
  110. //
  111. // If PARTS are given, only the selected PARTS are submitted.
  112. //
  113. // If both PARTS and FILES are given, only the selected PARTS *and*
  114. // all the given FILES are submitted.
  115. // If given explicit FILES to submit, pass them to the handler.
  116. //
  117. if (args.Files) {
  118. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  119. // were also explicitly mentioned, they will be selected below...
  120. // But FILES with no PARTS mentioned should just submit the FILES
  121. // without any of the default parts.
  122. //
  123. handler->SelectParts(std::set<cmCTest::Part>());
  124. handler->SelectFiles(
  125. std::set<std::string>(args.Files->begin(), args.Files->end()));
  126. }
  127. // If a PARTS option was given, select only the named parts for submission.
  128. //
  129. if (args.Parts) {
  130. auto parts =
  131. cmMakeRange(*(args.Parts)).transform([this](std::string const& arg) {
  132. return this->CTest->GetPartFromName(arg);
  133. });
  134. handler->SelectParts(std::set<cmCTest::Part>(parts.begin(), parts.end()));
  135. }
  136. // Pass along any HTTPHEADER to the handler if this option was given.
  137. if (!args.HttpHeaders.empty()) {
  138. handler->SetHttpHeaders(args.HttpHeaders);
  139. }
  140. handler->RetryDelay = args.RetryDelay;
  141. handler->RetryCount = args.RetryCount;
  142. handler->InternalTest = args.InternalTest;
  143. handler->SetQuiet(args.Quiet);
  144. if (args.CDashUpload) {
  145. handler->CDashUpload = true;
  146. handler->CDashUploadFile = args.CDashUploadFile;
  147. handler->CDashUploadType = args.CDashUploadType;
  148. }
  149. return std::unique_ptr<cmCTestGenericHandler>(std::move(handler));
  150. }
  151. bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
  152. cmExecutionStatus& status) const
  153. {
  154. // Arguments used by both modes.
  155. static auto const parserBase =
  156. cmArgumentParser<SubmitArguments>{ MakeHandlerParser<SubmitArguments>() }
  157. .Bind("BUILD_ID"_s, &SubmitArguments::BuildID)
  158. .Bind("HTTPHEADER"_s, &SubmitArguments::HttpHeaders)
  159. .Bind("RETRY_COUNT"_s, &SubmitArguments::RetryCount)
  160. .Bind("RETRY_DELAY"_s, &SubmitArguments::RetryDelay)
  161. .Bind("SUBMIT_URL"_s, &SubmitArguments::SubmitURL)
  162. .Bind("INTERNAL_TEST_CHECKSUM"_s, &SubmitArguments::InternalTest);
  163. // Arguments specific to the CDASH_UPLOAD signature.
  164. static auto const uploadParser =
  165. cmArgumentParser<SubmitArguments>{ parserBase }
  166. .Bind("CDASH_UPLOAD"_s, &SubmitArguments::CDashUploadFile)
  167. .Bind("CDASH_UPLOAD_TYPE"_s, &SubmitArguments::CDashUploadType);
  168. // Arguments that cannot be used with CDASH_UPLOAD.
  169. static auto const partsParser =
  170. cmArgumentParser<SubmitArguments>{ parserBase }
  171. .Bind("PARTS"_s, &SubmitArguments::Parts)
  172. .Bind("FILES"_s, &SubmitArguments::Files);
  173. bool const cdashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
  174. auto const& parser = cdashUpload ? uploadParser : partsParser;
  175. return this->Invoke(parser, args, status, [&](SubmitArguments& a) -> bool {
  176. a.CDashUpload = cdashUpload;
  177. return this->ExecuteHandlerCommand(a, status);
  178. });
  179. }
  180. void cmCTestSubmitCommand::CheckArguments(HandlerArguments& arguments,
  181. cmExecutionStatus& status) const
  182. {
  183. cmMakefile& mf = status.GetMakefile();
  184. auto& args = static_cast<SubmitArguments&>(arguments);
  185. if (args.Parts) {
  186. cm::erase_if(*(args.Parts), [this, &mf](std::string const& arg) -> bool {
  187. cmCTest::Part p = this->CTest->GetPartFromName(arg);
  188. if (p == cmCTest::PartCount) {
  189. std::ostringstream e;
  190. e << "Part name \"" << arg << "\" is invalid.";
  191. mf.IssueMessage(MessageType::FATAL_ERROR, e.str());
  192. return true;
  193. }
  194. return false;
  195. });
  196. }
  197. if (args.Files) {
  198. cm::erase_if(*(args.Files), [&mf](std::string const& arg) -> bool {
  199. if (!cmSystemTools::FileExists(arg)) {
  200. std::ostringstream e;
  201. e << "File \"" << arg << "\" does not exist. Cannot submit "
  202. << "a non-existent file.";
  203. mf.IssueMessage(MessageType::FATAL_ERROR, e.str());
  204. return true;
  205. }
  206. return false;
  207. });
  208. }
  209. }
  210. void cmCTestSubmitCommand::ProcessAdditionalValues(
  211. cmCTestGenericHandler*, HandlerArguments const& arguments,
  212. cmExecutionStatus& status) const
  213. {
  214. cmMakefile& mf = status.GetMakefile();
  215. auto const& args = static_cast<SubmitArguments const&>(arguments);
  216. if (!args.BuildID.empty()) {
  217. mf.AddDefinition(args.BuildID, this->CTest->GetBuildID());
  218. }
  219. }