cmake/Source/CTest/cmCTestGenericHandler.cxx

177 lines
5.1 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 "cmCTestGenericHandler.h"
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include <sstream>
#include <utility>
2017-04-14 19:02:05 +02:00
#include "cmCTest.h"
2021-09-14 00:13:48 +02:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
cmCTestGenericHandler::cmCTestGenericHandler()
{
2012-02-18 12:40:36 +02:00
this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
2018-01-26 17:06:56 +01:00
this->CTest = nullptr;
this->SubmitIndex = 0;
2009-10-04 10:30:41 +03:00
this->AppendXML = false;
2015-08-17 11:37:30 +02:00
this->Quiet = false;
2015-11-17 17:22:37 +01:00
this->TestLoad = 0;
}
2019-11-11 23:01:05 +01:00
cmCTestGenericHandler::~cmCTestGenericHandler() = default;
2021-11-20 13:41:27 +01:00
namespace {
2021-09-14 00:13:48 +02:00
/* Modify the given `map`, setting key `op` to `value` if `value`
* is non-null, otherwise removing key `op` (if it exists).
*/
2021-11-20 13:41:27 +01:00
void SetMapValue(cmCTestGenericHandler::t_StringToString& map,
2023-05-23 16:38:00 +02:00
const std::string& op, const std::string& value)
{
2021-09-14 00:13:48 +02:00
map[op] = value;
}
2021-11-20 13:41:27 +01:00
void SetMapValue(cmCTestGenericHandler::t_StringToString& map,
const std::string& op, cmValue value)
{
if (!value) {
map.erase(op);
return;
}
map[op] = *value;
}
}
2021-09-14 00:13:48 +02:00
2023-05-23 16:38:00 +02:00
void cmCTestGenericHandler::SetOption(const std::string& op,
const std::string& value)
2021-09-14 00:13:48 +02:00
{
SetMapValue(this->Options, op, value);
}
2021-11-20 13:41:27 +01:00
void cmCTestGenericHandler::SetOption(const std::string& op, cmValue value)
{
SetMapValue(this->Options, op, value);
}
2015-04-27 22:25:09 +02:00
void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
2023-05-23 16:38:00 +02:00
const std::string& value)
{
this->SetOption(op, value);
2021-09-14 00:13:48 +02:00
SetMapValue(this->PersistentOptions, op, value);
}
2021-11-20 13:41:27 +01:00
void cmCTestGenericHandler::SetPersistentOption(const std::string& op,
cmValue value)
{
this->SetOption(op, value);
SetMapValue(this->PersistentOptions, op, value);
}
2021-09-14 00:13:48 +02:00
void cmCTestGenericHandler::AddMultiOption(const std::string& op,
const std::string& value)
{
if (!value.empty()) {
this->MultiOptions[op].emplace_back(value);
2016-07-09 11:21:54 +02:00
}
2021-09-14 00:13:48 +02:00
}
2021-09-14 00:13:48 +02:00
void cmCTestGenericHandler::AddPersistentMultiOption(const std::string& op,
const std::string& value)
{
if (!value.empty()) {
this->MultiOptions[op].emplace_back(value);
this->PersistentMultiOptions[op].emplace_back(value);
}
}
void cmCTestGenericHandler::Initialize()
{
2009-10-04 10:30:41 +03:00
this->AppendXML = false;
2015-11-17 17:22:37 +01:00
this->TestLoad = 0;
2021-09-14 00:13:48 +02:00
this->Options = this->PersistentOptions;
this->MultiOptions = this->PersistentMultiOptions;
}
2021-11-20 13:41:27 +01:00
cmValue cmCTestGenericHandler::GetOption(const std::string& op)
{
2020-02-01 23:06:01 +01:00
auto remit = this->Options.find(op);
2016-07-09 11:21:54 +02:00
if (remit == this->Options.end()) {
2018-01-26 17:06:56 +01:00
return nullptr;
2016-07-09 11:21:54 +02:00
}
2021-11-20 13:41:27 +01:00
return cmValue(remit->second);
}
2021-09-14 00:13:48 +02:00
std::vector<std::string> cmCTestGenericHandler::GetMultiOption(
const std::string& optionName) const
{
// Avoid inserting a key, which MultiOptions[op] would do.
auto remit = this->MultiOptions.find(optionName);
if (remit == this->MultiOptions.end()) {
return {};
}
return remit->second;
}
2009-10-04 10:30:41 +03:00
bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
const char* name,
cmGeneratedFileStream& xofs)
{
2016-07-09 11:21:54 +02:00
if (!name) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Cannot create resulting XML file without providing the name"
2023-05-23 16:38:00 +02:00
<< std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
std::ostringstream ostr;
ostr << name;
2016-07-09 11:21:54 +02:00
if (this->SubmitIndex > 0) {
ostr << "_" << this->SubmitIndex;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
ostr << ".xml";
2016-07-09 11:21:54 +02:00
if (this->CTest->GetCurrentTag().empty()) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2009-10-04 10:30:41 +03:00
"Current Tag empty, this may mean NightlyStartTime / "
"CTEST_NIGHTLY_START_TIME was not set correctly. Or "
"maybe you forgot to call ctest_start() before calling "
2016-07-09 11:21:54 +02:00
"ctest_configure()."
<< std::endl);
2022-08-04 22:12:04 +02:00
cmSystemTools::SetFatalErrorOccurred();
return false;
2016-07-09 11:21:54 +02:00
}
if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), ostr.str(),
xofs, true)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create resulting XML file: " << ostr.str()
<< std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
2021-09-14 00:13:48 +02:00
this->CTest->AddSubmitFile(part, ostr.str());
return true;
}
bool cmCTestGenericHandler::StartLogFile(const char* name,
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream& xofs)
{
2016-07-09 11:21:54 +02:00
if (!name) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Cannot create log file without providing the name"
2023-05-23 16:38:00 +02:00
<< std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
std::ostringstream ostr;
ostr << "Last" << name;
2016-07-09 11:21:54 +02:00
if (this->SubmitIndex > 0) {
ostr << "_" << this->SubmitIndex;
2016-07-09 11:21:54 +02:00
}
if (!this->CTest->GetCurrentTag().empty()) {
ostr << "_" << this->CTest->GetCurrentTag();
2016-07-09 11:21:54 +02:00
}
ostr << ".log";
2021-09-14 00:13:48 +02:00
this->LogFileNames[name] =
cmStrCat(this->CTest->GetBinaryDir(), "/Testing/Temporary/", ostr.str());
2016-07-09 11:21:54 +02:00
if (!this->CTest->OpenOutputFile("Temporary", ostr.str(), xofs)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create log file: " << ostr.str() << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
return true;
}