2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-06-23 17:04:18 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-06-23 17:04:18 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2005-06-23 17:04:18 +00:00
|
|
|
#include "cmCTestHandlerCommand.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmCTestGenericHandler.h"
|
|
|
|
|
|
|
|
cmCTestHandlerCommand::cmCTestHandlerCommand()
|
|
|
|
{
|
|
|
|
const size_t INIT_SIZE = 100;
|
|
|
|
size_t cc;
|
2006-03-10 20:03:09 +00:00
|
|
|
this->Arguments.reserve(INIT_SIZE);
|
2005-06-23 17:04:18 +00:00
|
|
|
for ( cc = 0; cc < INIT_SIZE; ++ cc )
|
|
|
|
{
|
2006-03-10 20:03:09 +00:00
|
|
|
this->Arguments.push_back(0);
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
2006-03-10 20:03:09 +00:00
|
|
|
this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
|
|
|
|
this->Arguments[ct_SOURCE] = "SOURCE";
|
|
|
|
this->Arguments[ct_BUILD] = "BUILD";
|
|
|
|
this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
|
|
|
|
this->Last = ct_LAST;
|
2009-01-12 14:11:29 +00:00
|
|
|
this->AppendXML = false;
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
bool cmCTestHandlerCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:10:47 +00:00
|
|
|
// Allocate space for argument values.
|
|
|
|
this->Values.clear();
|
|
|
|
this->Values.resize(this->Last, 0);
|
|
|
|
|
|
|
|
// Process input arguments.
|
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
for(unsigned int i=0; i < args.size(); ++i)
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:10:47 +00:00
|
|
|
// Check this argument.
|
|
|
|
if(!this->CheckArgumentKeyword(args[i]) &&
|
|
|
|
!this->CheckArgumentValue(args[i]))
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "called with unknown argument \"" << args[i] << "\".";
|
|
|
|
this->SetError(e.str().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Quit if an argument is invalid.
|
|
|
|
if(this->ArgumentDoing == ArgumentDoingError)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 17:09:01 +00:00
|
|
|
// Set the config type of this ctest to the current value of the
|
|
|
|
// CTEST_CONFIGURATION_TYPE script variable if it is defined.
|
|
|
|
// The current script value trumps the -C argument on the command
|
|
|
|
// line.
|
|
|
|
const char* ctestConfigType =
|
|
|
|
this->Makefile->GetDefinition("CTEST_CONFIGURATION_TYPE");
|
|
|
|
if (ctestConfigType)
|
|
|
|
{
|
|
|
|
this->CTest->SetConfigType(ctestConfigType);
|
|
|
|
}
|
|
|
|
|
2006-03-29 17:01:24 +00:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
|
2005-06-23 17:04:18 +00:00
|
|
|
cmCTestGenericHandler* handler = this->InitializeHandler();
|
|
|
|
if ( !handler )
|
|
|
|
{
|
2006-07-27 13:40:21 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot instantiate test handler " << this->GetName()
|
|
|
|
<< std::endl);
|
2005-06-23 17:04:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-12 14:11:29 +00:00
|
|
|
handler->SetAppendXML(this->AppendXML);
|
|
|
|
|
2006-03-29 17:01:24 +00:00
|
|
|
handler->PopulateCustomVectors(this->Makefile);
|
2006-03-10 20:03:09 +00:00
|
|
|
if ( this->Values[ct_BUILD] )
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2006-03-10 20:03:09 +00:00
|
|
|
this->CTest->SetCTestConfiguration("BuildDirectory",
|
2006-07-11 19:58:07 +00:00
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->Values[ct_BUILD]).c_str());
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
2006-03-29 17:01:24 +00:00
|
|
|
else
|
|
|
|
{
|
2008-12-19 02:57:42 +00:00
|
|
|
const char* bdir =
|
|
|
|
this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
|
|
|
|
if(bdir)
|
|
|
|
{
|
|
|
|
this->
|
|
|
|
CTest->SetCTestConfiguration("BuildDirectory",
|
2008-12-26 20:27:01 +00:00
|
|
|
cmSystemTools::CollapseFullPath(bdir).c_str());
|
2008-12-19 02:57:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"CTEST_BINARY_DIRECTORY not set" << std::endl;);
|
|
|
|
}
|
2006-03-29 17:01:24 +00:00
|
|
|
}
|
|
|
|
if ( this->Values[ct_SOURCE] )
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, DEBUG,
|
|
|
|
"Set source directory to: " << this->Values[ct_SOURCE] << std::endl);
|
|
|
|
this->CTest->SetCTestConfiguration("SourceDirectory",
|
2006-07-11 19:58:07 +00:00
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->Values[ct_SOURCE]).c_str());
|
2006-03-29 17:01:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->CTest->SetCTestConfiguration("SourceDirectory",
|
2006-07-11 19:58:07 +00:00
|
|
|
cmSystemTools::CollapseFullPath(
|
2009-09-11 21:15:02 +00:00
|
|
|
this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
|
2006-03-29 17:01:24 +00:00
|
|
|
}
|
2006-03-10 20:03:09 +00:00
|
|
|
if ( this->Values[ct_SUBMIT_INDEX] )
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2006-03-10 20:03:09 +00:00
|
|
|
if ( this->CTest->GetDartVersion() <= 1 )
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2006-03-10 20:03:09 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2006-03-09 16:17:10 +00:00
|
|
|
"Dart before version 2.0 does not support collecting submissions."
|
|
|
|
<< std::endl
|
|
|
|
<< "Please upgrade the server to Dart 2 or higher, or do not use "
|
|
|
|
"SUBMIT_INDEX." << std::endl);
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 20:03:09 +00:00
|
|
|
handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
2006-03-09 16:17:10 +00:00
|
|
|
cmSystemTools::ChangeDirectory(
|
2006-03-10 20:03:09 +00:00
|
|
|
this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
|
2005-06-23 17:04:18 +00:00
|
|
|
int res = handler->ProcessHandler();
|
2006-03-10 20:03:09 +00:00
|
|
|
if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE])
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
|
|
|
cmOStringStream str;
|
|
|
|
str << res;
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->AddDefinition(
|
2006-03-10 20:03:09 +00:00
|
|
|
this->Values[ct_RETURN_VALUE], str.str().c_str());
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
|
|
|
cmSystemTools::ChangeDirectory(current_dir.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-12 14:10:47 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:11:29 +00:00
|
|
|
// Look for non-value arguments common to all commands.
|
|
|
|
if(arg == "APPEND")
|
|
|
|
{
|
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
this->AppendXML = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-12 14:10:47 +00:00
|
|
|
// Check for a keyword in our argument/value table.
|
|
|
|
for(unsigned int k=0; k < this->Arguments.size(); ++k)
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:10:47 +00:00
|
|
|
if(this->Arguments[k] && arg == this->Arguments[k])
|
|
|
|
{
|
|
|
|
this->ArgumentDoing = ArgumentDoingKeyword;
|
|
|
|
this->ArgumentIndex = k;
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
2009-01-12 14:10:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-06-23 17:04:18 +00:00
|
|
|
|
2009-01-12 14:10:47 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
|
|
|
|
{
|
|
|
|
if(this->ArgumentDoing == ArgumentDoingKeyword)
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:10:47 +00:00
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
unsigned int k = this->ArgumentIndex;
|
|
|
|
if(this->Values[k])
|
2005-06-23 17:04:18 +00:00
|
|
|
{
|
2009-01-12 14:10:47 +00:00
|
|
|
cmOStringStream e;
|
|
|
|
e << "Called with more than one value for " << this->Arguments[k];
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
this->ArgumentDoing = ArgumentDoingError;
|
|
|
|
return true;
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
2009-01-12 14:10:47 +00:00
|
|
|
this->Values[k] = arg.c_str();
|
|
|
|
cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
|
|
|
|
<< " to " << arg << "\n");
|
|
|
|
return true;
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|
2009-01-12 14:10:47 +00:00
|
|
|
return false;
|
2005-06-23 17:04:18 +00:00
|
|
|
}
|