2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-06-23 21:04:18 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-06-23 21:04:18 +04:00
|
|
|
|
2009-09-28 19:43:28 +04: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 21:04:18 +04:00
|
|
|
#include "cmCTestHandlerCommand.h"
|
|
|
|
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmCTestGenericHandler.h"
|
2016-08-24 23:01:40 +03:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
class cmExecutionStatus;
|
2005-06-23 21:04:18 +04:00
|
|
|
|
|
|
|
cmCTestHandlerCommand::cmCTestHandlerCommand()
|
|
|
|
{
|
|
|
|
const size_t INIT_SIZE = 100;
|
|
|
|
size_t cc;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Arguments.reserve(INIT_SIZE);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < INIT_SIZE; ++cc) {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Arguments.push_back(CM_NULLPTR);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
|
2016-07-28 22:12:43 +03:00
|
|
|
this->Arguments[ct_CAPTURE_CMAKE_ERROR] = "CAPTURE_CMAKE_ERROR";
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Arguments[ct_SOURCE] = "SOURCE";
|
|
|
|
this->Arguments[ct_BUILD] = "BUILD";
|
|
|
|
this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
|
|
|
|
this->Last = ct_LAST;
|
2009-01-12 17:11:29 +03:00
|
|
|
this->AppendXML = false;
|
2015-02-17 00:02:14 +03:00
|
|
|
this->Quiet = false;
|
2005-06-23 21:04:18 +04:00
|
|
|
}
|
|
|
|
|
2016-07-28 22:12:43 +03:00
|
|
|
namespace {
|
|
|
|
// class to save and restore the error state for ctest_* commands
|
|
|
|
// if a ctest_* command has a CAPTURE_CMAKE_ERROR then put the error
|
|
|
|
// state into there and restore the system wide error to what
|
|
|
|
// it was before the command ran
|
|
|
|
class SaveRestoreErrorState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SaveRestoreErrorState()
|
|
|
|
{
|
|
|
|
this->InitialErrorState = cmSystemTools::GetErrorOccuredFlag();
|
|
|
|
cmSystemTools::ResetErrorOccuredFlag(); // rest the error state
|
|
|
|
this->CaptureCMakeErrorValue = false;
|
|
|
|
}
|
|
|
|
// if the function has a CAPTURE_CMAKE_ERROR then we should restore
|
|
|
|
// the error state to what it was before the function was run
|
|
|
|
// if not then let the error state be what it is
|
|
|
|
void CaptureCMakeError() { this->CaptureCMakeErrorValue = true; }
|
|
|
|
~SaveRestoreErrorState()
|
|
|
|
{
|
|
|
|
// if we are not saving the return value then make sure
|
|
|
|
// if it was in error it goes back to being in error
|
|
|
|
// otherwise leave it be what it is
|
|
|
|
if (!this->CaptureCMakeErrorValue) {
|
|
|
|
if (this->InitialErrorState) {
|
|
|
|
cmSystemTools::SetErrorOccured();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if we have saved the error in a return variable
|
|
|
|
// then put things back exactly like they were
|
|
|
|
bool currentState = cmSystemTools::GetErrorOccuredFlag();
|
|
|
|
// if the state changed during this command we need
|
|
|
|
// to handle it, if not then nothing needs to be done
|
|
|
|
if (currentState != this->InitialErrorState) {
|
|
|
|
// restore the initial error state
|
|
|
|
if (this->InitialErrorState) {
|
|
|
|
cmSystemTools::SetErrorOccured();
|
|
|
|
} else {
|
|
|
|
cmSystemTools::ResetErrorOccuredFlag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool InitialErrorState;
|
|
|
|
bool CaptureCMakeErrorValue;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
|
2016-08-17 02:49:57 +03:00
|
|
|
cmExecutionStatus& /*unused*/)
|
2005-06-23 21:04:18 +04:00
|
|
|
{
|
2016-07-28 22:12:43 +03:00
|
|
|
// save error state and restore it if needed
|
|
|
|
SaveRestoreErrorState errorState;
|
2009-01-12 17:10:47 +03:00
|
|
|
// Allocate space for argument values.
|
|
|
|
this->Values.clear();
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Values.resize(this->Last, CM_NULLPTR);
|
2009-01-12 17:10:47 +03:00
|
|
|
|
|
|
|
// Process input arguments.
|
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
2016-07-28 22:12:43 +03:00
|
|
|
// look at all arguments and do not short circuit on the first
|
|
|
|
// bad one so that CAPTURE_CMAKE_ERROR can override setting the
|
|
|
|
// global error state
|
|
|
|
bool foundBadArgument = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < args.size(); ++i) {
|
2009-01-12 17:10:47 +03:00
|
|
|
// Check this argument.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CheckArgumentKeyword(args[i]) &&
|
|
|
|
!this->CheckArgumentValue(args[i])) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-01-12 17:10:47 +03:00
|
|
|
e << "called with unknown argument \"" << args[i] << "\".";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2016-07-28 22:12:43 +03:00
|
|
|
foundBadArgument = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-07-28 22:12:43 +03:00
|
|
|
// note bad argument
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ArgumentDoing == ArgumentDoingError) {
|
2016-07-28 22:12:43 +03:00
|
|
|
foundBadArgument = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool capureCMakeError = (this->Values[ct_CAPTURE_CMAKE_ERROR] &&
|
|
|
|
*this->Values[ct_CAPTURE_CMAKE_ERROR]);
|
|
|
|
// now that arguments are parsed check to see if there is a
|
|
|
|
// CAPTURE_CMAKE_ERROR specified let the errorState object know.
|
|
|
|
if (capureCMakeError) {
|
|
|
|
errorState.CaptureCMakeError();
|
|
|
|
}
|
|
|
|
// if we found a bad argument then exit before running command
|
|
|
|
if (foundBadArgument) {
|
|
|
|
// store the cmake error
|
|
|
|
if (capureCMakeError) {
|
|
|
|
this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
|
|
|
|
"-1");
|
|
|
|
const char* err = this->GetError();
|
|
|
|
if (err && !cmSystemTools::FindLastString(err, "unknown error.")) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n");
|
|
|
|
}
|
|
|
|
// return success because failure is recorded in CAPTURE_CMAKE_ERROR
|
|
|
|
return true;
|
2005-06-23 21:04:18 +04:00
|
|
|
}
|
2016-07-28 22:12:43 +03:00
|
|
|
// return failure because of bad argument
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-06-23 21:04:18 +04:00
|
|
|
|
2009-12-04 20:09:01 +03: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");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ctestConfigType) {
|
2009-12-04 20:09:01 +03:00
|
|
|
this->CTest->SetConfigType(ctestConfigType);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-12-04 20:09:01 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Values[ct_BUILD]) {
|
|
|
|
this->CTest->SetCTestConfiguration(
|
|
|
|
"BuildDirectory",
|
|
|
|
cmSystemTools::CollapseFullPath(this->Values[ct_BUILD]).c_str(),
|
|
|
|
this->Quiet);
|
|
|
|
} else {
|
2012-08-13 21:42:58 +04:00
|
|
|
const char* bdir =
|
2008-12-19 05:57:42 +03:00
|
|
|
this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (bdir) {
|
|
|
|
this->CTest->SetCTestConfiguration(
|
|
|
|
"BuildDirectory", cmSystemTools::CollapseFullPath(bdir).c_str(),
|
|
|
|
this->Quiet);
|
|
|
|
} else {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "CTEST_BINARY_DIRECTORY not set"
|
|
|
|
<< std::endl;);
|
2006-03-29 21:01:24 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->Values[ct_SOURCE]) {
|
|
|
|
cmCTestLog(this->CTest, DEBUG, "Set source directory to: "
|
|
|
|
<< this->Values[ct_SOURCE] << std::endl);
|
|
|
|
this->CTest->SetCTestConfiguration(
|
|
|
|
"SourceDirectory",
|
|
|
|
cmSystemTools::CollapseFullPath(this->Values[ct_SOURCE]).c_str(),
|
|
|
|
this->Quiet);
|
|
|
|
} else {
|
|
|
|
this->CTest->SetCTestConfiguration(
|
|
|
|
"SourceDirectory",
|
2006-07-11 23:58:07 +04:00
|
|
|
cmSystemTools::CollapseFullPath(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"))
|
|
|
|
.c_str(),
|
2015-02-17 00:02:14 +03:00
|
|
|
this->Quiet);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-03-28 18:05:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* changeId =
|
|
|
|
this->Makefile->GetDefinition("CTEST_CHANGE_ID")) {
|
2015-07-08 04:50:32 +03:00
|
|
|
this->CTest->SetCTestConfiguration("ChangeId", changeId, this->Quiet);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-08 04:50:32 +03:00
|
|
|
|
2013-03-28 18:05:42 +04:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
|
|
|
|
cmCTestGenericHandler* handler = this->InitializeHandler();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!handler) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot instantiate test handler "
|
|
|
|
<< this->GetName() << std::endl);
|
2016-07-28 22:12:43 +03:00
|
|
|
if (capureCMakeError) {
|
|
|
|
this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
|
|
|
|
"-1");
|
|
|
|
const char* err = this->GetError();
|
|
|
|
if (err && !cmSystemTools::FindLastString(err, "unknown error.")) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-28 18:05:42 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-03-28 18:05:42 +04:00
|
|
|
|
|
|
|
handler->SetAppendXML(this->AppendXML);
|
|
|
|
|
|
|
|
handler->PopulateCustomVectors(this->Makefile);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Values[ct_SUBMIT_INDEX]) {
|
|
|
|
if (!this->CTest->GetDropSiteCDash() &&
|
|
|
|
this->CTest->GetDartVersion() <= 1) {
|
|
|
|
cmCTestLog(
|
|
|
|
this->CTest, ERROR_MESSAGE,
|
2006-03-09 19:17:10 +03:00
|
|
|
"Dart before version 2.0 does not support collecting submissions."
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl
|
|
|
|
<< "Please upgrade the server to Dart 2 or higher, or do not use "
|
|
|
|
"SUBMIT_INDEX."
|
|
|
|
<< std::endl);
|
|
|
|
} else {
|
2006-03-10 23:03:09 +03:00
|
|
|
handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
|
2005-06-23 21:04:18 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-06-23 21:04:18 +04:00
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
2006-03-09 19:17:10 +03:00
|
|
|
cmSystemTools::ChangeDirectory(
|
2014-10-15 16:54:05 +04:00
|
|
|
this->CTest->GetCTestConfiguration("BuildDirectory"));
|
2005-06-23 21:04:18 +04:00
|
|
|
int res = handler->ProcessHandler();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream str;
|
2005-06-23 21:04:18 +04:00
|
|
|
str << res;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE],
|
|
|
|
str.str().c_str());
|
|
|
|
}
|
2016-07-28 22:12:43 +03:00
|
|
|
// log the error message if there was an error
|
|
|
|
if (capureCMakeError) {
|
|
|
|
const char* returnString = "0";
|
|
|
|
if (cmSystemTools::GetErrorOccuredFlag()) {
|
|
|
|
returnString = "-1";
|
|
|
|
const char* err = this->GetError();
|
|
|
|
// print out the error if it is not "unknown error" which means
|
|
|
|
// there was no message
|
|
|
|
if (err && !cmSystemTools::FindLastString(err, "unknown error.")) {
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// store the captured cmake error state 0 or -1
|
|
|
|
this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
|
|
|
|
returnString);
|
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(current_dir);
|
2005-06-23 21:04:18 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-12 17:10:47 +03:00
|
|
|
bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
|
2005-06-23 21:04:18 +04:00
|
|
|
{
|
2009-01-12 17:11:29 +03:00
|
|
|
// Look for non-value arguments common to all commands.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg == "APPEND") {
|
2009-01-12 17:11:29 +03:00
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
this->AppendXML = true;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (arg == "QUIET") {
|
2015-02-17 00:02:14 +03:00
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
this->Quiet = true;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-12 17:11:29 +03:00
|
|
|
|
2009-01-12 17:10:47 +03:00
|
|
|
// Check for a keyword in our argument/value table.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int k = 0; k < this->Arguments.size(); ++k) {
|
|
|
|
if (this->Arguments[k] && arg == this->Arguments[k]) {
|
2009-01-12 17:10:47 +03:00
|
|
|
this->ArgumentDoing = ArgumentDoingKeyword;
|
|
|
|
this->ArgumentIndex = k;
|
|
|
|
return true;
|
2005-06-23 21:04:18 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-12 17:10:47 +03:00
|
|
|
return false;
|
|
|
|
}
|
2005-06-23 21:04:18 +04:00
|
|
|
|
2009-01-12 17:10:47 +03:00
|
|
|
bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ArgumentDoing == ArgumentDoingKeyword) {
|
2009-01-12 17:10:47 +03:00
|
|
|
this->ArgumentDoing = ArgumentDoingNone;
|
|
|
|
unsigned int k = this->ArgumentIndex;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Values[k]) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-01-12 17:10:47 +03:00
|
|
|
e << "Called with more than one value for " << this->Arguments[k];
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
this->ArgumentDoing = ArgumentDoingError;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-12 17:10:47 +03:00
|
|
|
this->Values[k] = arg.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k] << " to "
|
|
|
|
<< arg << "\n");
|
2009-01-12 17:10:47 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-12 17:10:47 +03:00
|
|
|
return false;
|
2005-06-23 21:04:18 +04:00
|
|
|
}
|