cmCTestHandlerCommand.cxx 4.0 KB

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