cmCTestSubmitCommand.cxx 6.6 KB

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