cmCTestSubmitCommand.cxx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 CM_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 CM_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. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  117. "RetryDelay", this->RetryDelay.c_str());
  118. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  119. "RetryCount", this->RetryCount.c_str());
  120. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  121. "InternalTest", this->InternalTest ? "ON" : "OFF");
  122. handler->SetQuiet(this->Quiet);
  123. if (this->CDashUpload) {
  124. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  125. "CDashUploadFile", this->CDashUploadFile.c_str());
  126. static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
  127. "CDashUploadType", this->CDashUploadType.c_str());
  128. }
  129. return handler;
  130. }
  131. bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
  132. cmExecutionStatus& status)
  133. {
  134. this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
  135. return this->cmCTestHandlerCommand::InitialPass(args, status);
  136. }
  137. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  138. {
  139. if (this->CDashUpload) {
  140. // Arguments specific to the CDASH_UPLOAD signature.
  141. if (arg == "CDASH_UPLOAD") {
  142. this->ArgumentDoing = ArgumentDoingCDashUpload;
  143. return true;
  144. }
  145. if (arg == "CDASH_UPLOAD_TYPE") {
  146. this->ArgumentDoing = ArgumentDoingCDashUploadType;
  147. return true;
  148. }
  149. } else {
  150. // Arguments that cannot be used with CDASH_UPLOAD.
  151. if (arg == "PARTS") {
  152. this->ArgumentDoing = ArgumentDoingParts;
  153. this->PartsMentioned = true;
  154. return true;
  155. }
  156. if (arg == "FILES") {
  157. this->ArgumentDoing = ArgumentDoingFiles;
  158. this->FilesMentioned = true;
  159. return true;
  160. }
  161. }
  162. // Arguments used by both modes.
  163. if (arg == "RETRY_COUNT") {
  164. this->ArgumentDoing = ArgumentDoingRetryCount;
  165. return true;
  166. }
  167. if (arg == "RETRY_DELAY") {
  168. this->ArgumentDoing = ArgumentDoingRetryDelay;
  169. return true;
  170. }
  171. if (arg == "INTERNAL_TEST_CHECKSUM") {
  172. this->InternalTest = true;
  173. return true;
  174. }
  175. // Look for other arguments.
  176. return this->Superclass::CheckArgumentKeyword(arg);
  177. }
  178. bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
  179. {
  180. // Handle states specific to this command.
  181. if (this->ArgumentDoing == ArgumentDoingParts) {
  182. cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
  183. if (p != cmCTest::PartCount) {
  184. this->Parts.insert(p);
  185. } else {
  186. std::ostringstream e;
  187. e << "Part name \"" << arg << "\" is invalid.";
  188. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  189. this->ArgumentDoing = ArgumentDoingError;
  190. }
  191. return true;
  192. }
  193. if (this->ArgumentDoing == ArgumentDoingFiles) {
  194. if (cmSystemTools::FileExists(arg.c_str())) {
  195. this->Files.insert(arg);
  196. } else {
  197. std::ostringstream e;
  198. e << "File \"" << arg << "\" does not exist. Cannot submit "
  199. << "a non-existent file.";
  200. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  201. this->ArgumentDoing = ArgumentDoingError;
  202. }
  203. return true;
  204. }
  205. if (this->ArgumentDoing == ArgumentDoingRetryCount) {
  206. this->RetryCount = arg;
  207. return true;
  208. }
  209. if (this->ArgumentDoing == ArgumentDoingRetryDelay) {
  210. this->RetryDelay = arg;
  211. return true;
  212. }
  213. if (this->ArgumentDoing == ArgumentDoingCDashUpload) {
  214. this->ArgumentDoing = ArgumentDoingNone;
  215. this->CDashUploadFile = arg;
  216. return true;
  217. }
  218. if (this->ArgumentDoing == ArgumentDoingCDashUploadType) {
  219. this->ArgumentDoing = ArgumentDoingNone;
  220. this->CDashUploadType = arg;
  221. return true;
  222. }
  223. // Look for other arguments.
  224. return this->Superclass::CheckArgumentValue(arg);
  225. }