cmCTestSubmitCommand.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestSubmitCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. #include "cmCTestSubmitHandler.h"
  17. cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
  18. {
  19. const char* ctestDropMethod
  20. = this->Makefile->GetDefinition("CTEST_DROP_METHOD");
  21. const char* ctestDropSite
  22. = this->Makefile->GetDefinition("CTEST_DROP_SITE");
  23. const char* ctestDropLocation
  24. = this->Makefile->GetDefinition("CTEST_DROP_LOCATION");
  25. const char* ctestTriggerSite
  26. = this->Makefile->GetDefinition("CTEST_TRIGGER_SITE");
  27. bool ctestDropSiteCDash
  28. = this->Makefile->IsOn("CTEST_DROP_SITE_CDASH");
  29. if ( !ctestDropMethod )
  30. {
  31. ctestDropMethod = "http";
  32. }
  33. if ( !ctestDropSite )
  34. {
  35. // error: CDash requires CTEST_DROP_SITE definition
  36. // in CTestConfig.cmake
  37. }
  38. if ( !ctestDropLocation )
  39. {
  40. // error: CDash requires CTEST_DROP_LOCATION definition
  41. // in CTestConfig.cmake
  42. }
  43. this->CTest->SetCTestConfiguration("DropMethod", ctestDropMethod);
  44. this->CTest->SetCTestConfiguration("DropSite", ctestDropSite);
  45. this->CTest->SetCTestConfiguration("DropLocation", ctestDropLocation);
  46. this->CTest->SetCTestConfiguration("IsCDash",
  47. ctestDropSiteCDash ? "TRUE" : "FALSE");
  48. // Only propagate TriggerSite for non-CDash projects:
  49. //
  50. if ( !ctestDropSiteCDash )
  51. {
  52. this->CTest->SetCTestConfiguration("TriggerSite", ctestTriggerSite);
  53. }
  54. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  55. "CurlOptions", "CTEST_CURL_OPTIONS");
  56. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  57. "DropSiteUser", "CTEST_DROP_SITE_USER");
  58. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  59. "DropSitePassword", "CTEST_DROP_SITE_PASSWORD");
  60. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  61. "ScpCommand", "CTEST_SCP_COMMAND");
  62. const char* notesFilesVariable
  63. = this->Makefile->GetDefinition("CTEST_NOTES_FILES");
  64. if (notesFilesVariable)
  65. {
  66. std::vector<std::string> notesFiles;
  67. std::vector<cmStdString> newNotesFiles;
  68. cmSystemTools::ExpandListArgument(notesFilesVariable,notesFiles);
  69. std::vector<std::string>::iterator it;
  70. for ( it = notesFiles.begin();
  71. it != notesFiles.end();
  72. ++ it )
  73. {
  74. newNotesFiles.push_back(*it);
  75. }
  76. this->CTest->GenerateNotesFile(newNotesFiles);
  77. }
  78. const char* extraFilesVariable
  79. = this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
  80. if (extraFilesVariable)
  81. {
  82. std::vector<std::string> extraFiles;
  83. std::vector<cmStdString> newExtraFiles;
  84. cmSystemTools::ExpandListArgument(extraFilesVariable,extraFiles);
  85. std::vector<std::string>::iterator it;
  86. for ( it = extraFiles.begin();
  87. it != extraFiles.end();
  88. ++ it )
  89. {
  90. newExtraFiles.push_back(*it);
  91. }
  92. if ( !this->CTest->SubmitExtraFiles(newExtraFiles))
  93. {
  94. this->SetError("problem submitting extra files.");
  95. return 0;
  96. }
  97. }
  98. cmCTestGenericHandler* handler
  99. = this->CTest->GetInitializedHandler("submit");
  100. if ( !handler )
  101. {
  102. this->SetError("internal CTest error. Cannot instantiate submit handler");
  103. return 0;
  104. }
  105. // If no FILES or PARTS given, *all* PARTS are submitted by default.
  106. //
  107. // If FILES are given, but not PARTS, only the FILES are submitted
  108. // and *no* PARTS are submitted.
  109. // (This is why we select the empty "noParts" set in the
  110. // FilesMentioned block below...)
  111. //
  112. // If PARTS are given, only the selected PARTS are submitted.
  113. //
  114. // If both PARTS and FILES are given, only the selected PARTS *and*
  115. // all the given FILES are submitted.
  116. // If given explicit FILES to submit, pass them to the handler.
  117. //
  118. if(this->FilesMentioned)
  119. {
  120. // Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
  121. // were also explicitly mentioned, they will be selected below...
  122. // But FILES with no PARTS mentioned should just submit the FILES
  123. // without any of the default parts.
  124. //
  125. std::set<cmCTest::Part> noParts;
  126. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(noParts);
  127. static_cast<cmCTestSubmitHandler*>(handler)->SelectFiles(this->Files);
  128. }
  129. // If a PARTS option was given, select only the named parts for submission.
  130. //
  131. if(this->PartsMentioned)
  132. {
  133. static_cast<cmCTestSubmitHandler*>(handler)->SelectParts(this->Parts);
  134. }
  135. return handler;
  136. }
  137. //----------------------------------------------------------------------------
  138. bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
  139. {
  140. // Look for arguments specific to this command.
  141. if(arg == "PARTS")
  142. {
  143. this->ArgumentDoing = ArgumentDoingParts;
  144. this->PartsMentioned = true;
  145. return true;
  146. }
  147. if(arg == "FILES")
  148. {
  149. this->ArgumentDoing = ArgumentDoingFiles;
  150. this->FilesMentioned = true;
  151. return true;
  152. }
  153. // Look for other arguments.
  154. return this->Superclass::CheckArgumentKeyword(arg);
  155. }
  156. //----------------------------------------------------------------------------
  157. bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
  158. {
  159. // Handle states specific to this command.
  160. if(this->ArgumentDoing == ArgumentDoingParts)
  161. {
  162. cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
  163. if(p != cmCTest::PartCount)
  164. {
  165. this->Parts.insert(p);
  166. }
  167. else
  168. {
  169. cmOStringStream e;
  170. e << "Part name \"" << arg << "\" is invalid.";
  171. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  172. this->ArgumentDoing = ArgumentDoingError;
  173. }
  174. return true;
  175. }
  176. if(this->ArgumentDoing == ArgumentDoingFiles)
  177. {
  178. cmStdString filename(arg);
  179. if(cmSystemTools::FileExists(filename.c_str()))
  180. {
  181. this->Files.insert(filename);
  182. }
  183. else
  184. {
  185. cmOStringStream e;
  186. e << "File \"" << filename << "\" does not exist. Cannot submit "
  187. << "a non-existent file.";
  188. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  189. this->ArgumentDoing = ArgumentDoingError;
  190. }
  191. return true;
  192. }
  193. // Look for other arguments.
  194. return this->Superclass::CheckArgumentValue(arg);
  195. }