cmCTestUpdateCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "cmCTestUpdateCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. bool cmCTestUpdateCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. const char* source_dir = 0;
  20. const char* res_var = 0;
  21. bool havereturn_variable = false;
  22. bool havesource = false;
  23. for(size_t i=0; i < args.size(); ++i)
  24. {
  25. if ( havereturn_variable )
  26. {
  27. res_var = args[i].c_str();
  28. havereturn_variable = false;
  29. }
  30. else if ( havesource )
  31. {
  32. source_dir = args[i].c_str();
  33. havesource = false;
  34. }
  35. else if(args[i] == "RETURN_VALUE")
  36. {
  37. if ( res_var )
  38. {
  39. this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
  40. return false;
  41. }
  42. havereturn_variable = true;
  43. }
  44. else if(args[i] == "SOURCE")
  45. {
  46. if ( source_dir )
  47. {
  48. this->SetError("called with incorrect number of arguments. SOURCE specified twice.");
  49. return false;
  50. }
  51. havesource = true;
  52. }
  53. else
  54. {
  55. cmOStringStream str;
  56. str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
  57. this->SetError(str.str().c_str());
  58. return false;
  59. }
  60. }
  61. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "UpdateCommand", "CTEST_UPDATE_COMMAND");
  62. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "UpdateOptions", "CTEST_UPDATE_OPTIONS");
  63. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND");
  64. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSUpdateOptions", "CTEST_CVS_UPDATE_OPTIONS");
  65. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND");
  66. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNUpdateOptions", "CTEST_SVN_UPDATE_OPTIONS");
  67. const char* initialCheckoutCommand = m_Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  68. if ( !initialCheckoutCommand )
  69. {
  70. initialCheckoutCommand = m_Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  71. }
  72. cmCTestGenericHandler* handler = m_CTest->GetInitializedHandler("update");
  73. if ( !handler )
  74. {
  75. this->SetError("internal CTest error. Cannot instantiate update handler");
  76. return false;
  77. }
  78. handler->SetCommand(this);
  79. if ( !source_dir )
  80. {
  81. this->SetError("source directory not specified. Please use SOURCE tag");
  82. return false;
  83. }
  84. if ( initialCheckoutCommand )
  85. {
  86. handler->SetOption("InitialCheckout", initialCheckoutCommand);
  87. }
  88. if ( (!cmSystemTools::FileExists(source_dir) || !cmSystemTools::FileIsDirectory(source_dir))
  89. && !initialCheckoutCommand )
  90. {
  91. cmOStringStream str;
  92. str << "cannot find source directory: " << source_dir << ".";
  93. if ( !cmSystemTools::FileExists(source_dir) )
  94. {
  95. str << " Looks like it is not checked out yet. Please specify CTEST_CHECKOUT_COMMAND.";
  96. }
  97. this->SetError(str.str().c_str());
  98. return false;
  99. }
  100. handler->SetOption("SourceDirectory", source_dir);
  101. int res = handler->ProcessHandler();
  102. if ( res_var )
  103. {
  104. cmOStringStream str;
  105. str << res;
  106. m_Makefile->AddDefinition(res_var, str.str().c_str());
  107. }
  108. return true;
  109. }