cmake/Source/CTest/cmCTestSubmitHandler.cxx

1684 lines
61 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 "cmCTestSubmitHandler.h"
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cm_curl.h"
#include "cm_jsoncpp_reader.h"
#include "cm_jsoncpp_value.h"
#include "cmsys/Process.h"
2018-04-23 21:13:27 +02:00
#include <chrono>
2018-08-09 18:06:22 +02:00
#include <cstring>
2017-04-14 19:02:05 +02:00
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
2016-07-09 11:21:54 +02:00
#include "cmCTest.h"
2016-10-30 18:24:19 +01:00
#include "cmCTestCurl.h"
2015-04-27 22:25:09 +02:00
#include "cmCTestScriptHandler.h"
2018-01-26 17:06:56 +01:00
#include "cmCryptoHash.h"
2016-10-30 18:24:19 +01:00
#include "cmCurl.h"
2018-04-23 21:13:27 +02:00
#include "cmDuration.h"
2016-07-09 11:21:54 +02:00
#include "cmGeneratedFileStream.h"
2017-04-14 19:02:05 +02:00
#include "cmProcessOutput.h"
2016-07-09 11:21:54 +02:00
#include "cmState.h"
#include "cmSystemTools.h"
2017-04-14 19:02:05 +02:00
#include "cmThirdParty.h"
2017-07-20 19:35:53 +02:00
#include "cmWorkingDirectory.h"
2010-11-13 01:00:53 +02:00
#include "cmXMLParser.h"
2016-07-09 11:21:54 +02:00
#include "cmake.h"
2016-10-30 18:24:19 +01:00
#if defined(CTEST_USE_XMLRPC)
2018-08-09 18:06:22 +02:00
# include "cmVersion.h"
# include "cm_sys_stat.h"
# include "cm_xmlrpc.h"
2016-10-30 18:24:19 +01:00
#endif
2009-10-04 10:30:41 +03:00
#define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
2016-07-09 11:21:54 +02:00
class cmCTestSubmitHandler::ResponseParser : public cmXMLParser
2010-11-13 01:00:53 +02:00
{
public:
ResponseParser() { this->Status = STATUS_OK; }
2018-01-26 17:06:56 +01:00
~ResponseParser() override {}
2010-11-13 01:00:53 +02:00
public:
enum StatusType
2016-07-09 11:21:54 +02:00
{
2010-11-13 01:00:53 +02:00
STATUS_OK,
STATUS_WARNING,
STATUS_ERROR
2016-07-09 11:21:54 +02:00
};
2010-11-13 01:00:53 +02:00
StatusType Status;
std::string Filename;
std::string MD5;
std::string Message;
private:
std::vector<char> CurrentValue;
std::string GetCurrentValue()
2016-07-09 11:21:54 +02:00
{
2010-11-13 01:00:53 +02:00
std::string val;
2016-07-09 11:21:54 +02:00
if (!this->CurrentValue.empty()) {
2010-11-13 01:00:53 +02:00
val.assign(&this->CurrentValue[0], this->CurrentValue.size());
}
2016-07-09 11:21:54 +02:00
return val;
}
2010-11-13 01:00:53 +02:00
2017-04-14 19:02:05 +02:00
void StartElement(const std::string& /*name*/,
2018-01-26 17:06:56 +01:00
const char** /*atts*/) override
2016-07-09 11:21:54 +02:00
{
2010-11-13 01:00:53 +02:00
this->CurrentValue.clear();
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2018-01-26 17:06:56 +01:00
void CharacterDataHandler(const char* data, int length) override
2016-07-09 11:21:54 +02:00
{
this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
}
2010-11-13 01:00:53 +02:00
2018-01-26 17:06:56 +01:00
void EndElement(const std::string& name) override
2016-07-09 11:21:54 +02:00
{
if (name == "status") {
2010-11-13 01:00:53 +02:00
std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
2016-07-09 11:21:54 +02:00
if (status == "OK" || status == "SUCCESS") {
2010-11-13 01:00:53 +02:00
this->Status = STATUS_OK;
2016-07-09 11:21:54 +02:00
} else if (status == "WARNING") {
2010-11-13 01:00:53 +02:00
this->Status = STATUS_WARNING;
2016-07-09 11:21:54 +02:00
} else {
2010-11-13 01:00:53 +02:00
this->Status = STATUS_ERROR;
}
2016-07-09 11:21:54 +02:00
} else if (name == "filename") {
2010-11-13 01:00:53 +02:00
this->Filename = this->GetCurrentValue();
2016-07-09 11:21:54 +02:00
} else if (name == "md5") {
2010-11-13 01:00:53 +02:00
this->MD5 = this->GetCurrentValue();
2016-07-09 11:21:54 +02:00
} else if (name == "message") {
2010-11-13 01:00:53 +02:00
this->Message = this->GetCurrentValue();
}
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
};
2016-07-09 11:21:54 +02:00
static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size,
size_t nmemb, void* data)
{
2018-01-26 17:06:56 +01:00
int realsize = static_cast<int>(size * nmemb);
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerVectorOfChar* vec =
static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
const char* chPtr = static_cast<char*>(ptr);
vec->insert(vec->end(), chPtr, chPtr + realsize);
return realsize;
}
2016-10-30 18:24:19 +01:00
static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
curl_infotype /*unused*/,
2016-07-09 11:21:54 +02:00
char* chPtr, size_t size,
void* data)
{
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerVectorOfChar* vec =
static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
vec->insert(vec->end(), chPtr, chPtr + size);
return size;
}
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandler::cmCTestSubmitHandler()
: HTTPProxy()
, FTPProxy()
{
2009-10-04 10:30:41 +03:00
this->Initialize();
}
void cmCTestSubmitHandler::Initialize()
{
2009-10-04 10:30:41 +03:00
// We submit all available parts by default.
2016-07-09 11:21:54 +02:00
for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
p = cmCTest::Part(p + 1)) {
2009-10-04 10:30:41 +03:00
this->SubmitPart[p] = true;
2016-07-09 11:21:54 +02:00
}
this->CDash = false;
2010-03-17 14:00:29 +02:00
this->HasWarnings = false;
this->HasErrors = false;
this->Superclass::Initialize();
2018-01-26 17:06:56 +01:00
this->HTTPProxy.clear();
this->HTTPProxyType = 0;
2018-01-26 17:06:56 +01:00
this->HTTPProxyAuth.clear();
this->FTPProxy.clear();
this->FTPProxyType = 0;
2018-01-26 17:06:56 +01:00
this->LogFile = nullptr;
2009-10-04 10:30:41 +03:00
this->Files.clear();
}
2015-04-27 22:25:09 +02:00
bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix,
2016-07-09 11:21:54 +02:00
const std::set<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
2016-07-09 11:21:54 +02:00
CURL* curl;
CURLcode res;
FILE* ftpfile;
char error_buffer[1024];
/* In windows, this will init the winsock stuff */
::curl_global_init(CURL_GLOBAL_ALL);
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
/* get a curl handle */
curl = curl_easy_init();
2016-07-09 11:21:54 +02:00
if (curl) {
// Using proxy
2016-07-09 11:21:54 +02:00
if (this->FTPProxyType > 0) {
curl_easy_setopt(curl, CURLOPT_PROXY, this->FTPProxy.c_str());
2016-07-09 11:21:54 +02:00
switch (this->FTPProxyType) {
case 2:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
break;
case 3:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
break;
default:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
}
2016-07-09 11:21:54 +02:00
}
// enable uploading
2009-10-04 10:30:41 +03:00
::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
// if there is little to no activity for too long stop submitting
::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
2016-07-09 11:21:54 +02:00
SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
2009-10-04 10:30:41 +03:00
::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
2018-01-26 17:06:56 +01:00
std::string local_file = file;
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(local_file)) {
2018-01-26 17:06:56 +01:00
local_file = localprefix + "/" + file;
2016-07-09 11:21:54 +02:00
}
std::string upload_as =
2018-01-26 17:06:56 +01:00
url + "/" + remoteprefix + cmSystemTools::GetFilenameName(file);
2015-04-27 22:25:09 +02:00
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(local_file)) {
2016-07-09 11:21:54 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Cannot find file: " << local_file << std::endl);
::curl_easy_cleanup(curl);
::curl_global_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
unsigned long filelen = cmSystemTools::FileLength(local_file);
2015-04-27 22:25:09 +02:00
ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
2016-07-09 11:21:54 +02:00
*this->LogFile << "\tUpload file: " << local_file << " to " << upload_as
<< std::endl;
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Upload file: " << local_file << " to "
<< upload_as << std::endl,
this->Quiet);
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// specify target
2016-07-09 11:21:54 +02:00
::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
// now specify which file to upload
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
// and give the size of the upload (optional)
2016-07-09 11:21:54 +02:00
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
// and give curl the buffer for errors
::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
// specify handler for output
::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerWriteMemoryCallback);
::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerCurlDebugCallback);
/* we pass our 'chunk' struct to the callback function */
cmCTestSubmitHandlerVectorOfChar chunk;
cmCTestSubmitHandlerVectorOfChar chunkDebug;
2018-01-26 17:06:56 +01:00
::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
// Now run off and do what you've been told!
res = ::curl_easy_perform(curl);
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< "]" << std::endl,
this->Quiet);
}
if (!chunkDebug.empty()) {
cmCTestOptionalLog(
2018-08-09 18:06:22 +02:00
this->CTest, DEBUG,
"CURL debug output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
<< std::endl,
this->Quiet);
}
fclose(ftpfile);
2016-07-09 11:21:54 +02:00
if (res) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Error when uploading file: " << local_file
<< std::endl);
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Error message was: " << error_buffer << std::endl);
*this->LogFile << " Error when uploading file: " << local_file
<< std::endl
2016-07-09 11:21:54 +02:00
<< " Error message was: " << error_buffer << std::endl
<< " Curl output was: ";
// avoid dereference of empty vector
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
*this->LogFile << cmCTestLogWrite(&*chunk.begin(), chunk.size());
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< std::endl);
}
*this->LogFile << std::endl;
::curl_easy_cleanup(curl);
::curl_global_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
// always cleanup
::curl_easy_cleanup(curl);
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Uploaded: " + local_file << std::endl,
this->Quiet);
}
2016-07-09 11:21:54 +02:00
}
::curl_global_cleanup();
return true;
}
// Uploading files is simpler
2015-04-27 22:25:09 +02:00
bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
2016-07-09 11:21:54 +02:00
const std::set<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
2016-07-09 11:21:54 +02:00
CURL* curl;
CURLcode res;
FILE* ftpfile;
char error_buffer[1024];
2017-07-20 19:35:53 +02:00
// Set Content-Type to satisfy fussy modsecurity rules.
2016-07-09 11:21:54 +02:00
struct curl_slist* headers =
2018-01-26 17:06:56 +01:00
::curl_slist_append(nullptr, "Content-Type: text/xml");
2017-07-20 19:35:53 +02:00
// Add any additional headers that the user specified.
2018-01-26 17:06:56 +01:00
for (std::string const& h : this->HttpHeaders) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
2018-01-26 17:06:56 +01:00
" Add HTTP Header: \"" << h << "\"" << std::endl,
2017-07-20 19:35:53 +02:00
this->Quiet);
2018-01-26 17:06:56 +01:00
headers = ::curl_slist_append(headers, h.c_str());
2017-07-20 19:35:53 +02:00
}
/* In windows, this will init the winsock stuff */
::curl_global_init(CURL_GLOBAL_ALL);
2015-04-27 22:25:09 +02:00
std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
2009-10-04 10:30:41 +03:00
std::vector<std::string> args;
2015-04-27 22:25:09 +02:00
cmSystemTools::ExpandListArgument(curlopt, args);
2009-10-04 10:30:41 +03:00
bool verifyPeerOff = false;
bool verifyHostOff = false;
2018-01-26 17:06:56 +01:00
for (std::string const& arg : args) {
if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
2009-10-04 10:30:41 +03:00
verifyPeerOff = true;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
2009-10-04 10:30:41 +03:00
verifyHostOff = true;
}
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
/* get a curl handle */
curl = curl_easy_init();
2016-07-09 11:21:54 +02:00
if (curl) {
2015-04-27 22:25:09 +02:00
cmCurlSetCAInfo(curl);
2016-07-09 11:21:54 +02:00
if (verifyPeerOff) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Set CURLOPT_SSL_VERIFYPEER to off\n",
this->Quiet);
2009-10-04 10:30:41 +03:00
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
2016-07-09 11:21:54 +02:00
}
if (verifyHostOff) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Set CURLOPT_SSL_VERIFYHOST to off\n",
this->Quiet);
2009-10-04 10:30:41 +03:00
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
2016-07-09 11:21:54 +02:00
}
// Using proxy
2016-07-09 11:21:54 +02:00
if (this->HTTPProxyType > 0) {
curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
2016-07-09 11:21:54 +02:00
switch (this->HTTPProxyType) {
case 2:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
break;
case 3:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
break;
default:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if (!this->HTTPProxyAuth.empty()) {
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
this->HTTPProxyAuth.c_str());
}
}
2016-07-09 11:21:54 +02:00
}
if (this->CTest->ShouldUseHTTP10()) {
2010-03-17 14:00:29 +02:00
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
// enable HTTP ERROR parsing
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
/* enable uploading */
2009-10-04 10:30:41 +03:00
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
// if there is little to no activity for too long stop submitting
::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
2016-07-09 11:21:54 +02:00
SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
/* HTTP PUT please */
::curl_easy_setopt(curl, CURLOPT_PUT, 1);
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
2015-11-17 17:22:37 +01:00
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
2018-01-26 17:06:56 +01:00
std::string local_file = file;
2018-10-28 12:09:07 +01:00
bool initialize_cdash_buildid = false;
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(local_file)) {
2018-01-26 17:06:56 +01:00
local_file = localprefix + "/" + file;
2018-10-28 12:09:07 +01:00
// If this file exists within the local Testing directory we assume
// that it will be associated with the current build in CDash.
initialize_cdash_buildid = true;
2016-07-09 11:21:54 +02:00
}
std::string remote_file =
2018-01-26 17:06:56 +01:00
remoteprefix + cmSystemTools::GetFilenameName(file);
2015-04-27 22:25:09 +02:00
*this->LogFile << "\tUpload file: " << local_file << " to "
2016-07-09 11:21:54 +02:00
<< remote_file << std::endl;
2017-04-14 19:02:05 +02:00
std::string ofile;
2018-01-26 17:06:56 +01:00
for (char c : remote_file) {
char hexCh[4] = { 0, 0, 0, 0 };
hexCh[0] = c;
2016-07-09 11:21:54 +02:00
switch (c) {
case '+':
case '?':
case '/':
case '\\':
case '&':
case ' ':
case '=':
case '%':
2018-01-26 17:06:56 +01:00
sprintf(hexCh, "%%%02X", static_cast<int>(c));
2016-07-09 11:21:54 +02:00
ofile.append(hexCh);
break;
default:
ofile.append(hexCh);
}
2016-07-09 11:21:54 +02:00
}
std::string upload_as = url +
2018-08-09 18:06:22 +02:00
((url.find('?') == std::string::npos) ? '?' : '&') +
"FileName=" + ofile;
2018-10-28 12:09:07 +01:00
if (initialize_cdash_buildid) {
// Provide extra arguments to CDash so that it can initialize and
// return a buildid.
cmCTestCurl ctest_curl(this->CTest);
upload_as += "&build=";
upload_as +=
ctest_curl.Escape(this->CTest->GetCTestConfiguration("BuildName"));
upload_as += "&site=";
upload_as +=
ctest_curl.Escape(this->CTest->GetCTestConfiguration("Site"));
upload_as += "&stamp=";
upload_as += ctest_curl.Escape(this->CTest->GetCurrentTag());
upload_as += "-";
upload_as += ctest_curl.Escape(this->CTest->GetTestModelString());
cmCTestScriptHandler* ch = static_cast<cmCTestScriptHandler*>(
this->CTest->GetHandler("script"));
cmake* cm = ch->GetCMake();
if (cm) {
const char* subproject =
cm->GetState()->GetGlobalProperty("SubProject");
if (subproject) {
upload_as += "&subproject=";
upload_as += ctest_curl.Escape(subproject);
}
}
}
2010-11-13 01:00:53 +02:00
upload_as += "&MD5=";
2016-07-09 11:21:54 +02:00
if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) {
2010-11-13 01:00:53 +02:00
upload_as += "bad_md5sum";
2016-07-09 11:21:54 +02:00
} else {
2018-01-26 17:06:56 +01:00
upload_as +=
cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(local_file)) {
2016-07-09 11:21:54 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Cannot find file: " << local_file << std::endl);
::curl_easy_cleanup(curl);
2015-11-17 17:22:37 +01:00
::curl_slist_free_all(headers);
::curl_global_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
unsigned long filelen = cmSystemTools::FileLength(local_file);
2015-04-27 22:25:09 +02:00
ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Upload file: " << local_file << " to "
<< upload_as << " Size: "
<< filelen << std::endl,
this->Quiet);
// specify target
2016-07-09 11:21:54 +02:00
::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
2018-10-28 12:09:07 +01:00
// CURLAUTH_BASIC is default, and here we allow additional methods,
// including more secure ones
::curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// now specify which file to upload
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
// and give the size of the upload (optional)
2016-07-09 11:21:54 +02:00
::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
// and give curl the buffer for errors
::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
// specify handler for output
::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerWriteMemoryCallback);
::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerCurlDebugCallback);
/* we pass our 'chunk' struct to the callback function */
cmCTestSubmitHandlerVectorOfChar chunk;
cmCTestSubmitHandlerVectorOfChar chunkDebug;
2018-01-26 17:06:56 +01:00
::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
// Now run off and do what you've been told!
res = ::curl_easy_perform(curl);
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< "]" << std::endl,
this->Quiet);
2010-03-17 14:00:29 +02:00
this->ParseResponse(chunk);
2016-07-09 11:21:54 +02:00
}
if (!chunkDebug.empty()) {
cmCTestOptionalLog(
2018-08-09 18:06:22 +02:00
this->CTest, DEBUG,
"CURL debug output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
<< std::endl,
this->Quiet);
}
2010-11-13 01:00:53 +02:00
// If curl failed for any reason, or checksum fails, wait and retry
//
2016-07-09 11:21:54 +02:00
if (res != CURLE_OK || this->HasErrors) {
2018-01-26 17:06:56 +01:00
std::string retryDelay = this->GetOption("RetryDelay") == nullptr
2016-07-09 11:21:54 +02:00
? ""
: this->GetOption("RetryDelay");
2018-01-26 17:06:56 +01:00
std::string retryCount = this->GetOption("RetryCount") == nullptr
2016-07-09 11:21:54 +02:00
? ""
: this->GetOption("RetryCount");
2018-04-23 21:13:27 +02:00
auto delay = cmDuration(
retryDelay.empty()
? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
.c_str())
: atoi(retryDelay.c_str()));
2018-01-26 17:06:56 +01:00
int count = retryCount.empty()
2016-07-09 11:21:54 +02:00
? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
.c_str())
: atoi(retryCount.c_str());
for (int i = 0; i < count; i++) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2018-04-23 21:13:27 +02:00
" Submit failed, waiting " << delay.count()
2016-07-09 11:21:54 +02:00
<< " seconds...\n",
this->Quiet);
2010-11-13 01:00:53 +02:00
2018-04-23 21:13:27 +02:00
auto stop = std::chrono::steady_clock::now() + delay;
while (std::chrono::steady_clock::now() < stop) {
2010-11-13 01:00:53 +02:00
cmSystemTools::Delay(100);
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Retry submission: Attempt "
<< (i + 1) << " of " << count << std::endl,
this->Quiet);
2010-11-13 01:00:53 +02:00
::fclose(ftpfile);
2015-04-27 22:25:09 +02:00
ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
2010-11-13 01:00:53 +02:00
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
chunk.clear();
chunkDebug.clear();
this->HasErrors = false;
res = ::curl_easy_perform(curl);
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
cmCTestOptionalLog(
2018-08-09 18:06:22 +02:00
this->CTest, DEBUG,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< std::endl,
this->Quiet);
2010-11-13 01:00:53 +02:00
this->ParseResponse(chunk);
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2016-07-09 11:21:54 +02:00
if (res == CURLE_OK && !this->HasErrors) {
2010-11-13 01:00:53 +02:00
break;
}
}
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
fclose(ftpfile);
2016-07-09 11:21:54 +02:00
if (res) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Error when uploading file: " << local_file
<< std::endl);
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Error message was: " << error_buffer << std::endl);
*this->LogFile << " Error when uploading file: " << local_file
<< std::endl
2011-06-19 15:41:06 +03:00
<< " Error message was: " << error_buffer
<< std::endl;
// avoid deref of begin for zero size array
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
*this->LogFile << " Curl output was: "
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< std::endl;
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< std::endl);
}
::curl_easy_cleanup(curl);
2015-11-17 17:22:37 +01:00
::curl_slist_free_all(headers);
::curl_global_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
// always cleanup
::curl_easy_cleanup(curl);
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Uploaded: " + local_file << std::endl,
this->Quiet);
}
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
::curl_slist_free_all(headers);
::curl_global_cleanup();
return true;
}
2016-07-09 11:21:54 +02:00
void cmCTestSubmitHandler::ParseResponse(
cmCTestSubmitHandlerVectorOfChar chunk)
2010-03-17 14:00:29 +02:00
{
2017-04-14 19:02:05 +02:00
std::string output;
2010-11-13 01:00:53 +02:00
output.append(chunk.begin(), chunk.end());
2010-03-17 14:00:29 +02:00
2017-07-20 19:35:53 +02:00
if (output.find("<cdash") != std::string::npos) {
2010-11-13 01:00:53 +02:00
ResponseParser parser;
parser.Parse(output.c_str());
2016-07-09 11:21:54 +02:00
if (parser.Status != ResponseParser::STATUS_OK) {
2010-11-13 01:00:53 +02:00
this->HasErrors = true;
2016-07-09 11:21:54 +02:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
" Submission failed: " << parser.Message << std::endl);
2010-11-13 01:00:53 +02:00
return;
2010-03-17 14:00:29 +02:00
}
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
output = cmSystemTools::UpperCase(output);
2016-07-09 11:21:54 +02:00
if (output.find("WARNING") != std::string::npos) {
2010-03-17 14:00:29 +02:00
this->HasWarnings = true;
2016-07-09 11:21:54 +02:00
}
if (output.find("ERROR") != std::string::npos) {
2010-03-17 14:00:29 +02:00
this->HasErrors = true;
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2016-07-09 11:21:54 +02:00
if (this->HasWarnings || this->HasErrors) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
" Server Response:\n"
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
}
2010-03-17 14:00:29 +02:00
}
2016-07-09 11:21:54 +02:00
bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
2016-07-09 11:21:54 +02:00
CURL* curl;
char error_buffer[1024];
2015-08-17 11:37:30 +02:00
/* In windows, this will init the winsock stuff */
::curl_global_init(CURL_GLOBAL_ALL);
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
/* get a curl handle */
curl = curl_easy_init();
2016-07-09 11:21:54 +02:00
if (curl) {
// Using proxy
2016-07-09 11:21:54 +02:00
if (this->HTTPProxyType > 0) {
curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
2016-07-09 11:21:54 +02:00
switch (this->HTTPProxyType) {
case 2:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
break;
case 3:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
break;
default:
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if (!this->HTTPProxyAuth.empty()) {
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
this->HTTPProxyAuth.c_str());
}
}
2016-07-09 11:21:54 +02:00
}
::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
// and give curl the buffer for errors
::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
// specify handler for output
::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerWriteMemoryCallback);
::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
2016-07-09 11:21:54 +02:00
cmCTestSubmitHandlerCurlDebugCallback);
/* we pass our 'chunk' struct to the callback function */
cmCTestSubmitHandlerVectorOfChar chunk;
cmCTestSubmitHandlerVectorOfChar chunkDebug;
2018-01-26 17:06:56 +01:00
::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
2018-01-26 17:06:56 +01:00
std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(file);
2017-04-14 19:02:05 +02:00
std::string ofile;
2018-01-26 17:06:56 +01:00
for (char c : rfile) {
char hexCh[4] = { 0, 0, 0, 0 };
hexCh[0] = c;
2016-07-09 11:21:54 +02:00
switch (c) {
case '+':
case '?':
case '/':
case '\\':
case '&':
case ' ':
case '=':
case '%':
2018-01-26 17:06:56 +01:00
sprintf(hexCh, "%%%02X", static_cast<int>(c));
2016-07-09 11:21:54 +02:00
ofile.append(hexCh);
break;
default:
ofile.append(hexCh);
}
2016-07-09 11:21:54 +02:00
}
std::string turl = url +
2018-08-09 18:06:22 +02:00
((url.find('?') == std::string::npos) ? '?' : '&') +
"xmlfile=" + ofile;
2015-04-27 22:25:09 +02:00
*this->LogFile << "Trigger url: " << turl << std::endl;
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Trigger url: " << turl << std::endl, this->Quiet);
2009-10-04 10:30:41 +03:00
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
2016-07-09 11:21:54 +02:00
if (curl_easy_perform(curl)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Error when triggering: " << turl << std::endl);
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Error message was: " << error_buffer << std::endl);
2010-11-13 01:00:53 +02:00
*this->LogFile << "\tTriggering failed with error: " << error_buffer
<< std::endl
2011-06-19 15:41:06 +03:00
<< " Error message was: " << error_buffer
<< std::endl;
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
*this->LogFile << " Curl output was: "
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< std::endl;
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
<< std::endl);
}
::curl_easy_cleanup(curl);
::curl_global_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (!chunk.empty()) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"CURL output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunk.begin(), chunk.size())
<< "]" << std::endl,
this->Quiet);
}
if (!chunkDebug.empty()) {
cmCTestOptionalLog(
2018-08-09 18:06:22 +02:00
this->CTest, DEBUG,
"CURL debug output: ["
2016-07-09 11:21:54 +02:00
<< cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
<< std::endl,
this->Quiet);
}
// always cleanup
::curl_easy_cleanup(curl);
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
}
2016-07-09 11:21:54 +02:00
}
::curl_global_cleanup();
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Dart server triggered..." << std::endl, this->Quiet);
return true;
}
2016-07-09 11:21:54 +02:00
bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command,
const std::string& localprefix,
const std::set<std::string>& files,
const std::string& remoteprefix,
const std::string& url)
{
2016-07-09 11:21:54 +02:00
if (scp_command.empty() || localprefix.empty() || files.empty() ||
remoteprefix.empty() || url.empty()) {
2017-04-14 19:02:05 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
std::vector<const char*> argv;
argv.push_back(scp_command.c_str()); // Scp command
argv.push_back(scp_command.c_str()); // Dummy string for file
argv.push_back(scp_command.c_str()); // Dummy string for remote url
2018-01-26 17:06:56 +01:00
argv.push_back(nullptr);
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
2016-07-09 11:21:54 +02:00
// cmsysProcess_SetTimeout(cp, timeout);
int problems = 0;
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
int retVal;
std::string lfname = localprefix;
cmSystemTools::ConvertToUnixSlashes(lfname);
2018-01-26 17:06:56 +01:00
lfname += "/" + file;
2018-04-23 21:13:27 +02:00
lfname = cmSystemTools::ConvertToOutputPath(lfname);
argv[1] = lfname.c_str();
2018-01-26 17:06:56 +01:00
std::string rfname = url + "/" + remoteprefix + file;
argv[2] = rfname.c_str();
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
<< argv[2] << "\"" << std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
*this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
2016-07-09 11:21:54 +02:00
<< argv[2] << "\"" << std::endl;
cmsysProcess_SetCommand(cp, &*argv.begin());
cmsysProcess_Execute(cp);
char* data;
int length;
2017-04-14 19:02:05 +02:00
cmProcessOutput processOutput;
std::string strdata;
2018-01-26 17:06:56 +01:00
while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
2017-04-14 19:02:05 +02:00
processOutput.DecodeText(data, length, strdata);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
cmCTestLogWrite(strdata.c_str(), strdata.size()),
this->Quiet);
}
processOutput.DecodeText(std::string(), strdata);
if (!strdata.empty()) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2017-04-14 19:02:05 +02:00
cmCTestLogWrite(strdata.c_str(), strdata.size()),
this->Quiet);
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
cmsysProcess_WaitForExit(cp, nullptr);
int result = cmsysProcess_GetState(cp);
2016-07-09 11:21:54 +02:00
if (result == cmsysProcess_State_Exited) {
retVal = cmsysProcess_GetExitValue(cp);
2016-07-09 11:21:54 +02:00
if (retVal != 0) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"\tSCP returned: " << retVal << std::endl,
this->Quiet);
*this->LogFile << "\tSCP returned: " << retVal << std::endl;
2016-07-09 11:21:54 +02:00
problems++;
}
2016-07-09 11:21:54 +02:00
} else if (result == cmsysProcess_State_Exception) {
retVal = cmsysProcess_GetExitException(cp);
2016-07-09 11:21:54 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"\tThere was an exception: " << retVal << std::endl);
*this->LogFile << "\tThere was an exception: " << retVal << std::endl;
2016-07-09 11:21:54 +02:00
problems++;
} else if (result == cmsysProcess_State_Expired) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"\tThere was a timeout" << std::endl);
*this->LogFile << "\tThere was a timeout" << std::endl;
2016-07-09 11:21:54 +02:00
problems++;
} else if (result == cmsysProcess_State_Error) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"\tError executing SCP: " << cmsysProcess_GetErrorString(cp)
<< std::endl);
*this->LogFile << "\tError executing SCP: "
2016-07-09 11:21:54 +02:00
<< cmsysProcess_GetErrorString(cp) << std::endl;
problems++;
}
2016-07-09 11:21:54 +02:00
}
cmsysProcess_Delete(cp);
2016-10-30 18:24:19 +01:00
return problems == 0;
}
2016-07-09 11:21:54 +02:00
bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
const std::set<std::string>& files,
const std::string& remoteprefix,
const std::string& destination)
2009-10-04 10:30:41 +03:00
{
2016-07-09 11:21:54 +02:00
if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
destination.empty()) {
/* clang-format off */
2011-06-19 15:41:06 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2009-10-04 10:30:41 +03:00
"Missing arguments for submit via cp:\n"
<< "\tlocalprefix: " << localprefix << "\n"
<< "\tNumber of files: " << files.size() << "\n"
<< "\tremoteprefix: " << remoteprefix << "\n"
<< "\tdestination: " << destination << std::endl);
2016-07-09 11:21:54 +02:00
/* clang-format on */
2017-04-14 19:02:05 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
2009-10-04 10:30:41 +03:00
std::string lfname = localprefix;
cmSystemTools::ConvertToUnixSlashes(lfname);
2018-01-26 17:06:56 +01:00
lfname += "/" + file;
std::string rfname = destination + "/" + remoteprefix + file;
2015-04-27 22:25:09 +02:00
cmSystemTools::CopyFileAlways(lfname, rfname);
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
" Copy file: " << lfname << " to " << rfname
<< std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
}
2009-10-04 10:30:41 +03:00
std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
2015-04-27 22:25:09 +02:00
cmSystemTools::Touch(tagDoneFile, true);
2009-10-04 10:30:41 +03:00
return true;
}
#if defined(CTEST_USE_XMLRPC)
2016-07-09 11:21:54 +02:00
bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
const std::string& localprefix, const std::set<std::string>& files,
const std::string& remoteprefix, const std::string& url)
{
xmlrpc_env env;
char ctestString[] = "CTest";
std::string ctestVersionString = cmVersion::GetCMakeVersion();
char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
2015-04-27 22:25:09 +02:00
std::string realURL = url + "/" + remoteprefix + "/Command/";
/* Start up our XML-RPC client library. */
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
/* Initialize our error-handling environment. */
xmlrpc_env_init(&env);
/* Call the famous server at UserLand. */
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Submitting to: " << realURL << " (" << remoteprefix
<< ")" << std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
2016-07-09 11:21:54 +02:00
xmlrpc_value* result;
2018-01-26 17:06:56 +01:00
std::string local_file = file;
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(local_file)) {
2018-01-26 17:06:56 +01:00
local_file = localprefix + "/" + file;
2016-07-09 11:21:54 +02:00
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-10-30 18:24:19 +01:00
" Submit file: " << local_file << std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
struct stat st;
2016-07-09 11:21:54 +02:00
if (::stat(local_file.c_str(), &st)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-10-30 18:24:19 +01:00
" Cannot find file: " << local_file << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
// off_t can be bigger than size_t. fread takes size_t.
// make sure the file is not too big.
2016-07-09 11:21:54 +02:00
if (static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
static_cast<off_t>(st.st_size)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" File too big: " << local_file << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
size_t fileSize = static_cast<size_t>(st.st_size);
2017-04-14 19:02:05 +02:00
FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
2016-07-09 11:21:54 +02:00
if (!fp) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-10-30 18:24:19 +01:00
" Cannot open file: " << local_file << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
unsigned char* fileBuffer = new unsigned char[fileSize];
if (fread(fileBuffer, 1, fileSize, fp) != fileSize) {
delete[] fileBuffer;
fclose(fp);
2016-07-09 11:21:54 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-10-30 18:24:19 +01:00
" Cannot read file: " << local_file << std::endl);
return false;
2016-07-09 11:21:54 +02:00
}
fclose(fp);
char remoteCommand[] = "Submit.put";
char* pRealURL = const_cast<char*>(realURL.c_str());
2018-01-26 17:06:56 +01:00
result =
xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer,
static_cast<xmlrpc_int32>(fileSize));
2016-07-09 11:21:54 +02:00
delete[] fileBuffer;
2016-07-09 11:21:54 +02:00
if (env.fault_occurred) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Submission problem: " << env.fault_string << " ("
<< env.fault_code << ")"
<< std::endl);
xmlrpc_env_clean(&env);
xmlrpc_client_cleanup();
return false;
2016-07-09 11:21:54 +02:00
}
/* Dispose of our result value. */
xmlrpc_DECREF(result);
2016-07-09 11:21:54 +02:00
}
/* Clean up our error-handling environment. */
xmlrpc_env_clean(&env);
/* Shutdown our XML-RPC client library. */
xmlrpc_client_cleanup();
return true;
}
2009-10-04 10:30:41 +03:00
#else
2016-10-30 18:24:19 +01:00
bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
std::string const& /*unused*/, std::set<std::string> const& /*unused*/,
std::string const& /*unused*/, std::string const& /*unused*/)
2009-10-04 10:30:41 +03:00
{
return false;
}
#endif
2015-04-27 22:25:09 +02:00
void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
std::string& url)
{
dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
url = dropMethod;
url += "://";
2016-10-30 18:24:19 +01:00
if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
2015-04-27 22:25:09 +02:00
url += this->CTest->GetCTestConfiguration("DropSiteUser");
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(
this->CTest, HANDLER_OUTPUT,
this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
2016-10-30 18:24:19 +01:00
if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
2015-04-27 22:25:09 +02:00
url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
url += "@";
}
2015-04-27 22:25:09 +02:00
url += this->CTest->GetCTestConfiguration("DropSite") +
this->CTest->GetCTestConfiguration("DropLocation");
}
int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
std::string const& typeString)
{
2016-07-09 11:21:54 +02:00
if (file.empty()) {
cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not specified\n");
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
if (!cmSystemTools::FileExists(file)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Upload file not found: '" << file << "'\n");
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
cmCTestCurl curl(this->CTest);
2017-04-14 19:02:05 +02:00
curl.SetQuiet(this->Quiet);
2015-04-27 22:25:09 +02:00
std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
std::vector<std::string> args;
cmSystemTools::ExpandListArgument(curlopt, args);
curl.SetCurlOptions(args);
curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
2017-07-20 19:35:53 +02:00
curl.SetHttpHeaders(this->HttpHeaders);
2015-04-27 22:25:09 +02:00
std::string dropMethod;
std::string url;
this->ConstructCDashURL(dropMethod, url);
std::string::size_type pos = url.find("submit.php?");
2016-07-09 11:21:54 +02:00
url = url.substr(0, pos + 10);
if (!(dropMethod == "http" || dropMethod == "https")) {
2015-04-27 22:25:09 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Only http and https are supported for CDASH_UPLOAD\n");
return -1;
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
// Get RETRY_COUNT and RETRY_DELAY values if they were set.
2018-01-26 17:06:56 +01:00
std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
2017-04-14 19:02:05 +02:00
? ""
: this->GetOption("RetryDelay");
2018-01-26 17:06:56 +01:00
std::string retryCountString = this->GetOption("RetryCount") == nullptr
2017-04-14 19:02:05 +02:00
? ""
: this->GetOption("RetryCount");
2018-04-23 21:13:27 +02:00
auto retryDelay = std::chrono::seconds(0);
2018-01-26 17:06:56 +01:00
if (!retryDelayString.empty()) {
2018-04-23 21:13:27 +02:00
unsigned long retryDelayValue = 0;
if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
&retryDelayValue)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'RETRY_DELAY' : " << retryDelayString
<< std::endl);
2018-04-23 21:13:27 +02:00
} else {
retryDelay = std::chrono::seconds(retryDelayValue);
2017-04-14 19:02:05 +02:00
}
}
unsigned long retryCount = 0;
2018-01-26 17:06:56 +01:00
if (!retryCountString.empty()) {
2017-04-14 19:02:05 +02:00
if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'RETRY_DELAY' : " << retryCountString
<< std::endl);
2017-04-14 19:02:05 +02:00
}
}
2018-01-26 17:06:56 +01:00
std::string md5sum =
cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
2015-04-27 22:25:09 +02:00
// 1. request the buildid and check to see if the file
// has already been uploaded
// TODO I added support for subproject. You would need to add
// a "&subproject=subprojectname" to the first POST.
cmCTestScriptHandler* ch =
static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
2016-07-09 11:21:54 +02:00
cmake* cm = ch->GetCMake();
2015-08-17 11:37:30 +02:00
const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
2015-04-27 22:25:09 +02:00
// TODO: Encode values for a URL instead of trusting caller.
std::ostringstream str;
str << "project="
<< curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
2016-07-09 11:21:54 +02:00
if (subproject) {
2015-04-27 22:25:09 +02:00
str << "subproject=" << curl.Escape(subproject) << "&";
2016-07-09 11:21:54 +02:00
}
2018-04-23 21:13:27 +02:00
auto timeNow =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
2015-04-27 22:25:09 +02:00
str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
<< curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "build="
<< curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
2016-07-09 11:21:54 +02:00
<< "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
<< "&"
<< "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
2018-04-23 21:13:27 +02:00
<< "starttime=" << timeNow << "&"
<< "endtime=" << timeNow << "&"
2015-04-27 22:25:09 +02:00
<< "datafilesmd5[0]=" << md5sum << "&"
<< "type=" << curl.Escape(typeString);
std::string fields = str.str();
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"fields: " << fields << "\nurl:" << url
<< "\nfile: " << file << "\n",
this->Quiet);
2015-04-27 22:25:09 +02:00
std::string response;
2017-04-14 19:02:05 +02:00
bool requestSucceeded = curl.HttpRequest(url, fields, response);
if (!internalTest && !requestSucceeded) {
// If request failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2018-04-23 21:13:27 +02:00
" Request failed, waiting " << retryDelay.count()
2017-04-14 19:02:05 +02:00
<< " seconds...\n",
this->Quiet);
2018-04-23 21:13:27 +02:00
auto stop = std::chrono::steady_clock::now() + retryDelay;
while (std::chrono::steady_clock::now() < stop) {
2017-04-14 19:02:05 +02:00
cmSystemTools::Delay(100);
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Retry request: Attempt "
<< (i + 1) << " of " << retryCount << std::endl,
this->Quiet);
requestSucceeded = curl.HttpRequest(url, fields, response);
if (requestSucceeded) {
break;
}
}
}
if (!internalTest && !requestSucceeded) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error in HttpRequest\n"
2016-07-09 11:21:54 +02:00
<< response);
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"Request upload response: [" << response << "]\n",
this->Quiet);
2015-04-27 22:25:09 +02:00
Json::Value json;
Json::Reader reader;
2017-04-14 19:02:05 +02:00
if (!internalTest && !reader.parse(response, json)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"error parsing json string ["
2016-07-09 11:21:54 +02:00
<< response << "]\n"
<< reader.getFormattedErrorMessages() << "\n");
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
if (!internalTest && json["status"].asInt() != 0) {
2015-04-27 22:25:09 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Bad status returned from CDash: " << json["status"].asInt());
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
if (!internalTest) {
if (json["datafilesmd5"].isArray()) {
int datares = json["datafilesmd5"][0].asInt();
if (datares == 1) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"File already exists on CDash, skip upload "
<< file << "\n",
this->Quiet);
return 0;
}
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"bad datafilesmd5 value in response " << response << "\n");
return -1;
2015-04-27 22:25:09 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
std::string upload_as = cmSystemTools::GetFilenameName(file);
std::ostringstream fstr;
fstr << "type=" << curl.Escape(typeString) << "&"
<< "md5=" << md5sum << "&"
<< "filename=" << curl.Escape(upload_as) << "&"
<< "buildid=" << json["buildid"].asString();
2017-04-14 19:02:05 +02:00
bool uploadSucceeded = false;
if (!internalTest) {
uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
}
if (!uploadSucceeded) {
// If upload failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2018-04-23 21:13:27 +02:00
" Upload failed, waiting " << retryDelay.count()
2017-04-14 19:02:05 +02:00
<< " seconds...\n",
this->Quiet);
2018-04-23 21:13:27 +02:00
auto stop = std::chrono::steady_clock::now() + retryDelay;
while (std::chrono::steady_clock::now() < stop) {
2017-04-14 19:02:05 +02:00
cmSystemTools::Delay(100);
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Retry upload: Attempt "
<< (i + 1) << " of " << retryCount << std::endl,
this->Quiet);
if (!internalTest) {
uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
}
if (uploadSucceeded) {
break;
}
}
}
if (!uploadSucceeded) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"error uploading to CDash. " << file << " " << url << " "
<< fstr.str());
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
if (!reader.parse(response, json)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"error parsing json string ["
2016-07-09 11:21:54 +02:00
<< response << "]\n"
<< reader.getFormattedErrorMessages() << "\n");
2015-04-27 22:25:09 +02:00
return -1;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"Upload file response: [" << response << "]\n",
this->Quiet);
2015-04-27 22:25:09 +02:00
return 0;
}
int cmCTestSubmitHandler::ProcessHandler()
{
2015-04-27 22:25:09 +02:00
const char* cdashUploadFile = this->GetOption("CDashUploadFile");
const char* cdashUploadType = this->GetOption("CDashUploadType");
2016-07-09 11:21:54 +02:00
if (cdashUploadFile && cdashUploadType) {
2015-04-27 22:25:09 +02:00
return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
2016-07-09 11:21:54 +02:00
}
std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
// cdash does not need to trigger so just return true
2016-07-09 11:21:54 +02:00
if (!iscdash.empty()) {
this->CDash = true;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
const std::string& buildDirectory =
this->CTest->GetCTestConfiguration("BuildDirectory");
if (buildDirectory.empty()) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Cannot find BuildDirectory key in the DartConfiguration.tcl"
<< std::endl);
return -1;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (getenv("HTTP_PROXY")) {
this->HTTPProxyType = 1;
this->HTTPProxy = getenv("HTTP_PROXY");
2016-07-09 11:21:54 +02:00
if (getenv("HTTP_PROXY_PORT")) {
this->HTTPProxy += ":";
this->HTTPProxy += getenv("HTTP_PROXY_PORT");
2016-07-09 11:21:54 +02:00
}
if (getenv("HTTP_PROXY_TYPE")) {
2015-04-27 22:25:09 +02:00
std::string type = getenv("HTTP_PROXY_TYPE");
// HTTP/SOCKS4/SOCKS5
2016-07-09 11:21:54 +02:00
if (type == "HTTP") {
this->HTTPProxyType = 1;
2016-07-09 11:21:54 +02:00
} else if (type == "SOCKS4") {
this->HTTPProxyType = 2;
2016-07-09 11:21:54 +02:00
} else if (type == "SOCKS5") {
this->HTTPProxyType = 3;
}
2016-07-09 11:21:54 +02:00
}
if (getenv("HTTP_PROXY_USER")) {
this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
2016-07-09 11:21:54 +02:00
}
if (getenv("HTTP_PROXY_PASSWD")) {
this->HTTPProxyAuth += ":";
this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
}
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (getenv("FTP_PROXY")) {
this->FTPProxyType = 1;
this->FTPProxy = getenv("FTP_PROXY");
2016-07-09 11:21:54 +02:00
if (getenv("FTP_PROXY_PORT")) {
this->FTPProxy += ":";
this->FTPProxy += getenv("FTP_PROXY_PORT");
2016-07-09 11:21:54 +02:00
}
if (getenv("FTP_PROXY_TYPE")) {
2015-04-27 22:25:09 +02:00
std::string type = getenv("FTP_PROXY_TYPE");
// HTTP/SOCKS4/SOCKS5
2016-07-09 11:21:54 +02:00
if (type == "HTTP") {
this->FTPProxyType = 1;
2016-07-09 11:21:54 +02:00
} else if (type == "SOCKS4") {
this->FTPProxyType = 2;
2016-07-09 11:21:54 +02:00
} else if (type == "SOCKS5") {
this->FTPProxyType = 3;
}
}
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (!this->HTTPProxy.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Use HTTP Proxy: " << this->HTTPProxy << std::endl,
this->Quiet);
}
if (!this->FTPProxy.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Use FTP Proxy: " << this->FTPProxy << std::endl,
this->Quiet);
}
cmGeneratedFileStream ofs;
this->StartLogFile("Submit", ofs);
cmCTest::SetOfStrings files;
std::string prefix = this->GetSubmitResultsPrefix();
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
if (!this->Files.empty()) {
2009-10-04 10:30:41 +03:00
// Submit the explicitly selected files:
//
2015-04-27 22:25:09 +02:00
files.insert(this->Files.begin(), this->Files.end());
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// Add to the list of files to submit from any selected, existing parts:
//
// TODO:
// Check if test is enabled
2009-10-04 10:30:41 +03:00
this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
2016-07-09 11:21:54 +02:00
if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
2015-04-27 22:25:09 +02:00
std::vector<std::string> gfiles;
2016-07-09 11:21:54 +02:00
std::string gpath =
buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
std::string::size_type glen = gpath.size() + 1;
gpath = gpath + "/CoverageLog*";
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"Globbing for: " << gpath << std::endl, this->Quiet);
if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
2018-01-26 17:06:56 +01:00
for (std::string& gfile : gfiles) {
gfile = gfile.substr(glen);
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
2018-01-26 17:06:56 +01:00
"Glob file: " << gfile << std::endl, this->Quiet);
this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
}
2016-07-09 11:21:54 +02:00
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
}
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
2011-06-19 15:41:06 +03:00
this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
2009-10-04 10:30:41 +03:00
// Query parts for files to submit.
2016-07-09 11:21:54 +02:00
for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
p = cmCTest::Part(p + 1)) {
2009-10-04 10:30:41 +03:00
// Skip parts we are not submitting.
2016-07-09 11:21:54 +02:00
if (!this->SubmitPart[p]) {
2009-10-04 10:30:41 +03:00
continue;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// Submit files from this part.
std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
2015-04-27 22:25:09 +02:00
files.insert(pfiles.begin(), pfiles.end());
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (ofs) {
ofs << "Upload files:" << std::endl;
int cnt = 0;
2018-01-26 17:06:56 +01:00
for (std::string const& file : files) {
ofs << cnt << "\t" << file << std::endl;
2016-07-09 11:21:54 +02:00
cnt++;
}
2016-07-09 11:21:54 +02:00
}
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"Submit files (using "
2016-07-09 11:21:54 +02:00
<< this->CTest->GetCTestConfiguration("DropMethod")
<< ")" << std::endl,
this->Quiet);
const char* specificTrack = this->CTest->GetSpecificTrack();
2016-07-09 11:21:54 +02:00
if (specificTrack) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Send to track: " << specificTrack << std::endl,
this->Quiet);
}
this->SetLogFile(&ofs);
2009-10-04 10:30:41 +03:00
2015-04-27 22:25:09 +02:00
std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
if (dropMethod.empty() || dropMethod == "ftp") {
ofs << "Using drop method: FTP" << std::endl;
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Using FTP submit method" << std::endl
<< " Drop site: ftp://",
this->Quiet);
std::string url = "ftp://";
url += cmCTest::MakeURLSafe(
2016-07-09 11:21:54 +02:00
this->CTest->GetCTestConfiguration("DropSiteUser")) +
2018-08-09 18:06:22 +02:00
":" +
cmCTest::MakeURLSafe(
this->CTest->GetCTestConfiguration("DropSitePassword")) +
2016-07-09 11:21:54 +02:00
"@" + this->CTest->GetCTestConfiguration("DropSite") +
cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
cmCTestOptionalLog(
this->CTest, HANDLER_OUTPUT,
this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
this->Quiet);
if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
2016-07-09 11:21:54 +02:00
this->Quiet);
}
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
this->CTest->GetCTestConfiguration("DropSite")
<< this->CTest->GetCTestConfiguration("DropLocation")
<< std::endl,
this->Quiet);
if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
this->CTest->GetCurrentTag(),
files, prefix, url)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Problems when submitting via FTP" << std::endl);
ofs << " Problems when submitting via FTP" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
if (!this->CDash) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Using HTTP trigger method"
<< std::endl
<< " Trigger site: "
<< this->CTest->GetCTestConfiguration("TriggerSite")
<< std::endl,
this->Quiet);
2016-07-09 11:21:54 +02:00
if (!this->TriggerUsingHTTP(
files, prefix,
this->CTest->GetCTestConfiguration("TriggerSite"))) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Problems when triggering via HTTP" << std::endl);
ofs << " Problems when triggering via HTTP" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Submission successful" << std::endl, this->Quiet);
ofs << " Submission successful" << std::endl;
return 0;
}
2016-07-09 11:21:54 +02:00
} else if (dropMethod == "http" || dropMethod == "https") {
2009-10-04 10:30:41 +03:00
std::string url = dropMethod;
url += "://";
ofs << "Using drop method: " << dropMethod << std::endl;
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Using HTTP submit method" << std::endl
<< " Drop site:" << url,
this->Quiet);
if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
url += this->CTest->GetCTestConfiguration("DropSiteUser");
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(
this->CTest, HANDLER_OUTPUT,
2015-08-17 11:37:30 +02:00
this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
this->Quiet);
2016-07-09 11:21:54 +02:00
if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
2016-07-09 11:21:54 +02:00
this->Quiet);
}
url += "@";
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
2016-07-09 11:21:54 +02:00
}
url += this->CTest->GetCTestConfiguration("DropSite") +
this->CTest->GetCTestConfiguration("DropLocation");
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
this->CTest->GetCTestConfiguration("DropSite")
<< this->CTest->GetCTestConfiguration("DropLocation")
<< std::endl,
this->Quiet);
if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
this->CTest->GetCurrentTag(),
files, prefix, url)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Problems when submitting via HTTP" << std::endl);
ofs << " Problems when submitting via HTTP" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
if (!this->CDash) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Using HTTP trigger method"
<< std::endl
<< " Trigger site: "
<< this->CTest->GetCTestConfiguration("TriggerSite")
<< std::endl,
this->Quiet);
2016-07-09 11:21:54 +02:00
if (!this->TriggerUsingHTTP(
files, prefix,
this->CTest->GetCTestConfiguration("TriggerSite"))) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Problems when triggering via HTTP" << std::endl);
ofs << " Problems when triggering via HTTP" << std::endl;
return -1;
}
2016-07-09 11:21:54 +02:00
}
if (this->HasErrors) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
" Errors occurred during "
"submission."
2016-07-09 11:21:54 +02:00
<< std::endl);
2010-03-17 14:00:29 +02:00
ofs << " Errors occurred during submission. " << std::endl;
2016-07-09 11:21:54 +02:00
} else {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Submission successful"
<< (this->HasWarnings ? ", with warnings." : "")
<< std::endl,
this->Quiet);
2016-07-09 11:21:54 +02:00
ofs << " Submission successful"
<< (this->HasWarnings ? ", with warnings." : "") << std::endl;
}
2010-03-17 14:00:29 +02:00
return 0;
2016-07-09 11:21:54 +02:00
} else if (dropMethod == "xmlrpc") {
2009-10-04 10:30:41 +03:00
#if defined(CTEST_USE_XMLRPC)
ofs << "Using drop method: XML-RPC" << std::endl;
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
2016-07-09 11:21:54 +02:00
" Using XML-RPC submit method" << std::endl,
this->Quiet);
std::string url = this->CTest->GetCTestConfiguration("DropSite");
prefix = this->CTest->GetCTestConfiguration("DropLocation");
2016-07-09 11:21:54 +02:00
if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
this->CTest->GetCurrentTag(),
files, prefix, url)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Problems when submitting via XML-RPC" << std::endl);
ofs << " Problems when submitting via XML-RPC" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Submission successful" << std::endl, this->Quiet);
ofs << " Submission successful" << std::endl;
return 0;
2009-10-04 10:30:41 +03:00
#else
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Submission method \"xmlrpc\" not compiled into CTest!"
2016-07-09 11:21:54 +02:00
<< std::endl);
2009-10-04 10:30:41 +03:00
return -1;
#endif
2016-07-09 11:21:54 +02:00
} else if (dropMethod == "scp") {
std::string url;
2016-07-09 11:21:54 +02:00
if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
2016-07-09 11:21:54 +02:00
}
url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
this->CTest->GetCTestConfiguration("DropLocation");
// change to the build directory so that we can uses a relative path
2018-04-23 21:13:27 +02:00
// on windows since scp doesn't support "c:" a drive in the path
2017-07-20 19:35:53 +02:00
cmWorkingDirectory workdir(buildDirectory);
2018-08-09 18:06:22 +02:00
if (workdir.Failed()) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Failed to change directory to "
<< buildDirectory << " : "
<< std::strerror(workdir.GetLastResult()) << std::endl);
ofs << " Failed to change directory to " << buildDirectory << " : "
<< std::strerror(workdir.GetLastResult()) << std::endl;
return -1;
}
2016-07-09 11:21:54 +02:00
if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
"Testing/" + this->CTest->GetCurrentTag(), files,
prefix, url)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Problems when submitting via SCP" << std::endl);
ofs << " Problems when submitting via SCP" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Submission successful" << std::endl, this->Quiet);
ofs << " Submission successful" << std::endl;
return 0;
2016-07-09 11:21:54 +02:00
} else if (dropMethod == "cp") {
std::string location = this->CTest->GetCTestConfiguration("DropLocation");
2009-10-04 10:30:41 +03:00
// change to the build directory so that we can uses a relative path
2018-04-23 21:13:27 +02:00
// on windows since scp doesn't support "c:" a drive in the path
2017-07-20 19:35:53 +02:00
cmWorkingDirectory workdir(buildDirectory);
2018-08-09 18:06:22 +02:00
if (workdir.Failed()) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Failed to change directory to "
<< buildDirectory << " : "
<< std::strerror(workdir.GetLastResult()) << std::endl);
ofs << " Failed to change directory to " << buildDirectory << " : "
<< std::strerror(workdir.GetLastResult()) << std::endl;
return -1;
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
" Change directory: " << buildDirectory << std::endl,
this->Quiet);
if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
prefix, location)) {
2009-10-04 10:30:41 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
" Problems when submitting via CP" << std::endl);
2009-10-04 10:30:41 +03:00
ofs << " Problems when submitting via cp" << std::endl;
return -1;
2016-07-09 11:21:54 +02:00
}
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Submission successful" << std::endl, this->Quiet);
2009-10-04 10:30:41 +03:00
ofs << " Submission successful" << std::endl;
return 0;
2016-07-09 11:21:54 +02:00
}
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Unknown submission method: \"" << dropMethod << "\""
<< std::endl);
return -1;
}
std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
{
2016-07-09 11:21:54 +02:00
std::string buildname =
cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
buildname + "___" + this->CTest->GetCurrentTag() + "-" +
this->CTest->GetTestModelString() + "___XML___";
return name;
}
2009-10-04 10:30:41 +03:00
void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
{
// Check whether each part is selected.
2016-07-09 11:21:54 +02:00
for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
p = cmCTest::Part(p + 1)) {
2009-10-04 10:30:41 +03:00
this->SubmitPart[p] =
(std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
}
2009-10-04 10:30:41 +03:00
void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
{
2015-04-27 22:25:09 +02:00
this->Files.insert(files.begin(), files.end());
2009-10-04 10:30:41 +03:00
}