cmCTestHandlerCommand.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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
  32. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  33. {
  34. if ( !this->ProcessArguments(args, (unsigned int)this->Last,
  35. &*this->Arguments.begin(),this->Values) )
  36. {
  37. return false;
  38. }
  39. cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
  40. cmCTestGenericHandler* handler = this->InitializeHandler();
  41. if ( !handler )
  42. {
  43. cmCTestLog(this->CTest, ERROR_MESSAGE,
  44. "Cannot instantiate test handler " << this->GetName()
  45. << std::endl);
  46. return false;
  47. }
  48. cmCTestLog(this->CTest, DEBUG, "Populate Custom Vectors" << std::endl;);
  49. handler->PopulateCustomVectors(this->Makefile);
  50. if ( this->Values[ct_BUILD] )
  51. {
  52. this->CTest->SetCTestConfiguration("BuildDirectory",
  53. cmSystemTools::CollapseFullPath(
  54. this->Values[ct_BUILD]).c_str());
  55. }
  56. else
  57. {
  58. this->CTest->SetCTestConfiguration("BuildDirectory",
  59. cmSystemTools::CollapseFullPath(
  60. this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY")).c_str());
  61. }
  62. if ( this->Values[ct_SOURCE] )
  63. {
  64. cmCTestLog(this->CTest, DEBUG,
  65. "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
  66. this->CTest->SetCTestConfiguration("SourceDirectory",
  67. cmSystemTools::CollapseFullPath(
  68. this->Values[ct_SOURCE]).c_str());
  69. }
  70. else
  71. {
  72. this->CTest->SetCTestConfiguration("SourceDirectory",
  73. cmSystemTools::CollapseFullPath(
  74. this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
  75. }
  76. if ( this->Values[ct_SUBMIT_INDEX] )
  77. {
  78. if ( this->CTest->GetDartVersion() <= 1 )
  79. {
  80. cmCTestLog(this->CTest, ERROR_MESSAGE,
  81. "Dart before version 2.0 does not support collecting submissions."
  82. << std::endl
  83. << "Please upgrade the server to Dart 2 or higher, or do not use "
  84. "SUBMIT_INDEX." << std::endl);
  85. }
  86. else
  87. {
  88. handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
  89. }
  90. }
  91. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  92. cmSystemTools::ChangeDirectory(
  93. this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
  94. int res = handler->ProcessHandler();
  95. if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
  96. {
  97. cmOStringStream str;
  98. str << res;
  99. this->Makefile->AddDefinition(
  100. this->Values[ct_RETURN_VALUE], str.str().c_str());
  101. }
  102. cmSystemTools::ChangeDirectory(current_dir.c_str());
  103. return true;
  104. }
  105. bool cmCTestHandlerCommand::ProcessArguments(
  106. std::vector<std::string> const& args, int last, const char** strings,
  107. std::vector<const char*>& values)
  108. {
  109. int state = 0;
  110. int cc;
  111. values.resize(last);
  112. for ( cc = 0; cc < last; ++ cc )
  113. {
  114. values[cc] = 0;
  115. }
  116. for(size_t i=0; i < args.size(); ++i)
  117. {
  118. if ( state > 0 && state < last )
  119. {
  120. values[state] = args[i].c_str();
  121. cmCTestLog(this->CTest, DEBUG, "Set " << strings[state] << " to "
  122. << args[i].c_str() << std::endl);
  123. state = 0;
  124. }
  125. else
  126. {
  127. bool found = false;
  128. for ( cc = 0; cc < last; ++ cc )
  129. {
  130. if ( strings[cc] && args[i] == strings[cc] )
  131. {
  132. state = cc;
  133. if ( values[state] )
  134. {
  135. cmOStringStream ostr;
  136. ostr << "called with incorrect number of arguments. "
  137. << strings[state] << " specified twice.";
  138. this->SetError(ostr.str().c_str());
  139. return false;
  140. }
  141. found = true;
  142. break;
  143. }
  144. }
  145. if ( !found )
  146. {
  147. cmOStringStream str;
  148. str
  149. << "called with incorrect number of arguments. Extra argument is: "
  150. << args[i].c_str() << ".";
  151. this->SetError(str.str().c_str());
  152. return false;
  153. }
  154. }
  155. }
  156. return true;
  157. }