ENH: check in almost building VMS stuff with VMSBuild directory since the bootstrap...
[cmake.git] / Source / CTest / cmCTestHandlerCommand.cxx
blob9c0057076e3f2ee9bf500c84f0e41097e424f993
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestHandlerCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2009-01-12 14:11:29 $
7 Version: $Revision: 1.15 $
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;
36 this->AppendXML = false;
39 bool cmCTestHandlerCommand
40 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
42 // Allocate space for argument values.
43 this->Values.clear();
44 this->Values.resize(this->Last, 0);
46 // Process input arguments.
47 this->ArgumentDoing = ArgumentDoingNone;
48 for(unsigned int i=0; i < args.size(); ++i)
50 // Check this argument.
51 if(!this->CheckArgumentKeyword(args[i]) &&
52 !this->CheckArgumentValue(args[i]))
54 cmOStringStream e;
55 e << "called with unknown argument \"" << args[i] << "\".";
56 this->SetError(e.str().c_str());
57 return false;
60 // Quit if an argument is invalid.
61 if(this->ArgumentDoing == ArgumentDoingError)
63 return false;
67 cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
68 cmCTestGenericHandler* handler = this->InitializeHandler();
69 if ( !handler )
71 cmCTestLog(this->CTest, ERROR_MESSAGE,
72 "Cannot instantiate test handler " << this->GetName()
73 << std::endl);
74 return false;
77 handler->SetAppendXML(this->AppendXML);
79 handler->PopulateCustomVectors(this->Makefile);
80 if ( this->Values[ct_BUILD] )
82 this->CTest->SetCTestConfiguration("BuildDirectory",
83 cmSystemTools::CollapseFullPath(
84 this->Values[ct_BUILD]).c_str());
86 else
88 const char* bdir =
89 this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
90 if(bdir)
92 this->
93 CTest->SetCTestConfiguration("BuildDirectory",
94 cmSystemTools::CollapseFullPath(bdir).c_str());
96 else
98 cmCTestLog(this->CTest, ERROR_MESSAGE,
99 "CTEST_BINARY_DIRECTORY not set" << std::endl;);
102 if ( this->Values[ct_SOURCE] )
104 cmCTestLog(this->CTest, DEBUG,
105 "Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
106 this->CTest->SetCTestConfiguration("SourceDirectory",
107 cmSystemTools::CollapseFullPath(
108 this->Values[ct_SOURCE]).c_str());
110 else
112 this->CTest->SetCTestConfiguration("SourceDirectory",
113 cmSystemTools::CollapseFullPath(
114 this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
116 if ( this->Values[ct_SUBMIT_INDEX] )
118 if ( this->CTest->GetDartVersion() <= 1 )
120 cmCTestLog(this->CTest, ERROR_MESSAGE,
121 "Dart before version 2.0 does not support collecting submissions."
122 << std::endl
123 << "Please upgrade the server to Dart 2 or higher, or do not use "
124 "SUBMIT_INDEX." << std::endl);
126 else
128 handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
131 std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
132 cmSystemTools::ChangeDirectory(
133 this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
134 int res = handler->ProcessHandler();
135 if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
137 cmOStringStream str;
138 str << res;
139 this->Makefile->AddDefinition(
140 this->Values[ct_RETURN_VALUE], str.str().c_str());
142 cmSystemTools::ChangeDirectory(current_dir.c_str());
143 return true;
146 //----------------------------------------------------------------------------
147 bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
149 // Look for non-value arguments common to all commands.
150 if(arg == "APPEND")
152 this->ArgumentDoing = ArgumentDoingNone;
153 this->AppendXML = true;
154 return true;
157 // Check for a keyword in our argument/value table.
158 for(unsigned int k=0; k < this->Arguments.size(); ++k)
160 if(this->Arguments[k] && arg == this->Arguments[k])
162 this->ArgumentDoing = ArgumentDoingKeyword;
163 this->ArgumentIndex = k;
164 return true;
167 return false;
170 //----------------------------------------------------------------------------
171 bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
173 if(this->ArgumentDoing == ArgumentDoingKeyword)
175 this->ArgumentDoing = ArgumentDoingNone;
176 unsigned int k = this->ArgumentIndex;
177 if(this->Values[k])
179 cmOStringStream e;
180 e << "Called with more than one value for " << this->Arguments[k];
181 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
182 this->ArgumentDoing = ArgumentDoingError;
183 return true;
185 this->Values[k] = arg.c_str();
186 cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
187 << " to " << arg << "\n");
188 return true;
190 return false;