cmCTestSubmitCommand.cxx 9.0 KB

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