cmCTestSubmitCommand.cxx 9.2 KB

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