cmCTestSubmitCommand.cxx 8.7 KB

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