cmCTestSubmitCommand.cxx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 "cmCTest.h"
  5. #include "cmCTestGenericHandler.h"
  6. #include "cmCTestSubmitHandler.h"
  7. #include "cmMakefile.h"
  8. #include "cmSystemTools.h"
  9. #include "cmake.h"
  10. #include <sstream>
  11. class cmExecutionStatus;
  12. cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
  13. {
  14. const char* ctestDropMethod =
  15. this->Makefile->GetDefinition("CTEST_DROP_METHOD");
  16. const char* ctestDropSite = this->Makefile->GetDefinition("CTEST_DROP_SITE");
  17. const char* ctestDropLocation =
  18. this->Makefile->GetDefinition("CTEST_DROP_LOCATION");
  19. const char* ctestTriggerSite =
  20. this->Makefile->GetDefinition("CTEST_TRIGGER_SITE");
  21. bool ctestDropSiteCDash = this->Makefile->IsOn("CTEST_DROP_SITE_CDASH");
  22. const char* ctestProjectName =
  23. this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
  24. if (!ctestDropMethod) {
  25. ctestDropMethod = "http";
  26. }
  27. if (!ctestDropSite) {
  28. // error: CDash requires CTEST_DROP_SITE definition
  29. // in CTestConfig.cmake
  30. }
  31. if (!ctestDropLocation) {
  32. // error: CDash requires CTEST_DROP_LOCATION definition
  33. // in CTestConfig.cmake
  34. }
  35. this->CTest->SetCTestConfiguration("ProjectName", ctestProjectName,
  36. this->Quiet);
  37. this->CTest->SetCTestConfiguration("DropMethod", ctestDropMethod,
  38. this->Quiet);
  39. this->CTest->SetCTestConfiguration("DropSite", ctestDropSite, this->Quiet);
  40. this->CTest->SetCTestConfiguration("DropLocation", ctestDropLocation,
  41. this->Quiet);
  42. this->CTest->SetCTestConfiguration(
  43. "IsCDash", ctestDropSiteCDash ? "TRUE" : "FALSE", this->Quiet);
  44. // Only propagate TriggerSite for non-CDash projects:
  45. //
  46. if (!ctestDropSiteCDash) {
  47. this->CTest->SetCTestConfiguration("TriggerSite", ctestTriggerSite,
  48. this->Quiet);
  49. }
  50. this->CTest->SetCTestConfigurationFromCMakeVariable(
  51. this->Makefile, "CurlOptions", "CTEST_CURL_OPTIONS", this->Quiet);
  52. this->CTest->SetCTestConfigurationFromCMakeVariable(
  53. this->Makefile, "DropSiteUser", "CTEST_DROP_SITE_USER", this->Quiet);
  54. this->CTest->SetCTestConfigurationFromCMakeVariable(
  55. this->Makefile, "DropSitePassword", "CTEST_DROP_SITE_PASSWORD",
  56. this->Quiet);
  57. this->CTest->SetCTestConfigurationFromCMakeVariable(
  58. this->Makefile, "ScpCommand", "CTEST_SCP_COMMAND", this->Quiet);
  59. const char* notesFilesVariable =
  60. this->Makefile->GetDefinition("CTEST_NOTES_FILES");
  61. if (notesFilesVariable) {
  62. std::vector<std::string> notesFiles;
  63. cmCTest::VectorOfStrings newNotesFiles;
  64. cmSystemTools::ExpandListArgument(notesFilesVariable, notesFiles);
  65. newNotesFiles.insert(newNotesFiles.end(), notesFiles.begin(),
  66. notesFiles.end());
  67. this->CTest->GenerateNotesFile(newNotesFiles);
  68. }
  69. const char* extraFilesVariable =
  70. this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  71. if (extraFilesVariable) {
  72. std::vector<std::string> extraFiles;
  73. cmCTest::VectorOfStrings newExtraFiles;
  74. cmSystemTools::ExpandListArgument(extraFilesVariable, extraFiles);
  75. newExtraFiles.insert(newExtraFiles.end(), extraFiles.begin(),
  76. extraFiles.end());
  77. if (!this->CTest->SubmitExtraFiles(newExtraFiles)) {
  78. this->SetError("problem submitting extra files.");
  79. return nullptr;
  80. }
  81. }
  82. cmCTestGenericHandler* handler =
  83. this->CTest->GetInitializedHandler("submit");
  84. if (!handler) {
  85. this->SetError("internal CTest error. Cannot instantiate submit handler");
  86. return nullptr;
  87. }
  88. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  89. //
  90. // If FILES are given, but not PARTS, only the FILES are submitted
  91. // and *no* PARTS are submitted.
  92. // (This is why we select the empty "noParts" set in the
  93. // FilesMentioned block below...)
  94. //
  95. // If PARTS are given, only the selected PARTS are submitted.
  96. //
  97. // If both PARTS and FILES are given, only the selected PARTS *and*
  98. // all the given FILES are submitted.
  99. // If given explicit FILES to submit, pass them to the handler.
  100. //
  101. if (this->FilesMentioned) {
  102. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  103. // were also explicitly mentioned, they will be selected below...
  104. // But FILES with no PARTS mentioned should just submit the FILES
  105. // without any of the default parts.
  106. //
  107. std::set<cmCTest::Part> noParts;
  108. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(noParts);
  109. static_cast<cmCTestSubmitHandler*>(handler)->SelectFiles(this->Files);
  110. }
  111. // If a PARTS option was given, select only the named parts for submission.
  112. //
  113. if (this->PartsMentioned) {
  114. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(this->Parts);
  115. }
  116. // Pass along any HTTPHEADER to the handler if this option was given.
  117. if (!this->HttpHeaders.empty()) {
  118. static_cast<cmCTestSubmitHandler*>(handler)->SetHttpHeaders(
  119. this->HttpHeaders);
  120. }
  121. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  122. "RetryDelay", this->RetryDelay.c_str());
  123. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  124. "RetryCount", this->RetryCount.c_str());
  125. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  126. "InternalTest", this->InternalTest ? "ON" : "OFF");
  127. handler->SetQuiet(this->Quiet);
  128. if (this->CDashUpload) {
  129. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  130. "CDashUploadFile", this->CDashUploadFile.c_str());
  131. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  132. "CDashUploadType", this->CDashUploadType.c_str());
  133. }
  134. return handler;
  135. }
  136. bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
  137. cmExecutionStatus& status)
  138. {
  139. this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
  140. return this->cmCTestHandlerCommand::InitialPass(args, status);
  141. }
  142. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  143. {
  144. if (this->CDashUpload) {
  145. // Arguments specific to the CDASH_UPLOAD signature.
  146. if (arg == "CDASH_UPLOAD") {
  147. this->ArgumentDoing = ArgumentDoingCDashUpload;
  148. return true;
  149. }
  150. if (arg == "CDASH_UPLOAD_TYPE") {
  151. this->ArgumentDoing = ArgumentDoingCDashUploadType;
  152. return true;
  153. }
  154. } else {
  155. // Arguments that cannot be used with CDASH_UPLOAD.
  156. if (arg == "PARTS") {
  157. this->ArgumentDoing = ArgumentDoingParts;
  158. this->PartsMentioned = true;
  159. return true;
  160. }
  161. if (arg == "FILES") {
  162. this->ArgumentDoing = ArgumentDoingFiles;
  163. this->FilesMentioned = true;
  164. return true;
  165. }
  166. }
  167. // Arguments used by both modes.
  168. if (arg == "HTTPHEADER") {
  169. this->ArgumentDoing = ArgumentDoingHttpHeader;
  170. return true;
  171. }
  172. if (arg == "RETRY_COUNT") {
  173. this->ArgumentDoing = ArgumentDoingRetryCount;
  174. return true;
  175. }
  176. if (arg == "RETRY_DELAY") {
  177. this->ArgumentDoing = ArgumentDoingRetryDelay;
  178. return true;
  179. }
  180. if (arg == "INTERNAL_TEST_CHECKSUM") {
  181. this->InternalTest = true;
  182. return true;
  183. }
  184. // Look for other arguments.
  185. return this->Superclass::CheckArgumentKeyword(arg);
  186. }
  187. bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
  188. {
  189. // Handle states specific to this command.
  190. if (this->ArgumentDoing == ArgumentDoingParts) {
  191. cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
  192. if (p != cmCTest::PartCount) {
  193. this->Parts.insert(p);
  194. } else {
  195. std::ostringstream e;
  196. e << "Part name \"" << arg << "\" is invalid.";
  197. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  198. this->ArgumentDoing = ArgumentDoingError;
  199. }
  200. return true;
  201. }
  202. if (this->ArgumentDoing == ArgumentDoingFiles) {
  203. if (cmSystemTools::FileExists(arg)) {
  204. this->Files.insert(arg);
  205. } else {
  206. std::ostringstream e;
  207. e << "File \"" << arg << "\" does not exist. Cannot submit "
  208. << "a non-existent file.";
  209. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  210. this->ArgumentDoing = ArgumentDoingError;
  211. }
  212. return true;
  213. }
  214. if (this->ArgumentDoing == ArgumentDoingHttpHeader) {
  215. this->HttpHeaders.push_back(arg);
  216. return true;
  217. }
  218. if (this->ArgumentDoing == ArgumentDoingRetryCount) {
  219. this->RetryCount = arg;
  220. return true;
  221. }
  222. if (this->ArgumentDoing == ArgumentDoingRetryDelay) {
  223. this->RetryDelay = arg;
  224. return true;
  225. }
  226. if (this->ArgumentDoing == ArgumentDoingCDashUpload) {
  227. this->ArgumentDoing = ArgumentDoingNone;
  228. this->CDashUploadFile = arg;
  229. return true;
  230. }
  231. if (this->ArgumentDoing == ArgumentDoingCDashUploadType) {
  232. this->ArgumentDoing = ArgumentDoingNone;
  233. this->CDashUploadType = arg;
  234. return true;
  235. }
  236. // Look for other arguments.
  237. return this->Superclass::CheckArgumentValue(arg);
  238. }