2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-06-04 00:10:55 +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-04 00:10:55 +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-04 00:10:55 +04:00
|
|
|
|
|
|
|
#include "cmCTestBuildAndTestHandler.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include <cmsys/Process.h>
|
2007-03-19 20:04:10 +03:00
|
|
|
#include "cmCTestTestHandler.h"
|
2013-11-14 19:14:35 +04:00
|
|
|
#include "cmCacheManager.h"
|
2005-06-04 00:10:55 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildTwoConfig = false;
|
|
|
|
this->BuildNoClean = false;
|
|
|
|
this->BuildNoCMake = false;
|
2007-01-25 19:16:16 +03:00
|
|
|
this->Timeout = 0;
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
|
2005-06-17 21:04:56 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestBuildAndTestHandler::Initialize()
|
|
|
|
{
|
2015-02-15 15:42:17 +03:00
|
|
|
this->BuildTargets.clear();
|
2005-06-23 21:04:18 +04:00
|
|
|
this->Superclass::Initialize();
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const char* cmCTestBuildAndTestHandler::GetOutput()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
return this->Output.c_str();
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestBuildAndTestHandler::ProcessHandler()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->Output = "";
|
2005-06-04 00:10:55 +04:00
|
|
|
std::string output;
|
|
|
|
cmSystemTools::ResetErrorOccuredFlag();
|
2006-03-10 23:03:09 +03:00
|
|
|
int retv = this->RunCMakeAndTest(&this->Output);
|
2005-06-04 00:10:55 +04:00
|
|
|
cmSystemTools::ResetErrorOccuredFlag();
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-03-09 19:17:10 +03:00
|
|
|
int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream &out, std::string &cmakeOutString, std::string &cwd,
|
2006-03-09 19:17:10 +03:00
|
|
|
cmake *cm)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
unsigned int k;
|
|
|
|
std::vector<std::string> args;
|
2013-11-08 00:30:59 +04:00
|
|
|
args.push_back(cmSystemTools::GetCMakeCommand());
|
2006-03-10 23:03:09 +03:00
|
|
|
args.push_back(this->SourceDir);
|
2015-01-16 01:04:33 +03:00
|
|
|
if(!this->BuildGenerator.empty())
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
std::string generator = "-G";
|
2006-03-10 23:03:09 +03:00
|
|
|
generator += this->BuildGenerator;
|
2005-06-04 00:10:55 +04:00
|
|
|
args.push_back(generator);
|
|
|
|
}
|
2014-09-05 23:14:13 +04:00
|
|
|
if(!this->BuildGeneratorPlatform.empty())
|
|
|
|
{
|
2014-09-12 18:37:07 +04:00
|
|
|
std::string platform = "-A";
|
2014-09-05 23:14:13 +04:00
|
|
|
platform += this->BuildGeneratorPlatform;
|
|
|
|
args.push_back(platform);
|
|
|
|
}
|
2015-01-16 01:04:33 +03:00
|
|
|
if(!this->BuildGeneratorToolset.empty())
|
2012-12-11 01:53:56 +04:00
|
|
|
{
|
|
|
|
std::string toolset = "-T";
|
|
|
|
toolset += this->BuildGeneratorToolset;
|
|
|
|
args.push_back(toolset);
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-09-11 22:43:17 +04:00
|
|
|
const char* config = 0;
|
2015-01-15 02:06:11 +03:00
|
|
|
if (!this->CTest->GetConfigType().empty())
|
2007-09-11 22:43:17 +04:00
|
|
|
{
|
|
|
|
config = this->CTest->GetConfigType().c_str();
|
|
|
|
}
|
|
|
|
#ifdef CMAKE_INTDIR
|
2008-09-04 19:31:10 +04:00
|
|
|
if(!config)
|
|
|
|
{
|
|
|
|
config = CMAKE_INTDIR;
|
|
|
|
}
|
2007-09-11 22:43:17 +04:00
|
|
|
#endif
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-09-11 22:43:17 +04:00
|
|
|
if ( config )
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
std::string btype
|
2007-09-11 22:43:17 +04:00
|
|
|
= "-DCMAKE_BUILD_TYPE:STRING=" + std::string(config);
|
2005-06-04 00:10:55 +04:00
|
|
|
args.push_back(btype);
|
|
|
|
}
|
|
|
|
|
2006-03-10 23:03:09 +03:00
|
|
|
for(k=0; k < this->BuildOptions.size(); ++k)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
args.push_back(this->BuildOptions[k]);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
if (cm->Run(args) != 0)
|
|
|
|
{
|
|
|
|
out << "Error: cmake execution failed\n";
|
|
|
|
out << cmakeOutString << "\n";
|
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2005-06-04 00:10:55 +04:00
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// do another config?
|
2006-03-10 23:03:09 +03:00
|
|
|
if(this->BuildTwoConfig)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
if (cm->Run(args) != 0)
|
|
|
|
{
|
|
|
|
out << "Error: cmake execution failed\n";
|
|
|
|
out << cmakeOutString << "\n";
|
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2005-06-04 00:10:55 +04:00
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
}
|
2006-08-08 23:55:41 +04:00
|
|
|
out << "======== CMake output ======\n";
|
|
|
|
out << cmakeOutString;
|
|
|
|
out << "======== End CMake output ======\n";
|
2005-06-04 00:10:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
|
|
|
|
{
|
|
|
|
std::string* out = (std::string*)s;
|
|
|
|
*out += m;
|
|
|
|
*out += "\n";
|
|
|
|
}
|
|
|
|
|
2008-06-18 17:07:53 +04:00
|
|
|
void CMakeProgressCallback(const char*msg, float , void * s)
|
|
|
|
{
|
|
|
|
std::string* out = (std::string*)s;
|
|
|
|
*out += msg;
|
|
|
|
*out += "\n";
|
|
|
|
}
|
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
//----------------------------------------------------------------------
|
2014-05-15 17:44:25 +04:00
|
|
|
void CMakeOutputCallback(const char* m, size_t len, void* s)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
std::string* out = (std::string*)s;
|
|
|
|
out->append(m, len);
|
|
|
|
}
|
2014-05-15 18:19:29 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class cmCTestBuildAndTestCaptureRAII
|
2009-06-15 21:51:07 +04:00
|
|
|
{
|
2014-05-15 18:19:29 +04:00
|
|
|
cmake& CM;
|
|
|
|
public:
|
|
|
|
cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s): CM(cm)
|
|
|
|
{
|
2014-05-15 17:38:30 +04:00
|
|
|
cmSystemTools::SetMessageCallback(CMakeMessageCallback, &s);
|
2014-05-15 17:44:25 +04:00
|
|
|
cmSystemTools::SetStdoutCallback(CMakeOutputCallback, &s);
|
|
|
|
cmSystemTools::SetStderrCallback(CMakeOutputCallback, &s);
|
2014-05-15 18:19:29 +04:00
|
|
|
this->CM.SetProgressCallback(CMakeProgressCallback, &s);
|
|
|
|
}
|
|
|
|
~cmCTestBuildAndTestCaptureRAII()
|
|
|
|
{
|
|
|
|
this->CM.SetProgressCallback(0, 0);
|
2014-05-15 17:44:25 +04:00
|
|
|
cmSystemTools::SetStderrCallback(0, 0);
|
2009-06-15 21:51:07 +04:00
|
|
|
cmSystemTools::SetStdoutCallback(0, 0);
|
2014-05-15 17:38:30 +04:00
|
|
|
cmSystemTools::SetMessageCallback(0, 0);
|
2014-05-15 18:19:29 +04:00
|
|
|
}
|
2009-06-15 21:51:07 +04:00
|
|
|
};
|
2005-06-04 00:10:55 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
|
2006-03-09 19:17:10 +03:00
|
|
|
{
|
2005-06-04 00:10:55 +04:00
|
|
|
// if the generator and make program are not specified then it is an error
|
2015-01-16 01:13:44 +03:00
|
|
|
if (this->BuildGenerator.empty())
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
if(outstring)
|
|
|
|
{
|
2006-03-09 19:17:10 +03:00
|
|
|
*outstring =
|
2013-11-14 19:14:35 +04:00
|
|
|
"--build-and-test requires that the generator "
|
|
|
|
"be provided using the --build-generator "
|
|
|
|
"command line option. ";
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2014-05-15 18:19:29 +04:00
|
|
|
cmake cm;
|
|
|
|
std::string cmakeOutString;
|
|
|
|
cmCTestBuildAndTestCaptureRAII captureRAII(cm, cmakeOutString);
|
|
|
|
static_cast<void>(captureRAII);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream out;
|
2014-05-15 18:19:29 +04:00
|
|
|
|
2015-01-15 02:31:49 +03:00
|
|
|
if ( this->CTest->GetConfigType().empty() &&
|
2015-01-16 01:04:33 +03:00
|
|
|
!this->ConfigSample.empty())
|
2007-03-19 20:04:10 +03:00
|
|
|
{
|
|
|
|
// use the config sample to set the ConfigType
|
|
|
|
std::string fullPath;
|
|
|
|
std::string resultingConfig;
|
|
|
|
std::vector<std::string> extraPaths;
|
|
|
|
std::vector<std::string> failed;
|
2012-08-13 21:42:58 +04:00
|
|
|
fullPath =
|
|
|
|
cmCTestTestHandler::FindExecutable(this->CTest,
|
2007-03-19 20:04:10 +03:00
|
|
|
this->ConfigSample.c_str(),
|
|
|
|
resultingConfig,
|
|
|
|
extraPaths,
|
|
|
|
failed);
|
2015-01-16 01:04:33 +03:00
|
|
|
if (!fullPath.empty() && !resultingConfig.empty())
|
2007-03-19 20:04:10 +03:00
|
|
|
{
|
|
|
|
this->CTest->SetConfigType(resultingConfig.c_str());
|
|
|
|
}
|
|
|
|
out << "Using config sample with results: "
|
|
|
|
<< fullPath << " and " << resultingConfig << std::endl;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-01-30 19:35:17 +03:00
|
|
|
// we need to honor the timeout specified, the timeout include cmake, build
|
|
|
|
// and test time
|
|
|
|
double clock_start = cmSystemTools::GetTime();
|
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
// make sure the binary dir is there
|
|
|
|
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
2006-03-10 23:03:09 +03:00
|
|
|
out << "Internal cmake changing into directory: "
|
|
|
|
<< this->BinaryDir << std::endl;
|
2014-10-15 16:54:05 +04:00
|
|
|
if (!cmSystemTools::FileIsDirectory(this->BinaryDir))
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(this->BinaryDir);
|
2005-06-04 00:10:55 +04:00
|
|
|
|
2012-12-11 01:53:56 +04:00
|
|
|
if(this->BuildNoCMake)
|
|
|
|
{
|
2013-11-14 19:14:35 +04:00
|
|
|
// Make the generator available for the Build call below.
|
2012-12-11 01:53:56 +04:00
|
|
|
cm.SetGlobalGenerator(cm.CreateGlobalGenerator(
|
2014-03-11 03:04:11 +04:00
|
|
|
this->BuildGenerator));
|
2014-09-05 23:14:13 +04:00
|
|
|
cm.SetGeneratorPlatform(this->BuildGeneratorPlatform);
|
2012-12-11 01:53:56 +04:00
|
|
|
cm.SetGeneratorToolset(this->BuildGeneratorToolset);
|
2013-11-14 19:14:35 +04:00
|
|
|
|
|
|
|
// Load the cache to make CMAKE_MAKE_PROGRAM available.
|
2014-03-11 03:04:11 +04:00
|
|
|
cm.GetCacheManager()->LoadCache(this->BinaryDir);
|
2012-12-11 01:53:56 +04:00
|
|
|
}
|
|
|
|
else
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2007-01-30 19:35:17 +03:00
|
|
|
// do the cmake step, no timeout here since it is not a sub process
|
2005-06-04 00:10:55 +04:00
|
|
|
if (this->RunCMake(outstring,out,cmakeOutString,cwd,&cm))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do the build
|
2006-02-28 16:23:40 +03:00
|
|
|
std::vector<std::string>::iterator tarIt;
|
2015-01-15 02:31:49 +03:00
|
|
|
if (this->BuildTargets.empty())
|
2006-02-28 16:23:40 +03:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildTargets.push_back("");
|
2006-02-28 16:23:40 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
for ( tarIt = this->BuildTargets.begin();
|
2007-06-06 19:02:24 +04:00
|
|
|
tarIt != this->BuildTargets.end(); ++ tarIt )
|
2006-02-28 16:23:40 +03:00
|
|
|
{
|
2007-01-30 19:35:17 +03:00
|
|
|
double remainingTime = 0;
|
2009-10-14 00:39:48 +04:00
|
|
|
if (this->Timeout > 0)
|
2007-01-30 19:35:17 +03:00
|
|
|
{
|
|
|
|
remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
|
|
|
|
if (remainingTime <= 0)
|
|
|
|
{
|
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = "--build-and-test timeout exceeded. ";
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2006-02-28 16:23:40 +03:00
|
|
|
std::string output;
|
2007-09-11 22:43:17 +04:00
|
|
|
const char* config = 0;
|
2015-01-15 02:06:11 +03:00
|
|
|
if (!this->CTest->GetConfigType().empty())
|
2007-09-11 22:43:17 +04:00
|
|
|
{
|
|
|
|
config = this->CTest->GetConfigType().c_str();
|
|
|
|
}
|
|
|
|
#ifdef CMAKE_INTDIR
|
2008-09-04 19:31:10 +04:00
|
|
|
if(!config)
|
|
|
|
{
|
|
|
|
config = CMAKE_INTDIR;
|
|
|
|
}
|
2007-09-11 22:43:17 +04:00
|
|
|
#endif
|
|
|
|
if(!config)
|
|
|
|
{
|
|
|
|
config = "Debug";
|
|
|
|
}
|
2006-03-23 23:35:03 +03:00
|
|
|
int retVal = cm.GetGlobalGenerator()->Build(
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SourceDir, this->BinaryDir,
|
|
|
|
this->BuildProject, *tarIt,
|
2014-07-31 20:48:46 +04:00
|
|
|
output, this->BuildMakeProgram,
|
2007-09-11 22:43:17 +04:00
|
|
|
config,
|
2012-08-13 21:42:58 +04:00
|
|
|
!this->BuildNoClean,
|
2007-01-30 19:35:17 +03:00
|
|
|
false, remainingTime);
|
2006-02-28 16:23:40 +03:00
|
|
|
out << output;
|
|
|
|
// if the build failed then return
|
|
|
|
if (retVal)
|
|
|
|
{
|
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2005-06-04 00:10:55 +04:00
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2007-01-25 19:16:16 +03:00
|
|
|
// if no test was specified then we are done
|
2015-01-16 01:13:44 +03:00
|
|
|
if (this->TestCommand.empty())
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
// now run the compiled test if we can find it
|
2007-03-19 20:04:10 +03:00
|
|
|
// store the final location in fullPath
|
|
|
|
std::string fullPath;
|
|
|
|
std::string resultingConfig;
|
|
|
|
std::vector<std::string> extraPaths;
|
2006-03-10 23:03:09 +03:00
|
|
|
// if this->ExecutableDirectory is set try that as well
|
2015-01-16 01:04:33 +03:00
|
|
|
if (!this->ExecutableDirectory.empty())
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2007-03-19 20:04:10 +03:00
|
|
|
std::string tempPath = this->ExecutableDirectory;
|
2005-06-04 00:10:55 +04:00
|
|
|
tempPath += "/";
|
2006-03-10 23:03:09 +03:00
|
|
|
tempPath += this->TestCommand;
|
2007-03-19 20:04:10 +03:00
|
|
|
extraPaths.push_back(tempPath);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2007-03-19 20:04:10 +03:00
|
|
|
std::vector<std::string> failed;
|
2012-08-13 21:42:58 +04:00
|
|
|
fullPath =
|
|
|
|
cmCTestTestHandler::FindExecutable(this->CTest,
|
2007-03-19 20:04:10 +03:00
|
|
|
this->TestCommand.c_str(),
|
|
|
|
resultingConfig,
|
|
|
|
extraPaths,
|
|
|
|
failed);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
if(!cmSystemTools::FileExists(fullPath.c_str()))
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
out << "Could not find path to executable, perhaps it was not built: "
|
|
|
|
<< this->TestCommand << "\n";
|
2005-06-04 00:10:55 +04:00
|
|
|
out << "tried to find it in these places:\n";
|
|
|
|
out << fullPath.c_str() << "\n";
|
|
|
|
for(unsigned int i=0; i < failed.size(); ++i)
|
|
|
|
{
|
|
|
|
out << failed[i] << "\n";
|
|
|
|
}
|
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str());
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
// return to the original directory
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(cwd);
|
2005-06-04 00:10:55 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const char*> testCommand;
|
|
|
|
testCommand.push_back(fullPath.c_str());
|
2014-05-15 18:16:48 +04:00
|
|
|
for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
testCommand.push_back(this->TestCommandArgs[k].c_str());
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
testCommand.push_back(0);
|
|
|
|
std::string outs;
|
|
|
|
int retval = 0;
|
2006-03-10 23:03:09 +03:00
|
|
|
// run the test from the this->BuildRunDir if set
|
2015-01-16 01:04:33 +03:00
|
|
|
if(!this->BuildRunDir.empty())
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
out << "Run test in directory: " << this->BuildRunDir << "\n";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::ChangeDirectory(this->BuildRunDir);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2008-12-18 20:27:59 +03:00
|
|
|
out << "Running test command: \"" << fullPath << "\"";
|
2014-05-15 18:16:48 +04:00
|
|
|
for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2008-12-18 20:27:59 +03:00
|
|
|
out << " \"" << this->TestCommandArgs[k] << "\"";
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
out << "\n";
|
2007-01-30 19:35:17 +03:00
|
|
|
|
|
|
|
// how much time is remaining
|
2007-06-06 19:02:24 +04:00
|
|
|
double remainingTime = 0;
|
2009-10-14 00:39:48 +04:00
|
|
|
if (this->Timeout > 0)
|
2007-06-06 19:02:24 +04:00
|
|
|
{
|
|
|
|
remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
|
|
|
|
if (remainingTime <= 0)
|
2007-01-30 19:35:17 +03:00
|
|
|
{
|
2007-06-06 19:02:24 +04:00
|
|
|
if(outstring)
|
2007-01-30 19:35:17 +03:00
|
|
|
{
|
2007-06-06 19:02:24 +04:00
|
|
|
*outstring = "--build-and-test timeout exceeded. ";
|
2007-01-30 19:35:17 +03:00
|
|
|
}
|
2007-06-06 19:02:24 +04:00
|
|
|
return 1;
|
2007-01-30 19:35:17 +03:00
|
|
|
}
|
2007-06-06 19:02:24 +04:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
|
|
int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval, 0,
|
2008-11-26 22:38:43 +03:00
|
|
|
remainingTime, 0);
|
2007-01-30 19:35:17 +03:00
|
|
|
|
2005-06-04 00:10:55 +04:00
|
|
|
if(runTestRes != cmsysProcess_State_Exited || retval != 0)
|
|
|
|
{
|
2008-12-18 20:27:59 +03:00
|
|
|
out << "Test command failed: " << testCommand[0] << "\n";
|
2005-06-04 00:10:55 +04:00
|
|
|
retval = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << outs << "\n";
|
|
|
|
if(outstring)
|
|
|
|
{
|
|
|
|
*outstring = out.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, OUTPUT, out.str() << std::endl);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int cmCTestBuildAndTestHandler::ProcessCommandLineArguments(
|
|
|
|
const std::string& currentArg, size_t& idx,
|
|
|
|
const std::vector<std::string>& allArgs)
|
|
|
|
{
|
|
|
|
// --build-and-test options
|
|
|
|
if(currentArg.find("--build-and-test",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
if(idx+2 < allArgs.size())
|
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->SourceDir = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BinaryDir = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
// dir must exist before CollapseFullPath is called
|
2006-03-10 23:03:09 +03:00
|
|
|
cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
|
|
|
|
this->BinaryDir
|
2014-10-15 16:54:05 +04:00
|
|
|
= cmSystemTools::CollapseFullPath(this->BinaryDir);
|
2006-03-10 23:03:09 +03:00
|
|
|
this->SourceDir
|
2014-10-15 16:54:05 +04:00
|
|
|
= cmSystemTools::CollapseFullPath(this->SourceDir);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2006-03-09 19:17:10 +03:00
|
|
|
"--build-and-test must have source and binary dir" << std::endl);
|
2005-06-04 00:10:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(currentArg.find("--build-target",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildTargets.push_back(allArgs[idx]);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
if(currentArg.find("--build-nocmake",0) == 0)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildNoCMake = true;
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
if(currentArg.find("--build-run-dir",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildRunDir = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
if(currentArg.find("--build-two-config",0) == 0)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildTwoConfig = true;
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
if(currentArg.find("--build-exe-dir",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->ExecutableDirectory = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2007-01-25 19:16:16 +03:00
|
|
|
if(currentArg.find("--test-timeout",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
this->Timeout = atof(allArgs[idx].c_str());
|
|
|
|
}
|
2012-12-11 01:53:56 +04:00
|
|
|
if(currentArg == "--build-generator" && idx < allArgs.size() - 1)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildGenerator = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2014-09-05 23:14:13 +04:00
|
|
|
if(currentArg == "--build-generator-platform" &&
|
|
|
|
idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
this->BuildGeneratorPlatform = allArgs[idx];
|
|
|
|
}
|
2012-12-11 01:53:56 +04:00
|
|
|
if(currentArg == "--build-generator-toolset" &&
|
|
|
|
idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
this->BuildGeneratorToolset = allArgs[idx];
|
|
|
|
}
|
2005-06-04 00:10:55 +04:00
|
|
|
if(currentArg.find("--build-project",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildProject = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2006-03-09 19:17:10 +03:00
|
|
|
if(currentArg.find("--build-makeprogram",0) == 0 &&
|
|
|
|
idx < allArgs.size() - 1)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
|
|
|
idx++;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildMakeProgram = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2007-03-19 20:04:10 +03:00
|
|
|
if(currentArg.find("--build-config-sample",0) == 0 &&
|
|
|
|
idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
this->ConfigSample = allArgs[idx];
|
|
|
|
}
|
2005-06-04 00:10:55 +04:00
|
|
|
if(currentArg.find("--build-noclean",0) == 0)
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildNoClean = true;
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
2013-11-15 17:28:25 +04:00
|
|
|
if(currentArg.find("--build-options",0) == 0)
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2013-11-15 17:28:25 +04:00
|
|
|
while(idx+1 < allArgs.size() &&
|
|
|
|
allArgs[idx+1] != "--build-target" &&
|
|
|
|
allArgs[idx+1] != "--test-command")
|
2005-06-04 00:10:55 +04:00
|
|
|
{
|
2013-11-15 17:28:25 +04:00
|
|
|
++idx;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->BuildOptions.push_back(allArgs[idx]);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(currentArg.find("--test-command",0) == 0 && idx < allArgs.size() - 1)
|
|
|
|
{
|
|
|
|
++idx;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->TestCommand = allArgs[idx];
|
2005-06-04 00:10:55 +04:00
|
|
|
while(idx+1 < allArgs.size())
|
|
|
|
{
|
|
|
|
++idx;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->TestCommandArgs.push_back(allArgs[idx]);
|
2005-06-04 00:10:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|