Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CTest / cmCTestHandlerCommand.cxx
blobe765b3f3e4e3ee0507d275fa9630283ae1aa49f8
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestHandlerCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:28:01 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCTestHandlerCommand.h"
19 #include "cmCTest.h"
20 #include "cmCTestGenericHandler.h"
22 cmCTestHandlerCommand::cmCTestHandlerCommand()
24 const size_t INIT_SIZE = 100;
25 size_t cc;
26 this->Arguments.reserve(INIT_SIZE);
27 for ( cc = 0; cc < INIT_SIZE; ++ cc )
29 this->Arguments.push_back(0);
31 this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
32 this->Arguments[ct_SOURCE] = "SOURCE";
33 this->Arguments[ct_BUILD] = "BUILD";
34 this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
35 this->Last = ct_LAST;
38 bool cmCTestHandlerCommand
39 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
41 if ( !this->ProcessArguments(args, (unsigned int)this->Last,
42 &*this->Arguments.begin(),this->Values) )
44 return false;
47 cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
48 cmCTestGenericHandler* handler = this->InitializeHandler();
49 if ( !handler )
51 cmCTestLog(this->CTest, ERROR_MESSAGE,
52 "Cannot instantiate test handler " << this->GetName()
53 << std::endl);
54 return false;
57 cmCTestLog(this->CTest, DEBUG, "Populate Custom Vectors" << std::endl;);
58 handler->PopulateCustomVectors(this->Makefile);
60 if ( this->Values[ct_BUILD] )
62 this->CTest->SetCTestConfiguration("BuildDirectory",
63 cmSystemTools::CollapseFullPath(
64 this->Values[ct_BUILD]).c_str());
66 else
68 this->CTest->SetCTestConfiguration("BuildDirectory",
69 cmSystemTools::CollapseFullPath(
70 this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY")).c_str());
72 if ( this->Values[ct_SOURCE] )
74 cmCTestLog(this->CTest, DEBUG,
75 "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
76 this->CTest->SetCTestConfiguration("SourceDirectory",
77 cmSystemTools::CollapseFullPath(
78 this->Values[ct_SOURCE]).c_str());
80 else
82 this->CTest->SetCTestConfiguration("SourceDirectory",
83 cmSystemTools::CollapseFullPath(
84 this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
86 if ( this->Values[ct_SUBMIT_INDEX] )
88 if ( this->CTest->GetDartVersion() <= 1 )
90 cmCTestLog(this->CTest, ERROR_MESSAGE,
91 "Dart before version 2.0 does not support collecting submissions."
92 << std::endl
93 << "Please upgrade the server to Dart 2 or higher, or do not use "
94 "SUBMIT_INDEX." << std::endl);
96 else
98 handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
102 std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
103 cmSystemTools::ChangeDirectory(
104 this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
105 int res = handler->ProcessHandler();
106 if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
108 cmOStringStream str;
109 str << res;
110 this->Makefile->AddDefinition(
111 this->Values[ct_RETURN_VALUE], str.str().c_str());
113 cmSystemTools::ChangeDirectory(current_dir.c_str());
114 return true;
117 bool cmCTestHandlerCommand::ProcessArguments(
118 std::vector<std::string> const& args, int last, const char** strings,
119 std::vector<const char*>& values)
121 int state = 0;
122 int cc;
123 values.resize(last);
124 for ( cc = 0; cc < last; ++ cc )
126 values[cc] = 0;
129 for(size_t i=0; i < args.size(); ++i)
131 if ( state > 0 && state < last )
133 values[state] = args[i].c_str();
134 cmCTestLog(this->CTest, DEBUG, "Set " << strings[state] << " to "
135 << args[i].c_str() << std::endl);
136 state = 0;
138 else
140 bool found = false;
141 for ( cc = 0; cc < last; ++ cc )
143 if ( strings[cc] && args[i] == strings[cc] )
145 state = cc;
146 if ( values[state] )
148 cmOStringStream ostr;
149 ostr << "called with incorrect number of arguments. "
150 << strings[state] << " specified twice.";
151 this->SetError(ostr.str().c_str());
152 return false;
154 found = true;
155 break;
158 if ( !found )
160 cmOStringStream str;
162 << "called with incorrect number of arguments. Extra argument is: "
163 << args[i].c_str() << ".";
164 this->SetError(str.str().c_str());
165 return false;
169 return true;