cmCTestHandlerCommand.cxx 3.8 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 "cmCTestHandlerCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. cmCTestHandlerCommand::cmCTestHandlerCommand()
  17. {
  18. const size_t INIT_SIZE = 100;
  19. size_t cc;
  20. m_Arguments.reserve(INIT_SIZE);
  21. for ( cc = 0; cc < INIT_SIZE; ++ cc )
  22. {
  23. m_Arguments[cc] = 0;
  24. }
  25. m_Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
  26. m_Arguments[ct_SOURCE] = "SOURCE";
  27. m_Arguments[ct_BUILD] = "BUILD";
  28. m_Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
  29. m_Last = ct_LAST;
  30. }
  31. bool cmCTestHandlerCommand::InitialPass(
  32. std::vector<std::string> const& args)
  33. {
  34. if ( !this->ProcessArguments(args, m_Last, &*m_Arguments.begin(), m_Values) )
  35. {
  36. return false;
  37. }
  38. cmCTestGenericHandler* handler = this->InitializeHandler();
  39. if ( !handler )
  40. {
  41. this->SetError("internal CTest error. Cannot instantiate test handler");
  42. return false;
  43. }
  44. if ( m_Values[ct_BUILD] )
  45. {
  46. m_CTest->SetCTestConfiguration("BuildDirectory", m_Values[ct_BUILD]);
  47. }
  48. if ( m_Values[ct_SUBMIT_INDEX] )
  49. {
  50. if ( m_CTest->GetDartVersion() <= 1 )
  51. {
  52. cmCTestLog(m_CTest, ERROR_MESSAGE, "Dart before version 2.0 does not support collecting submissions." << std::endl
  53. << "Please upgrade the server to Dart 2 or higher, or do not use SUBMIT_INDEX." << std::endl);
  54. }
  55. else
  56. {
  57. handler->SetSubmitIndex(atoi(m_Values[ct_SUBMIT_INDEX]));
  58. }
  59. }
  60. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  61. cmSystemTools::ChangeDirectory(m_CTest->GetCTestConfiguration("BuildDirectory").c_str());
  62. int res = handler->ProcessHandler();
  63. if ( m_Values[ct_RETURN_VALUE] && *m_Values[ct_RETURN_VALUE])
  64. {
  65. cmOStringStream str;
  66. str << res;
  67. m_Makefile->AddDefinition(m_Values[ct_RETURN_VALUE], str.str().c_str());
  68. }
  69. cmSystemTools::ChangeDirectory(current_dir.c_str());
  70. return true;
  71. }
  72. bool cmCTestHandlerCommand::ProcessArguments(std::vector<std::string> const& args,
  73. int last, const char** strings, std::vector<const char*>& values)
  74. {
  75. int state = 0;
  76. int cc;
  77. values.resize(last);
  78. for ( cc = 0; cc < last; ++ cc )
  79. {
  80. values[cc] = 0;
  81. }
  82. for(size_t i=0; i < args.size(); ++i)
  83. {
  84. if ( state > 0 && state < last )
  85. {
  86. values[state] = args[i].c_str();
  87. #undef cerr
  88. cmCTestLog(m_CTest, DEBUG, "Set " << strings[state] << " to " << args[i].c_str() << std::endl);
  89. state = 0;
  90. }
  91. else
  92. {
  93. bool found = false;
  94. for ( cc = 0; cc < last; ++ cc )
  95. {
  96. if ( strings[cc] && args[i] == strings[cc] )
  97. {
  98. state = cc;
  99. if ( values[state] )
  100. {
  101. cmOStringStream ostr;
  102. ostr << "called with incorrect number of arguments. " << strings[state] << " specified twice.";
  103. this->SetError(ostr.str().c_str());
  104. return false;
  105. }
  106. found = true;
  107. break;
  108. }
  109. }
  110. if ( !found )
  111. {
  112. cmOStringStream str;
  113. str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
  114. this->SetError(str.str().c_str());
  115. return false;
  116. }
  117. }
  118. }
  119. return true;
  120. }