cmCTestUpdateCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. "
  40. "RETURN_VALUE specified twice.");
  41. return false;
  42. }
  43. havereturn_variable = true;
  44. }
  45. else if(args[i] == "SOURCE")
  46. {
  47. if ( source_dir )
  48. {
  49. this->SetError("called with incorrect number of arguments. SOURCE "
  50. "specified twice.");
  51. return false;
  52. }
  53. havesource = true;
  54. }
  55. else
  56. {
  57. cmOStringStream str;
  58. str << "called with incorrect number of arguments. Extra argument is: "
  59. << args[i].c_str() << ".";
  60. this->SetError(str.str().c_str());
  61. return false;
  62. }
  63. }
  64. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  65. "UpdateCommand", "CTEST_UPDATE_COMMAND");
  66. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  67. "UpdateOptions", "CTEST_UPDATE_OPTIONS");
  68. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  69. "CVSCommand", "CTEST_CVS_COMMAND");
  70. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  71. "CVSUpdateOptions", "CTEST_CVS_UPDATE_OPTIONS");
  72. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  73. "SVNCommand", "CTEST_SVN_COMMAND");
  74. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  75. "SVNUpdateOptions", "CTEST_SVN_UPDATE_OPTIONS");
  76. const char* initialCheckoutCommand
  77. = m_Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
  78. if ( !initialCheckoutCommand )
  79. {
  80. initialCheckoutCommand = m_Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
  81. }
  82. cmCTestGenericHandler* handler = m_CTest->GetInitializedHandler("update");
  83. if ( !handler )
  84. {
  85. this->SetError("internal CTest error. Cannot instantiate update handler");
  86. return false;
  87. }
  88. handler->SetCommand(this);
  89. if ( !source_dir )
  90. {
  91. this->SetError("source directory not specified. Please use SOURCE tag");
  92. return false;
  93. }
  94. if ( initialCheckoutCommand )
  95. {
  96. handler->SetOption("InitialCheckout", initialCheckoutCommand);
  97. }
  98. if ( (!cmSystemTools::FileExists(source_dir) ||
  99. !cmSystemTools::FileIsDirectory(source_dir))
  100. && !initialCheckoutCommand )
  101. {
  102. cmOStringStream str;
  103. str << "cannot find source directory: " << source_dir << ".";
  104. if ( !cmSystemTools::FileExists(source_dir) )
  105. {
  106. str << " Looks like it is not checked out yet. Please specify "
  107. "CTEST_CHECKOUT_COMMAND.";
  108. }
  109. this->SetError(str.str().c_str());
  110. return false;
  111. }
  112. handler->SetOption("SourceDirectory", source_dir);
  113. int res = handler->ProcessHandler();
  114. if ( res_var )
  115. {
  116. cmOStringStream str;
  117. str << res;
  118. m_Makefile->AddDefinition(res_var, str.str().c_str());
  119. }
  120. return true;
  121. }