cmCTestHandlerCommand.cxx 4.7 KB

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