cmake/Source/CTest/cmCTestSubmitCommand.cxx

201 lines
6.7 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 "cmCTestSubmitCommand.h"
2020-02-01 23:06:01 +01:00
#include <set>
#include <sstream>
#include <utility>
#include <cm/memory>
2020-08-30 11:54:41 +02:00
#include <cm/vector>
#include <cmext/algorithm>
#include <cmext/string_view>
2020-02-01 23:06:01 +01:00
#include "cmCTest.h"
2009-10-04 10:30:41 +03:00
#include "cmCTestSubmitHandler.h"
2020-02-01 23:06:01 +01:00
#include "cmCommand.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2020-02-01 23:06:01 +01:00
#include "cmRange.h"
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
class cmExecutionStatus;
2019-11-11 23:01:05 +01:00
/**
* This is a virtual constructor for the command.
*/
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmCommand> cmCTestSubmitCommand::Clone()
2019-11-11 23:01:05 +01:00
{
2020-02-01 23:06:01 +01:00
auto ni = cm::make_unique<cmCTestSubmitCommand>();
2019-11-11 23:01:05 +01:00
ni->CTest = this->CTest;
ni->CTestScriptHandler = this->CTestScriptHandler;
2020-02-01 23:06:01 +01:00
return std::unique_ptr<cmCommand>(std::move(ni));
2019-11-11 23:01:05 +01:00
}
cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
{
2019-11-11 23:01:05 +01:00
const char* submitURL = !this->SubmitURL.empty()
? this->SubmitURL.c_str()
: this->Makefile->GetDefinition("CTEST_SUBMIT_URL");
2009-05-01 17:43:35 +03:00
2019-11-11 23:01:05 +01:00
if (submitURL) {
this->CTest->SetCTestConfiguration("SubmitURL", submitURL, this->Quiet);
} else {
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "DropMethod", "CTEST_DROP_METHOD", this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "DropSiteUser", "CTEST_DROP_SITE_USER", this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "DropSitePassword", "CTEST_DROP_SITE_PASSWORD",
this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "DropSite", "CTEST_DROP_SITE", this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "DropLocation", "CTEST_DROP_LOCATION", this->Quiet);
2016-07-09 11:21:54 +02:00
}
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "CurlOptions", "CTEST_CURL_OPTIONS", this->Quiet);
2016-07-09 11:21:54 +02:00
const char* notesFilesVariable =
this->Makefile->GetDefinition("CTEST_NOTES_FILES");
if (notesFilesVariable) {
2020-02-01 23:06:01 +01:00
std::vector<std::string> notesFiles = cmExpandedList(notesFilesVariable);
2019-11-11 23:01:05 +01:00
this->CTest->GenerateNotesFile(notesFiles);
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
const char* extraFilesVariable =
this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
if (extraFilesVariable) {
2020-02-01 23:06:01 +01:00
std::vector<std::string> extraFiles = cmExpandedList(extraFilesVariable);
2019-11-11 23:01:05 +01:00
if (!this->CTest->SubmitExtraFiles(extraFiles)) {
this->SetError("problem submitting extra files.");
2018-01-26 17:06:56 +01:00
return nullptr;
}
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
handler->Initialize();
2009-10-04 10:30:41 +03:00
// If no FILES or PARTS given, *all* PARTS are submitted by default.
//
// If FILES are given, but not PARTS, only the FILES are submitted
// and *no* PARTS are submitted.
// (This is why we select the empty "noParts" set in the
// FilesMentioned block below...)
//
// If PARTS are given, only the selected PARTS are submitted.
//
// If both PARTS and FILES are given, only the selected PARTS *and*
// all the given FILES are submitted.
// If given explicit FILES to submit, pass them to the handler.
//
2016-07-09 11:21:54 +02:00
if (this->FilesMentioned) {
2009-10-04 10:30:41 +03:00
// Intentionally select *no* PARTS. (Pass an empty set.) If PARTS
// were also explicitly mentioned, they will be selected below...
// But FILES with no PARTS mentioned should just submit the FILES
// without any of the default parts.
//
2019-11-11 23:01:05 +01:00
handler->SelectParts(std::set<cmCTest::Part>());
2020-02-01 23:06:01 +01:00
handler->SelectFiles(
std::set<std::string>(this->Files.begin(), this->Files.end()));
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// If a PARTS option was given, select only the named parts for submission.
//
2016-07-09 11:21:54 +02:00
if (this->PartsMentioned) {
2020-02-01 23:06:01 +01:00
auto parts =
cmMakeRange(this->Parts).transform([this](std::string const& arg) {
return this->CTest->GetPartFromName(arg.c_str());
});
handler->SelectParts(std::set<cmCTest::Part>(parts.begin(), parts.end()));
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2017-07-20 19:35:53 +02:00
// Pass along any HTTPHEADER to the handler if this option was given.
if (!this->HttpHeaders.empty()) {
2019-11-11 23:01:05 +01:00
handler->SetHttpHeaders(this->HttpHeaders);
2017-07-20 19:35:53 +02:00
}
2019-11-11 23:01:05 +01:00
handler->SetOption("RetryDelay", this->RetryDelay.c_str());
handler->SetOption("RetryCount", this->RetryCount.c_str());
handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
2010-11-13 01:00:53 +02:00
2015-08-17 11:37:30 +02:00
handler->SetQuiet(this->Quiet);
2016-07-09 11:21:54 +02:00
if (this->CDashUpload) {
2019-11-11 23:01:05 +01:00
handler->SetOption("CDashUploadFile", this->CDashUploadFile.c_str());
handler->SetOption("CDashUploadType", this->CDashUploadType.c_str());
2016-07-09 11:21:54 +02:00
}
return handler;
}
2015-04-27 22:25:09 +02:00
bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
2019-11-11 23:01:05 +01:00
bool ret = this->cmCTestHandlerCommand::InitialPass(args, status);
2020-02-01 23:06:01 +01:00
if (!this->BuildID.empty()) {
this->Makefile->AddDefinition(this->BuildID, this->CTest->GetBuildID());
2019-11-11 23:01:05 +01:00
}
return ret;
2015-04-27 22:25:09 +02:00
}
2020-02-01 23:06:01 +01:00
void cmCTestSubmitCommand::BindArguments()
2009-10-04 10:30:41 +03:00
{
2016-07-09 11:21:54 +02:00
if (this->CDashUpload) {
2017-04-14 19:02:05 +02:00
// Arguments specific to the CDASH_UPLOAD signature.
2020-02-01 23:06:01 +01:00
this->Bind("CDASH_UPLOAD", this->CDashUploadFile);
this->Bind("CDASH_UPLOAD_TYPE", this->CDashUploadType);
2016-07-09 11:21:54 +02:00
} else {
2017-04-14 19:02:05 +02:00
// Arguments that cannot be used with CDASH_UPLOAD.
2020-02-01 23:06:01 +01:00
this->Bind("PARTS"_s, this->Parts);
this->Bind("FILES"_s, this->Files);
2017-04-14 19:02:05 +02:00
}
// Arguments used by both modes.
2020-02-01 23:06:01 +01:00
this->Bind("BUILD_ID"_s, this->BuildID);
this->Bind("HTTPHEADER"_s, this->HttpHeaders);
this->Bind("RETRY_COUNT"_s, this->RetryCount);
this->Bind("RETRY_DELAY"_s, this->RetryDelay);
this->Bind("SUBMIT_URL"_s, this->SubmitURL);
this->Bind("INTERNAL_TEST_CHECKSUM", this->InternalTest);
2010-11-13 01:00:53 +02:00
2009-10-04 10:30:41 +03:00
// Look for other arguments.
2020-02-01 23:06:01 +01:00
this->cmCTestHandlerCommand::BindArguments();
2009-10-04 10:30:41 +03:00
}
2020-02-01 23:06:01 +01:00
void cmCTestSubmitCommand::CheckArguments(
std::vector<std::string> const& keywords)
2009-10-04 10:30:41 +03:00
{
2020-08-30 11:54:41 +02:00
this->PartsMentioned =
!this->Parts.empty() || cm::contains(keywords, "PARTS");
this->FilesMentioned =
!this->Files.empty() || cm::contains(keywords, "FILES");
2020-02-01 23:06:01 +01:00
2020-08-30 11:54:41 +02:00
cm::erase_if(this->Parts, [this](std::string const& arg) -> bool {
2009-10-04 10:30:41 +03:00
cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());
2020-02-01 23:06:01 +01:00
if (p == cmCTest::PartCount) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2009-10-04 10:30:41 +03:00
e << "Part name \"" << arg << "\" is invalid.";
2019-11-11 23:01:05 +01:00
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
2020-02-01 23:06:01 +01:00
return true;
2009-10-04 10:30:41 +03:00
}
2020-02-01 23:06:01 +01:00
return false;
});
2009-10-04 10:30:41 +03:00
2020-08-30 11:54:41 +02:00
cm::erase_if(this->Files, [this](std::string const& arg) -> bool {
2020-02-01 23:06:01 +01:00
if (!cmSystemTools::FileExists(arg)) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "File \"" << arg << "\" does not exist. Cannot submit "
<< "a non-existent file.";
2019-11-11 23:01:05 +01:00
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
2020-02-01 23:06:01 +01:00
return true;
2009-10-04 10:30:41 +03:00
}
2020-02-01 23:06:01 +01:00
return false;
});
2009-10-04 10:30:41 +03:00
}