cmake/Source/CTest/cmCTestStartCommand.cxx

181 lines
5.6 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestStartCommand.h"
2020-02-01 23:06:01 +01:00
#include <cstddef>
#include <sstream>
#include "cmCTest.h"
2010-03-17 14:00:29 +02:00
#include "cmCTestVC.h"
#include "cmGeneratedFileStream.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
2010-03-17 14:00:29 +02:00
cmCTestStartCommand::cmCTestStartCommand()
{
this->CreateNewTag = true;
2015-08-17 11:37:30 +02:00
this->Quiet = false;
2010-03-17 14:00:29 +02:00
}
2016-07-09 11:21:54 +02:00
bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
2016-10-30 18:24:19 +01:00
cmExecutionStatus& /*unused*/)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
size_t cnt = 0;
2018-08-09 18:06:22 +02:00
const char* smodel = nullptr;
2018-01-26 17:06:56 +01:00
const char* src_dir = nullptr;
const char* bld_dir = nullptr;
2018-08-09 18:06:22 +02:00
while (cnt < args.size()) {
2020-02-01 23:06:01 +01:00
if (args[cnt] == "GROUP" || args[cnt] == "TRACK") {
2016-07-09 11:21:54 +02:00
cnt++;
2018-08-09 18:06:22 +02:00
if (cnt >= args.size() || args[cnt] == "APPEND" ||
args[cnt] == "QUIET") {
2020-02-01 23:06:01 +01:00
std::ostringstream e;
e << args[cnt - 1] << " argument missing group name";
this->SetError(e.str());
2018-08-09 18:06:22 +02:00
return false;
}
2020-02-01 23:06:01 +01:00
this->CTest->SetSpecificGroup(args[cnt].c_str());
2016-07-09 11:21:54 +02:00
cnt++;
2018-08-09 18:06:22 +02:00
} else if (args[cnt] == "APPEND") {
2016-07-09 11:21:54 +02:00
cnt++;
2010-03-17 14:00:29 +02:00
this->CreateNewTag = false;
2018-08-09 18:06:22 +02:00
} else if (args[cnt] == "QUIET") {
2016-07-09 11:21:54 +02:00
cnt++;
2015-08-17 11:37:30 +02:00
this->Quiet = true;
2018-08-09 18:06:22 +02:00
} else if (!smodel) {
smodel = args[cnt].c_str();
cnt++;
} else if (!src_dir) {
src_dir = args[cnt].c_str();
cnt++;
} else if (!bld_dir) {
bld_dir = args[cnt].c_str();
2018-08-09 18:06:22 +02:00
cnt++;
} else {
this->SetError("Too many arguments");
return false;
}
2016-07-09 11:21:54 +02:00
}
2018-08-09 18:06:22 +02:00
2016-07-09 11:21:54 +02:00
if (!src_dir) {
src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
2016-07-09 11:21:54 +02:00
}
if (!bld_dir) {
bld_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
2016-07-09 11:21:54 +02:00
}
if (!src_dir) {
this->SetError("source directory not specified. Specify source directory "
2016-07-09 11:21:54 +02:00
"as an argument or set CTEST_SOURCE_DIRECTORY");
return false;
2016-07-09 11:21:54 +02:00
}
if (!bld_dir) {
this->SetError("binary directory not specified. Specify binary directory "
2016-07-09 11:21:54 +02:00
"as an argument or set CTEST_BINARY_DIRECTORY");
return false;
2016-07-09 11:21:54 +02:00
}
2018-08-09 18:06:22 +02:00
if (!smodel && this->CreateNewTag) {
this->SetError("no test model specified and APPEND not specified. Specify "
"either a test model or the APPEND argument");
return false;
}
cmSystemTools::AddKeepPath(src_dir);
cmSystemTools::AddKeepPath(bld_dir);
this->CTest->EmptyCTestConfiguration();
2010-03-17 14:00:29 +02:00
std::string sourceDir = cmSystemTools::CollapseFullPath(src_dir);
std::string binaryDir = cmSystemTools::CollapseFullPath(bld_dir);
2015-08-17 11:37:30 +02:00
this->CTest->SetCTestConfiguration("SourceDirectory", sourceDir.c_str(),
2016-07-09 11:21:54 +02:00
this->Quiet);
2015-08-17 11:37:30 +02:00
this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str(),
2016-07-09 11:21:54 +02:00
this->Quiet);
2018-08-09 18:06:22 +02:00
if (smodel) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"Run dashboard with model "
<< smodel << std::endl
<< " Source directory: " << src_dir << std::endl
<< " Build directory: " << bld_dir << std::endl,
this->Quiet);
} else {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"Run dashboard with "
"to-be-determined model"
<< std::endl
<< " Source directory: " << src_dir << std::endl
<< " Build directory: " << bld_dir << std::endl,
this->Quiet);
}
2020-02-01 23:06:01 +01:00
const char* group = this->CTest->GetSpecificGroup();
if (group) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2020-02-01 23:06:01 +01:00
" Group: " << group << std::endl, this->Quiet);
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
// Log startup actions.
std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
2018-10-28 12:09:07 +01:00
cmGeneratedFileStream ofs(startLogFile);
2016-07-09 11:21:54 +02:00
if (!ofs) {
2010-03-17 14:00:29 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create log file: LastStart.log" << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
// Make sure the source directory exists.
2016-07-09 11:21:54 +02:00
if (!this->InitialCheckout(ofs, sourceDir)) {
2010-03-17 14:00:29 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
if (!cmSystemTools::FileIsDirectory(sourceDir)) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2010-03-17 14:00:29 +02:00
e << "given source path\n"
<< " " << sourceDir << "\n"
<< "which is not an existing directory. "
<< "Set CTEST_CHECKOUT_COMMAND to a command line to create it.";
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
2010-03-17 14:00:29 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2018-04-23 21:13:27 +02:00
this->CTest->SetRunCurrentScript(false);
this->CTest->SetSuppressUpdatingCTestConfiguration(true);
2018-08-09 18:06:22 +02:00
int model;
if (smodel) {
2019-11-11 23:01:05 +01:00
model = cmCTest::GetTestModelFromString(smodel);
2018-08-09 18:06:22 +02:00
} else {
model = cmCTest::UNKNOWN;
}
this->CTest->SetTestModel(model);
this->CTest->SetProduceXML(true);
2010-03-17 14:00:29 +02:00
return this->CTest->InitializeFromCommand(this);
}
2016-07-09 11:21:54 +02:00
bool cmCTestStartCommand::InitialCheckout(std::ostream& ofs,
std::string const& sourceDir)
2010-03-17 14:00:29 +02:00
{
// Use the user-provided command to create the source tree.
2016-07-09 11:21:54 +02:00
const char* initialCheckoutCommand =
this->Makefile->GetDefinition("CTEST_CHECKOUT_COMMAND");
if (!initialCheckoutCommand) {
2010-03-17 14:00:29 +02:00
initialCheckoutCommand =
this->Makefile->GetDefinition("CTEST_CVS_CHECKOUT");
2016-07-09 11:21:54 +02:00
}
if (initialCheckoutCommand) {
2010-03-17 14:00:29 +02:00
// Use a generic VC object to run and log the command.
cmCTestVC vc(this->CTest, ofs);
2015-04-27 22:25:09 +02:00
vc.SetSourceDirectory(sourceDir);
2016-07-09 11:21:54 +02:00
if (!vc.InitialCheckout(initialCheckoutCommand)) {
2010-03-17 14:00:29 +02:00
return false;
}
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
return true;
}