cmCTestSubmitHandler.cxx 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestSubmitHandler.h"
  4. #include "cm_curl.h"
  5. #include "cm_jsoncpp_reader.h"
  6. #include "cm_jsoncpp_value.h"
  7. #include "cmsys/Process.h"
  8. #include <chrono>
  9. #include <cstring>
  10. #include <sstream>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "cmCTest.h"
  14. #include "cmCTestCurl.h"
  15. #include "cmCTestScriptHandler.h"
  16. #include "cmCryptoHash.h"
  17. #include "cmCurl.h"
  18. #include "cmDuration.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include "cmProcessOutput.h"
  21. #include "cmState.h"
  22. #include "cmSystemTools.h"
  23. #include "cmThirdParty.h"
  24. #include "cmWorkingDirectory.h"
  25. #include "cmXMLParser.h"
  26. #include "cmake.h"
  27. #if defined(CTEST_USE_XMLRPC)
  28. #include "cmVersion.h"
  29. #include "cm_sys_stat.h"
  30. #include "cm_xmlrpc.h"
  31. #endif
  32. #define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
  33. typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
  34. class cmCTestSubmitHandler::ResponseParser : public cmXMLParser
  35. {
  36. public:
  37. ResponseParser() { this->Status = STATUS_OK; }
  38. ~ResponseParser() override {}
  39. public:
  40. enum StatusType
  41. {
  42. STATUS_OK,
  43. STATUS_WARNING,
  44. STATUS_ERROR
  45. };
  46. StatusType Status;
  47. std::string Filename;
  48. std::string MD5;
  49. std::string Message;
  50. private:
  51. std::vector<char> CurrentValue;
  52. std::string GetCurrentValue()
  53. {
  54. std::string val;
  55. if (!this->CurrentValue.empty()) {
  56. val.assign(&this->CurrentValue[0], this->CurrentValue.size());
  57. }
  58. return val;
  59. }
  60. void StartElement(const std::string& /*name*/,
  61. const char** /*atts*/) override
  62. {
  63. this->CurrentValue.clear();
  64. }
  65. void CharacterDataHandler(const char* data, int length) override
  66. {
  67. this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
  68. }
  69. void EndElement(const std::string& name) override
  70. {
  71. if (name == "status") {
  72. std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
  73. if (status == "OK" || status == "SUCCESS") {
  74. this->Status = STATUS_OK;
  75. } else if (status == "WARNING") {
  76. this->Status = STATUS_WARNING;
  77. } else {
  78. this->Status = STATUS_ERROR;
  79. }
  80. } else if (name == "filename") {
  81. this->Filename = this->GetCurrentValue();
  82. } else if (name == "md5") {
  83. this->MD5 = this->GetCurrentValue();
  84. } else if (name == "message") {
  85. this->Message = this->GetCurrentValue();
  86. }
  87. }
  88. };
  89. static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size,
  90. size_t nmemb, void* data)
  91. {
  92. int realsize = static_cast<int>(size * nmemb);
  93. cmCTestSubmitHandlerVectorOfChar* vec =
  94. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  95. const char* chPtr = static_cast<char*>(ptr);
  96. vec->insert(vec->end(), chPtr, chPtr + realsize);
  97. return realsize;
  98. }
  99. static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
  100. curl_infotype /*unused*/,
  101. char* chPtr, size_t size,
  102. void* data)
  103. {
  104. cmCTestSubmitHandlerVectorOfChar* vec =
  105. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  106. vec->insert(vec->end(), chPtr, chPtr + size);
  107. return size;
  108. }
  109. cmCTestSubmitHandler::cmCTestSubmitHandler()
  110. : HTTPProxy()
  111. , FTPProxy()
  112. {
  113. this->Initialize();
  114. }
  115. void cmCTestSubmitHandler::Initialize()
  116. {
  117. // We submit all available parts by default.
  118. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  119. p = cmCTest::Part(p + 1)) {
  120. this->SubmitPart[p] = true;
  121. }
  122. this->CDash = false;
  123. this->HasWarnings = false;
  124. this->HasErrors = false;
  125. this->Superclass::Initialize();
  126. this->HTTPProxy.clear();
  127. this->HTTPProxyType = 0;
  128. this->HTTPProxyAuth.clear();
  129. this->FTPProxy.clear();
  130. this->FTPProxyType = 0;
  131. this->LogFile = nullptr;
  132. this->Files.clear();
  133. }
  134. bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix,
  135. const std::set<std::string>& files,
  136. const std::string& remoteprefix,
  137. const std::string& url)
  138. {
  139. CURL* curl;
  140. CURLcode res;
  141. FILE* ftpfile;
  142. char error_buffer[1024];
  143. /* In windows, this will init the winsock stuff */
  144. ::curl_global_init(CURL_GLOBAL_ALL);
  145. for (std::string const& file : files) {
  146. /* get a curl handle */
  147. curl = curl_easy_init();
  148. if (curl) {
  149. // Using proxy
  150. if (this->FTPProxyType > 0) {
  151. curl_easy_setopt(curl, CURLOPT_PROXY, this->FTPProxy.c_str());
  152. switch (this->FTPProxyType) {
  153. case 2:
  154. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  155. break;
  156. case 3:
  157. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  158. break;
  159. default:
  160. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  161. }
  162. }
  163. // enable uploading
  164. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  165. // if there is little to no activity for too long stop submitting
  166. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  167. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  168. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  169. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  170. std::string local_file = file;
  171. if (!cmSystemTools::FileExists(local_file)) {
  172. local_file = localprefix + "/" + file;
  173. }
  174. std::string upload_as =
  175. url + "/" + remoteprefix + cmSystemTools::GetFilenameName(file);
  176. if (!cmSystemTools::FileExists(local_file)) {
  177. cmCTestLog(this->CTest, ERROR_MESSAGE,
  178. " Cannot find file: " << local_file << std::endl);
  179. ::curl_easy_cleanup(curl);
  180. ::curl_global_cleanup();
  181. return false;
  182. }
  183. unsigned long filelen = cmSystemTools::FileLength(local_file);
  184. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  185. *this->LogFile << "\tUpload file: " << local_file << " to " << upload_as
  186. << std::endl;
  187. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  188. " Upload file: " << local_file << " to "
  189. << upload_as << std::endl,
  190. this->Quiet);
  191. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  192. // specify target
  193. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  194. // now specify which file to upload
  195. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  196. // and give the size of the upload (optional)
  197. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  198. // and give curl the buffer for errors
  199. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  200. // specify handler for output
  201. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  202. cmCTestSubmitHandlerWriteMemoryCallback);
  203. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  204. cmCTestSubmitHandlerCurlDebugCallback);
  205. /* we pass our 'chunk' struct to the callback function */
  206. cmCTestSubmitHandlerVectorOfChar chunk;
  207. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  208. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  209. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  210. // Now run off and do what you've been told!
  211. res = ::curl_easy_perform(curl);
  212. if (!chunk.empty()) {
  213. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  214. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  215. << "]" << std::endl,
  216. this->Quiet);
  217. }
  218. if (!chunkDebug.empty()) {
  219. cmCTestOptionalLog(
  220. this->CTest, DEBUG, "CURL debug output: ["
  221. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  222. << std::endl,
  223. this->Quiet);
  224. }
  225. fclose(ftpfile);
  226. if (res) {
  227. cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when uploading file: "
  228. << local_file << std::endl);
  229. cmCTestLog(this->CTest, ERROR_MESSAGE,
  230. " Error message was: " << error_buffer << std::endl);
  231. *this->LogFile << " Error when uploading file: " << local_file
  232. << std::endl
  233. << " Error message was: " << error_buffer << std::endl
  234. << " Curl output was: ";
  235. // avoid dereference of empty vector
  236. if (!chunk.empty()) {
  237. *this->LogFile << cmCTestLogWrite(&*chunk.begin(), chunk.size());
  238. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  239. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  240. << std::endl);
  241. }
  242. *this->LogFile << std::endl;
  243. ::curl_easy_cleanup(curl);
  244. ::curl_global_cleanup();
  245. return false;
  246. }
  247. // always cleanup
  248. ::curl_easy_cleanup(curl);
  249. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  250. " Uploaded: " + local_file << std::endl,
  251. this->Quiet);
  252. }
  253. }
  254. ::curl_global_cleanup();
  255. return true;
  256. }
  257. // Uploading files is simpler
  258. bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
  259. const std::set<std::string>& files,
  260. const std::string& remoteprefix,
  261. const std::string& url)
  262. {
  263. CURL* curl;
  264. CURLcode res;
  265. FILE* ftpfile;
  266. char error_buffer[1024];
  267. // Set Content-Type to satisfy fussy modsecurity rules.
  268. struct curl_slist* headers =
  269. ::curl_slist_append(nullptr, "Content-Type: text/xml");
  270. // Add any additional headers that the user specified.
  271. for (std::string const& h : this->HttpHeaders) {
  272. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  273. " Add HTTP Header: \"" << h << "\"" << std::endl,
  274. this->Quiet);
  275. headers = ::curl_slist_append(headers, h.c_str());
  276. }
  277. /* In windows, this will init the winsock stuff */
  278. ::curl_global_init(CURL_GLOBAL_ALL);
  279. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  280. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  281. std::vector<std::string> args;
  282. cmSystemTools::ExpandListArgument(curlopt, args);
  283. bool verifyPeerOff = false;
  284. bool verifyHostOff = false;
  285. for (std::string const& arg : args) {
  286. if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
  287. verifyPeerOff = true;
  288. }
  289. if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
  290. verifyHostOff = true;
  291. }
  292. }
  293. for (std::string const& file : files) {
  294. /* get a curl handle */
  295. curl = curl_easy_init();
  296. if (curl) {
  297. cmCurlSetCAInfo(curl);
  298. if (verifyPeerOff) {
  299. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  300. " Set CURLOPT_SSL_VERIFYPEER to off\n",
  301. this->Quiet);
  302. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  303. }
  304. if (verifyHostOff) {
  305. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  306. " Set CURLOPT_SSL_VERIFYHOST to off\n",
  307. this->Quiet);
  308. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
  309. }
  310. // Using proxy
  311. if (this->HTTPProxyType > 0) {
  312. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  313. switch (this->HTTPProxyType) {
  314. case 2:
  315. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  316. break;
  317. case 3:
  318. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  319. break;
  320. default:
  321. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  322. if (!this->HTTPProxyAuth.empty()) {
  323. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  324. this->HTTPProxyAuth.c_str());
  325. }
  326. }
  327. }
  328. if (this->CTest->ShouldUseHTTP10()) {
  329. curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  330. }
  331. // enable HTTP ERROR parsing
  332. curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  333. /* enable uploading */
  334. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  335. // if there is little to no activity for too long stop submitting
  336. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  337. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  338. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  339. /* HTTP PUT please */
  340. ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
  341. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  342. ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  343. std::string local_file = file;
  344. if (!cmSystemTools::FileExists(local_file)) {
  345. local_file = localprefix + "/" + file;
  346. }
  347. std::string remote_file =
  348. remoteprefix + cmSystemTools::GetFilenameName(file);
  349. *this->LogFile << "\tUpload file: " << local_file << " to "
  350. << remote_file << std::endl;
  351. std::string ofile;
  352. for (char c : remote_file) {
  353. char hexCh[4] = { 0, 0, 0, 0 };
  354. hexCh[0] = c;
  355. switch (c) {
  356. case '+':
  357. case '?':
  358. case '/':
  359. case '\\':
  360. case '&':
  361. case ' ':
  362. case '=':
  363. case '%':
  364. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  365. ofile.append(hexCh);
  366. break;
  367. default:
  368. ofile.append(hexCh);
  369. }
  370. }
  371. std::string upload_as = url +
  372. ((url.find('?') == std::string::npos) ? '?' : '&') + "FileName=" +
  373. ofile;
  374. upload_as += "&MD5=";
  375. if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) {
  376. upload_as += "bad_md5sum";
  377. } else {
  378. upload_as +=
  379. cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
  380. }
  381. if (!cmSystemTools::FileExists(local_file)) {
  382. cmCTestLog(this->CTest, ERROR_MESSAGE,
  383. " Cannot find file: " << local_file << std::endl);
  384. ::curl_easy_cleanup(curl);
  385. ::curl_slist_free_all(headers);
  386. ::curl_global_cleanup();
  387. return false;
  388. }
  389. unsigned long filelen = cmSystemTools::FileLength(local_file);
  390. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  391. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  392. " Upload file: " << local_file << " to "
  393. << upload_as << " Size: "
  394. << filelen << std::endl,
  395. this->Quiet);
  396. // specify target
  397. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  398. // now specify which file to upload
  399. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  400. // and give the size of the upload (optional)
  401. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  402. // and give curl the buffer for errors
  403. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  404. // specify handler for output
  405. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  406. cmCTestSubmitHandlerWriteMemoryCallback);
  407. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  408. cmCTestSubmitHandlerCurlDebugCallback);
  409. /* we pass our 'chunk' struct to the callback function */
  410. cmCTestSubmitHandlerVectorOfChar chunk;
  411. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  412. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  413. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  414. // Now run off and do what you've been told!
  415. res = ::curl_easy_perform(curl);
  416. if (!chunk.empty()) {
  417. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  418. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  419. << "]" << std::endl,
  420. this->Quiet);
  421. this->ParseResponse(chunk);
  422. }
  423. if (!chunkDebug.empty()) {
  424. cmCTestOptionalLog(
  425. this->CTest, DEBUG, "CURL debug output: ["
  426. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  427. << std::endl,
  428. this->Quiet);
  429. }
  430. // If curl failed for any reason, or checksum fails, wait and retry
  431. //
  432. if (res != CURLE_OK || this->HasErrors) {
  433. std::string retryDelay = this->GetOption("RetryDelay") == nullptr
  434. ? ""
  435. : this->GetOption("RetryDelay");
  436. std::string retryCount = this->GetOption("RetryCount") == nullptr
  437. ? ""
  438. : this->GetOption("RetryCount");
  439. auto delay = cmDuration(
  440. retryDelay.empty()
  441. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
  442. .c_str())
  443. : atoi(retryDelay.c_str()));
  444. int count = retryCount.empty()
  445. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
  446. .c_str())
  447. : atoi(retryCount.c_str());
  448. for (int i = 0; i < count; i++) {
  449. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  450. " Submit failed, waiting " << delay.count()
  451. << " seconds...\n",
  452. this->Quiet);
  453. auto stop = std::chrono::steady_clock::now() + delay;
  454. while (std::chrono::steady_clock::now() < stop) {
  455. cmSystemTools::Delay(100);
  456. }
  457. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  458. " Retry submission: Attempt "
  459. << (i + 1) << " of " << count << std::endl,
  460. this->Quiet);
  461. ::fclose(ftpfile);
  462. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  463. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  464. chunk.clear();
  465. chunkDebug.clear();
  466. this->HasErrors = false;
  467. res = ::curl_easy_perform(curl);
  468. if (!chunk.empty()) {
  469. cmCTestOptionalLog(
  470. this->CTest, DEBUG, "CURL output: ["
  471. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  472. << std::endl,
  473. this->Quiet);
  474. this->ParseResponse(chunk);
  475. }
  476. if (res == CURLE_OK && !this->HasErrors) {
  477. break;
  478. }
  479. }
  480. }
  481. fclose(ftpfile);
  482. if (res) {
  483. cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when uploading file: "
  484. << local_file << std::endl);
  485. cmCTestLog(this->CTest, ERROR_MESSAGE,
  486. " Error message was: " << error_buffer << std::endl);
  487. *this->LogFile << " Error when uploading file: " << local_file
  488. << std::endl
  489. << " Error message was: " << error_buffer
  490. << std::endl;
  491. // avoid deref of begin for zero size array
  492. if (!chunk.empty()) {
  493. *this->LogFile << " Curl output was: "
  494. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  495. << std::endl;
  496. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  497. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  498. << std::endl);
  499. }
  500. ::curl_easy_cleanup(curl);
  501. ::curl_slist_free_all(headers);
  502. ::curl_global_cleanup();
  503. return false;
  504. }
  505. // always cleanup
  506. ::curl_easy_cleanup(curl);
  507. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  508. " Uploaded: " + local_file << std::endl,
  509. this->Quiet);
  510. }
  511. }
  512. ::curl_slist_free_all(headers);
  513. ::curl_global_cleanup();
  514. return true;
  515. }
  516. void cmCTestSubmitHandler::ParseResponse(
  517. cmCTestSubmitHandlerVectorOfChar chunk)
  518. {
  519. std::string output;
  520. output.append(chunk.begin(), chunk.end());
  521. if (output.find("<cdash") != std::string::npos) {
  522. ResponseParser parser;
  523. parser.Parse(output.c_str());
  524. if (parser.Status != ResponseParser::STATUS_OK) {
  525. this->HasErrors = true;
  526. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  527. " Submission failed: " << parser.Message << std::endl);
  528. return;
  529. }
  530. }
  531. output = cmSystemTools::UpperCase(output);
  532. if (output.find("WARNING") != std::string::npos) {
  533. this->HasWarnings = true;
  534. }
  535. if (output.find("ERROR") != std::string::npos) {
  536. this->HasErrors = true;
  537. }
  538. if (this->HasWarnings || this->HasErrors) {
  539. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n"
  540. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
  541. }
  542. }
  543. bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set<std::string>& files,
  544. const std::string& remoteprefix,
  545. const std::string& url)
  546. {
  547. CURL* curl;
  548. char error_buffer[1024];
  549. /* In windows, this will init the winsock stuff */
  550. ::curl_global_init(CURL_GLOBAL_ALL);
  551. for (std::string const& file : files) {
  552. /* get a curl handle */
  553. curl = curl_easy_init();
  554. if (curl) {
  555. // Using proxy
  556. if (this->HTTPProxyType > 0) {
  557. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  558. switch (this->HTTPProxyType) {
  559. case 2:
  560. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  561. break;
  562. case 3:
  563. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  564. break;
  565. default:
  566. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  567. if (!this->HTTPProxyAuth.empty()) {
  568. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  569. this->HTTPProxyAuth.c_str());
  570. }
  571. }
  572. }
  573. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  574. // and give curl the buffer for errors
  575. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  576. // specify handler for output
  577. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  578. cmCTestSubmitHandlerWriteMemoryCallback);
  579. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  580. cmCTestSubmitHandlerCurlDebugCallback);
  581. /* we pass our 'chunk' struct to the callback function */
  582. cmCTestSubmitHandlerVectorOfChar chunk;
  583. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  584. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  585. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  586. std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(file);
  587. std::string ofile;
  588. for (char c : rfile) {
  589. char hexCh[4] = { 0, 0, 0, 0 };
  590. hexCh[0] = c;
  591. switch (c) {
  592. case '+':
  593. case '?':
  594. case '/':
  595. case '\\':
  596. case '&':
  597. case ' ':
  598. case '=':
  599. case '%':
  600. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  601. ofile.append(hexCh);
  602. break;
  603. default:
  604. ofile.append(hexCh);
  605. }
  606. }
  607. std::string turl = url +
  608. ((url.find('?') == std::string::npos) ? '?' : '&') + "xmlfile=" +
  609. ofile;
  610. *this->LogFile << "Trigger url: " << turl << std::endl;
  611. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  612. " Trigger url: " << turl << std::endl, this->Quiet);
  613. curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  614. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  615. if (curl_easy_perform(curl)) {
  616. cmCTestLog(this->CTest, ERROR_MESSAGE,
  617. " Error when triggering: " << turl << std::endl);
  618. cmCTestLog(this->CTest, ERROR_MESSAGE,
  619. " Error message was: " << error_buffer << std::endl);
  620. *this->LogFile << "\tTriggering failed with error: " << error_buffer
  621. << std::endl
  622. << " Error message was: " << error_buffer
  623. << std::endl;
  624. if (!chunk.empty()) {
  625. *this->LogFile << " Curl output was: "
  626. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  627. << std::endl;
  628. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  629. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  630. << std::endl);
  631. }
  632. ::curl_easy_cleanup(curl);
  633. ::curl_global_cleanup();
  634. return false;
  635. }
  636. if (!chunk.empty()) {
  637. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  638. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  639. << "]" << std::endl,
  640. this->Quiet);
  641. }
  642. if (!chunkDebug.empty()) {
  643. cmCTestOptionalLog(
  644. this->CTest, DEBUG, "CURL debug output: ["
  645. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  646. << std::endl,
  647. this->Quiet);
  648. }
  649. // always cleanup
  650. ::curl_easy_cleanup(curl);
  651. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
  652. this->Quiet);
  653. }
  654. }
  655. ::curl_global_cleanup();
  656. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  657. " Dart server triggered..." << std::endl, this->Quiet);
  658. return true;
  659. }
  660. bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command,
  661. const std::string& localprefix,
  662. const std::set<std::string>& files,
  663. const std::string& remoteprefix,
  664. const std::string& url)
  665. {
  666. if (scp_command.empty() || localprefix.empty() || files.empty() ||
  667. remoteprefix.empty() || url.empty()) {
  668. return false;
  669. }
  670. std::vector<const char*> argv;
  671. argv.push_back(scp_command.c_str()); // Scp command
  672. argv.push_back(scp_command.c_str()); // Dummy string for file
  673. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  674. argv.push_back(nullptr);
  675. cmsysProcess* cp = cmsysProcess_New();
  676. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  677. // cmsysProcess_SetTimeout(cp, timeout);
  678. int problems = 0;
  679. for (std::string const& file : files) {
  680. int retVal;
  681. std::string lfname = localprefix;
  682. cmSystemTools::ConvertToUnixSlashes(lfname);
  683. lfname += "/" + file;
  684. lfname = cmSystemTools::ConvertToOutputPath(lfname);
  685. argv[1] = lfname.c_str();
  686. std::string rfname = url + "/" + remoteprefix + file;
  687. argv[2] = rfname.c_str();
  688. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Execute \""
  689. << argv[0] << "\" \"" << argv[1] << "\" \"" << argv[2]
  690. << "\"" << std::endl,
  691. this->Quiet);
  692. *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  693. << argv[2] << "\"" << std::endl;
  694. cmsysProcess_SetCommand(cp, &*argv.begin());
  695. cmsysProcess_Execute(cp);
  696. char* data;
  697. int length;
  698. cmProcessOutput processOutput;
  699. std::string strdata;
  700. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  701. processOutput.DecodeText(data, length, strdata);
  702. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  703. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  704. this->Quiet);
  705. }
  706. processOutput.DecodeText(std::string(), strdata);
  707. if (!strdata.empty()) {
  708. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  709. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  710. this->Quiet);
  711. }
  712. cmsysProcess_WaitForExit(cp, nullptr);
  713. int result = cmsysProcess_GetState(cp);
  714. if (result == cmsysProcess_State_Exited) {
  715. retVal = cmsysProcess_GetExitValue(cp);
  716. if (retVal != 0) {
  717. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  718. "\tSCP returned: " << retVal << std::endl,
  719. this->Quiet);
  720. *this->LogFile << "\tSCP returned: " << retVal << std::endl;
  721. problems++;
  722. }
  723. } else if (result == cmsysProcess_State_Exception) {
  724. retVal = cmsysProcess_GetExitException(cp);
  725. cmCTestLog(this->CTest, ERROR_MESSAGE,
  726. "\tThere was an exception: " << retVal << std::endl);
  727. *this->LogFile << "\tThere was an exception: " << retVal << std::endl;
  728. problems++;
  729. } else if (result == cmsysProcess_State_Expired) {
  730. cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was a timeout"
  731. << std::endl);
  732. *this->LogFile << "\tThere was a timeout" << std::endl;
  733. problems++;
  734. } else if (result == cmsysProcess_State_Error) {
  735. cmCTestLog(this->CTest, ERROR_MESSAGE, "\tError executing SCP: "
  736. << cmsysProcess_GetErrorString(cp) << std::endl);
  737. *this->LogFile << "\tError executing SCP: "
  738. << cmsysProcess_GetErrorString(cp) << std::endl;
  739. problems++;
  740. }
  741. }
  742. cmsysProcess_Delete(cp);
  743. return problems == 0;
  744. }
  745. bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
  746. const std::set<std::string>& files,
  747. const std::string& remoteprefix,
  748. const std::string& destination)
  749. {
  750. if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
  751. destination.empty()) {
  752. /* clang-format off */
  753. cmCTestLog(this->CTest, ERROR_MESSAGE,
  754. "Missing arguments for submit via cp:\n"
  755. << "\tlocalprefix: " << localprefix << "\n"
  756. << "\tNumber of files: " << files.size() << "\n"
  757. << "\tremoteprefix: " << remoteprefix << "\n"
  758. << "\tdestination: " << destination << std::endl);
  759. /* clang-format on */
  760. return false;
  761. }
  762. for (std::string const& file : files) {
  763. std::string lfname = localprefix;
  764. cmSystemTools::ConvertToUnixSlashes(lfname);
  765. lfname += "/" + file;
  766. std::string rfname = destination + "/" + remoteprefix + file;
  767. cmSystemTools::CopyFileAlways(lfname, rfname);
  768. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Copy file: "
  769. << lfname << " to " << rfname << std::endl,
  770. this->Quiet);
  771. }
  772. std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
  773. cmSystemTools::Touch(tagDoneFile, true);
  774. return true;
  775. }
  776. #if defined(CTEST_USE_XMLRPC)
  777. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  778. const std::string& localprefix, const std::set<std::string>& files,
  779. const std::string& remoteprefix, const std::string& url)
  780. {
  781. xmlrpc_env env;
  782. char ctestString[] = "CTest";
  783. std::string ctestVersionString = cmVersion::GetCMakeVersion();
  784. char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
  785. std::string realURL = url + "/" + remoteprefix + "/Command/";
  786. /* Start up our XML-RPC client library. */
  787. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
  788. /* Initialize our error-handling environment. */
  789. xmlrpc_env_init(&env);
  790. /* Call the famous server at UserLand. */
  791. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Submitting to: "
  792. << realURL << " (" << remoteprefix << ")" << std::endl,
  793. this->Quiet);
  794. for (std::string const& file : files) {
  795. xmlrpc_value* result;
  796. std::string local_file = file;
  797. if (!cmSystemTools::FileExists(local_file)) {
  798. local_file = localprefix + "/" + file;
  799. }
  800. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  801. " Submit file: " << local_file << std::endl,
  802. this->Quiet);
  803. struct stat st;
  804. if (::stat(local_file.c_str(), &st)) {
  805. cmCTestLog(this->CTest, ERROR_MESSAGE,
  806. " Cannot find file: " << local_file << std::endl);
  807. return false;
  808. }
  809. // off_t can be bigger than size_t. fread takes size_t.
  810. // make sure the file is not too big.
  811. if (static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
  812. static_cast<off_t>(st.st_size)) {
  813. cmCTestLog(this->CTest, ERROR_MESSAGE, " File too big: " << local_file
  814. << std::endl);
  815. return false;
  816. }
  817. size_t fileSize = static_cast<size_t>(st.st_size);
  818. FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
  819. if (!fp) {
  820. cmCTestLog(this->CTest, ERROR_MESSAGE,
  821. " Cannot open file: " << local_file << std::endl);
  822. return false;
  823. }
  824. unsigned char* fileBuffer = new unsigned char[fileSize];
  825. if (fread(fileBuffer, 1, fileSize, fp) != fileSize) {
  826. delete[] fileBuffer;
  827. fclose(fp);
  828. cmCTestLog(this->CTest, ERROR_MESSAGE,
  829. " Cannot read file: " << local_file << std::endl);
  830. return false;
  831. }
  832. fclose(fp);
  833. char remoteCommand[] = "Submit.put";
  834. char* pRealURL = const_cast<char*>(realURL.c_str());
  835. result =
  836. xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer,
  837. static_cast<xmlrpc_int32>(fileSize));
  838. delete[] fileBuffer;
  839. if (env.fault_occurred) {
  840. cmCTestLog(this->CTest, ERROR_MESSAGE, " Submission problem: "
  841. << env.fault_string << " (" << env.fault_code << ")"
  842. << std::endl);
  843. xmlrpc_env_clean(&env);
  844. xmlrpc_client_cleanup();
  845. return false;
  846. }
  847. /* Dispose of our result value. */
  848. xmlrpc_DECREF(result);
  849. }
  850. /* Clean up our error-handling environment. */
  851. xmlrpc_env_clean(&env);
  852. /* Shutdown our XML-RPC client library. */
  853. xmlrpc_client_cleanup();
  854. return true;
  855. }
  856. #else
  857. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  858. std::string const& /*unused*/, std::set<std::string> const& /*unused*/,
  859. std::string const& /*unused*/, std::string const& /*unused*/)
  860. {
  861. return false;
  862. }
  863. #endif
  864. void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
  865. std::string& url)
  866. {
  867. dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
  868. url = dropMethod;
  869. url += "://";
  870. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  871. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  872. cmCTestOptionalLog(
  873. this->CTest, HANDLER_OUTPUT,
  874. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
  875. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  876. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  877. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
  878. }
  879. url += "@";
  880. }
  881. url += this->CTest->GetCTestConfiguration("DropSite") +
  882. this->CTest->GetCTestConfiguration("DropLocation");
  883. }
  884. int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
  885. std::string const& typeString)
  886. {
  887. if (file.empty()) {
  888. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not specified\n");
  889. return -1;
  890. }
  891. if (!cmSystemTools::FileExists(file)) {
  892. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not found: '"
  893. << file << "'\n");
  894. return -1;
  895. }
  896. cmCTestCurl curl(this->CTest);
  897. curl.SetQuiet(this->Quiet);
  898. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  899. std::vector<std::string> args;
  900. cmSystemTools::ExpandListArgument(curlopt, args);
  901. curl.SetCurlOptions(args);
  902. curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  903. curl.SetHttpHeaders(this->HttpHeaders);
  904. std::string dropMethod;
  905. std::string url;
  906. this->ConstructCDashURL(dropMethod, url);
  907. std::string::size_type pos = url.find("submit.php?");
  908. url = url.substr(0, pos + 10);
  909. if (!(dropMethod == "http" || dropMethod == "https")) {
  910. cmCTestLog(this->CTest, ERROR_MESSAGE,
  911. "Only http and https are supported for CDASH_UPLOAD\n");
  912. return -1;
  913. }
  914. bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
  915. // Get RETRY_COUNT and RETRY_DELAY values if they were set.
  916. std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
  917. ? ""
  918. : this->GetOption("RetryDelay");
  919. std::string retryCountString = this->GetOption("RetryCount") == nullptr
  920. ? ""
  921. : this->GetOption("RetryCount");
  922. auto retryDelay = std::chrono::seconds(0);
  923. if (!retryDelayString.empty()) {
  924. unsigned long retryDelayValue = 0;
  925. if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
  926. &retryDelayValue)) {
  927. cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
  928. << retryDelayString << std::endl);
  929. } else {
  930. retryDelay = std::chrono::seconds(retryDelayValue);
  931. }
  932. }
  933. unsigned long retryCount = 0;
  934. if (!retryCountString.empty()) {
  935. if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
  936. cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
  937. << retryCountString << std::endl);
  938. }
  939. }
  940. std::string md5sum =
  941. cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
  942. // 1. request the buildid and check to see if the file
  943. // has already been uploaded
  944. // TODO I added support for subproject. You would need to add
  945. // a "&subproject=subprojectname" to the first POST.
  946. cmCTestScriptHandler* ch =
  947. static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
  948. cmake* cm = ch->GetCMake();
  949. const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
  950. // TODO: Encode values for a URL instead of trusting caller.
  951. std::ostringstream str;
  952. str << "project="
  953. << curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
  954. if (subproject) {
  955. str << "subproject=" << curl.Escape(subproject) << "&";
  956. }
  957. auto timeNow =
  958. std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  959. str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
  960. << curl.Escape(this->CTest->GetTestModelString()) << "&"
  961. << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  962. << "build="
  963. << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
  964. << "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
  965. << "&"
  966. << "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  967. << "starttime=" << timeNow << "&"
  968. << "endtime=" << timeNow << "&"
  969. << "datafilesmd5[0]=" << md5sum << "&"
  970. << "type=" << curl.Escape(typeString);
  971. std::string fields = str.str();
  972. cmCTestOptionalLog(this->CTest, DEBUG,
  973. "fields: " << fields << "\nurl:" << url
  974. << "\nfile: " << file << "\n",
  975. this->Quiet);
  976. std::string response;
  977. bool requestSucceeded = curl.HttpRequest(url, fields, response);
  978. if (!internalTest && !requestSucceeded) {
  979. // If request failed, wait and retry.
  980. for (unsigned long i = 0; i < retryCount; i++) {
  981. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  982. " Request failed, waiting " << retryDelay.count()
  983. << " seconds...\n",
  984. this->Quiet);
  985. auto stop = std::chrono::steady_clock::now() + retryDelay;
  986. while (std::chrono::steady_clock::now() < stop) {
  987. cmSystemTools::Delay(100);
  988. }
  989. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  990. " Retry request: Attempt "
  991. << (i + 1) << " of " << retryCount << std::endl,
  992. this->Quiet);
  993. requestSucceeded = curl.HttpRequest(url, fields, response);
  994. if (requestSucceeded) {
  995. break;
  996. }
  997. }
  998. }
  999. if (!internalTest && !requestSucceeded) {
  1000. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in HttpRequest\n"
  1001. << response);
  1002. return -1;
  1003. }
  1004. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1005. "Request upload response: [" << response << "]\n",
  1006. this->Quiet);
  1007. Json::Value json;
  1008. Json::Reader reader;
  1009. if (!internalTest && !reader.parse(response, json)) {
  1010. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1011. << response << "]\n"
  1012. << reader.getFormattedErrorMessages() << "\n");
  1013. return -1;
  1014. }
  1015. if (!internalTest && json["status"].asInt() != 0) {
  1016. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1017. "Bad status returned from CDash: " << json["status"].asInt());
  1018. return -1;
  1019. }
  1020. if (!internalTest) {
  1021. if (json["datafilesmd5"].isArray()) {
  1022. int datares = json["datafilesmd5"][0].asInt();
  1023. if (datares == 1) {
  1024. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1025. "File already exists on CDash, skip upload "
  1026. << file << "\n",
  1027. this->Quiet);
  1028. return 0;
  1029. }
  1030. } else {
  1031. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1032. "bad datafilesmd5 value in response " << response << "\n");
  1033. return -1;
  1034. }
  1035. }
  1036. std::string upload_as = cmSystemTools::GetFilenameName(file);
  1037. std::ostringstream fstr;
  1038. fstr << "type=" << curl.Escape(typeString) << "&"
  1039. << "md5=" << md5sum << "&"
  1040. << "filename=" << curl.Escape(upload_as) << "&"
  1041. << "buildid=" << json["buildid"].asString();
  1042. bool uploadSucceeded = false;
  1043. if (!internalTest) {
  1044. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1045. }
  1046. if (!uploadSucceeded) {
  1047. // If upload failed, wait and retry.
  1048. for (unsigned long i = 0; i < retryCount; i++) {
  1049. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1050. " Upload failed, waiting " << retryDelay.count()
  1051. << " seconds...\n",
  1052. this->Quiet);
  1053. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1054. while (std::chrono::steady_clock::now() < stop) {
  1055. cmSystemTools::Delay(100);
  1056. }
  1057. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1058. " Retry upload: Attempt "
  1059. << (i + 1) << " of " << retryCount << std::endl,
  1060. this->Quiet);
  1061. if (!internalTest) {
  1062. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1063. }
  1064. if (uploadSucceeded) {
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. if (!uploadSucceeded) {
  1070. cmCTestLog(this->CTest, ERROR_MESSAGE, "error uploading to CDash. "
  1071. << file << " " << url << " " << fstr.str());
  1072. return -1;
  1073. }
  1074. if (!reader.parse(response, json)) {
  1075. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1076. << response << "]\n"
  1077. << reader.getFormattedErrorMessages() << "\n");
  1078. return -1;
  1079. }
  1080. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1081. "Upload file response: [" << response << "]\n",
  1082. this->Quiet);
  1083. return 0;
  1084. }
  1085. int cmCTestSubmitHandler::ProcessHandler()
  1086. {
  1087. const char* cdashUploadFile = this->GetOption("CDashUploadFile");
  1088. const char* cdashUploadType = this->GetOption("CDashUploadType");
  1089. if (cdashUploadFile && cdashUploadType) {
  1090. return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
  1091. }
  1092. std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
  1093. // cdash does not need to trigger so just return true
  1094. if (!iscdash.empty()) {
  1095. this->CDash = true;
  1096. }
  1097. const std::string& buildDirectory =
  1098. this->CTest->GetCTestConfiguration("BuildDirectory");
  1099. if (buildDirectory.empty()) {
  1100. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1101. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  1102. << std::endl);
  1103. return -1;
  1104. }
  1105. if (getenv("HTTP_PROXY")) {
  1106. this->HTTPProxyType = 1;
  1107. this->HTTPProxy = getenv("HTTP_PROXY");
  1108. if (getenv("HTTP_PROXY_PORT")) {
  1109. this->HTTPProxy += ":";
  1110. this->HTTPProxy += getenv("HTTP_PROXY_PORT");
  1111. }
  1112. if (getenv("HTTP_PROXY_TYPE")) {
  1113. std::string type = getenv("HTTP_PROXY_TYPE");
  1114. // HTTP/SOCKS4/SOCKS5
  1115. if (type == "HTTP") {
  1116. this->HTTPProxyType = 1;
  1117. } else if (type == "SOCKS4") {
  1118. this->HTTPProxyType = 2;
  1119. } else if (type == "SOCKS5") {
  1120. this->HTTPProxyType = 3;
  1121. }
  1122. }
  1123. if (getenv("HTTP_PROXY_USER")) {
  1124. this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  1125. }
  1126. if (getenv("HTTP_PROXY_PASSWD")) {
  1127. this->HTTPProxyAuth += ":";
  1128. this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  1129. }
  1130. }
  1131. if (getenv("FTP_PROXY")) {
  1132. this->FTPProxyType = 1;
  1133. this->FTPProxy = getenv("FTP_PROXY");
  1134. if (getenv("FTP_PROXY_PORT")) {
  1135. this->FTPProxy += ":";
  1136. this->FTPProxy += getenv("FTP_PROXY_PORT");
  1137. }
  1138. if (getenv("FTP_PROXY_TYPE")) {
  1139. std::string type = getenv("FTP_PROXY_TYPE");
  1140. // HTTP/SOCKS4/SOCKS5
  1141. if (type == "HTTP") {
  1142. this->FTPProxyType = 1;
  1143. } else if (type == "SOCKS4") {
  1144. this->FTPProxyType = 2;
  1145. } else if (type == "SOCKS5") {
  1146. this->FTPProxyType = 3;
  1147. }
  1148. }
  1149. }
  1150. if (!this->HTTPProxy.empty()) {
  1151. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1152. " Use HTTP Proxy: " << this->HTTPProxy << std::endl,
  1153. this->Quiet);
  1154. }
  1155. if (!this->FTPProxy.empty()) {
  1156. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1157. " Use FTP Proxy: " << this->FTPProxy << std::endl,
  1158. this->Quiet);
  1159. }
  1160. cmGeneratedFileStream ofs;
  1161. this->StartLogFile("Submit", ofs);
  1162. cmCTest::SetOfStrings files;
  1163. std::string prefix = this->GetSubmitResultsPrefix();
  1164. if (!this->Files.empty()) {
  1165. // Submit the explicitly selected files:
  1166. //
  1167. files.insert(this->Files.begin(), this->Files.end());
  1168. }
  1169. // Add to the list of files to submit from any selected, existing parts:
  1170. //
  1171. // TODO:
  1172. // Check if test is enabled
  1173. this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
  1174. this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
  1175. this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
  1176. this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
  1177. if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
  1178. std::vector<std::string> gfiles;
  1179. std::string gpath =
  1180. buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
  1181. std::string::size_type glen = gpath.size() + 1;
  1182. gpath = gpath + "/CoverageLog*";
  1183. cmCTestOptionalLog(this->CTest, DEBUG,
  1184. "Globbing for: " << gpath << std::endl, this->Quiet);
  1185. if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
  1186. for (std::string& gfile : gfiles) {
  1187. gfile = gfile.substr(glen);
  1188. cmCTestOptionalLog(this->CTest, DEBUG,
  1189. "Glob file: " << gfile << std::endl, this->Quiet);
  1190. this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
  1191. }
  1192. } else {
  1193. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
  1194. }
  1195. }
  1196. this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
  1197. this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
  1198. this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
  1199. this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
  1200. // Query parts for files to submit.
  1201. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1202. p = cmCTest::Part(p + 1)) {
  1203. // Skip parts we are not submitting.
  1204. if (!this->SubmitPart[p]) {
  1205. continue;
  1206. }
  1207. // Submit files from this part.
  1208. std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
  1209. files.insert(pfiles.begin(), pfiles.end());
  1210. }
  1211. if (ofs) {
  1212. ofs << "Upload files:" << std::endl;
  1213. int cnt = 0;
  1214. for (std::string const& file : files) {
  1215. ofs << cnt << "\t" << file << std::endl;
  1216. cnt++;
  1217. }
  1218. }
  1219. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files (using "
  1220. << this->CTest->GetCTestConfiguration("DropMethod")
  1221. << ")" << std::endl,
  1222. this->Quiet);
  1223. const char* specificTrack = this->CTest->GetSpecificTrack();
  1224. if (specificTrack) {
  1225. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1226. " Send to track: " << specificTrack << std::endl,
  1227. this->Quiet);
  1228. }
  1229. this->SetLogFile(&ofs);
  1230. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  1231. if (dropMethod.empty() || dropMethod == "ftp") {
  1232. ofs << "Using drop method: FTP" << std::endl;
  1233. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1234. " Using FTP submit method" << std::endl
  1235. << " Drop site: ftp://",
  1236. this->Quiet);
  1237. std::string url = "ftp://";
  1238. url += cmCTest::MakeURLSafe(
  1239. this->CTest->GetCTestConfiguration("DropSiteUser")) +
  1240. ":" + cmCTest::MakeURLSafe(
  1241. this->CTest->GetCTestConfiguration("DropSitePassword")) +
  1242. "@" + this->CTest->GetCTestConfiguration("DropSite") +
  1243. cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
  1244. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1245. cmCTestOptionalLog(
  1246. this->CTest, HANDLER_OUTPUT,
  1247. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1248. this->Quiet);
  1249. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1250. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1251. this->Quiet);
  1252. }
  1253. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1254. }
  1255. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1256. this->CTest->GetCTestConfiguration("DropSite")
  1257. << this->CTest->GetCTestConfiguration("DropLocation")
  1258. << std::endl,
  1259. this->Quiet);
  1260. if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
  1261. this->CTest->GetCurrentTag(),
  1262. files, prefix, url)) {
  1263. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1264. " Problems when submitting via FTP" << std::endl);
  1265. ofs << " Problems when submitting via FTP" << std::endl;
  1266. return -1;
  1267. }
  1268. if (!this->CDash) {
  1269. cmCTestOptionalLog(
  1270. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1271. << std::endl
  1272. << " Trigger site: "
  1273. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1274. this->Quiet);
  1275. if (!this->TriggerUsingHTTP(
  1276. files, prefix,
  1277. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1278. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1279. " Problems when triggering via HTTP" << std::endl);
  1280. ofs << " Problems when triggering via HTTP" << std::endl;
  1281. return -1;
  1282. }
  1283. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1284. " Submission successful" << std::endl, this->Quiet);
  1285. ofs << " Submission successful" << std::endl;
  1286. return 0;
  1287. }
  1288. } else if (dropMethod == "http" || dropMethod == "https") {
  1289. std::string url = dropMethod;
  1290. url += "://";
  1291. ofs << "Using drop method: " << dropMethod << std::endl;
  1292. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1293. " Using HTTP submit method" << std::endl
  1294. << " Drop site:" << url,
  1295. this->Quiet);
  1296. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1297. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  1298. cmCTestOptionalLog(
  1299. this->CTest, HANDLER_OUTPUT,
  1300. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1301. this->Quiet);
  1302. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1303. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  1304. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1305. this->Quiet);
  1306. }
  1307. url += "@";
  1308. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1309. }
  1310. url += this->CTest->GetCTestConfiguration("DropSite") +
  1311. this->CTest->GetCTestConfiguration("DropLocation");
  1312. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1313. this->CTest->GetCTestConfiguration("DropSite")
  1314. << this->CTest->GetCTestConfiguration("DropLocation")
  1315. << std::endl,
  1316. this->Quiet);
  1317. if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
  1318. this->CTest->GetCurrentTag(),
  1319. files, prefix, url)) {
  1320. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1321. " Problems when submitting via HTTP" << std::endl);
  1322. ofs << " Problems when submitting via HTTP" << std::endl;
  1323. return -1;
  1324. }
  1325. if (!this->CDash) {
  1326. cmCTestOptionalLog(
  1327. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1328. << std::endl
  1329. << " Trigger site: "
  1330. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1331. this->Quiet);
  1332. if (!this->TriggerUsingHTTP(
  1333. files, prefix,
  1334. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1335. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1336. " Problems when triggering via HTTP" << std::endl);
  1337. ofs << " Problems when triggering via HTTP" << std::endl;
  1338. return -1;
  1339. }
  1340. }
  1341. if (this->HasErrors) {
  1342. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Errors occurred during "
  1343. "submission."
  1344. << std::endl);
  1345. ofs << " Errors occurred during submission. " << std::endl;
  1346. } else {
  1347. cmCTestOptionalLog(
  1348. this->CTest, HANDLER_OUTPUT, " Submission successful"
  1349. << (this->HasWarnings ? ", with warnings." : "") << std::endl,
  1350. this->Quiet);
  1351. ofs << " Submission successful"
  1352. << (this->HasWarnings ? ", with warnings." : "") << std::endl;
  1353. }
  1354. return 0;
  1355. } else if (dropMethod == "xmlrpc") {
  1356. #if defined(CTEST_USE_XMLRPC)
  1357. ofs << "Using drop method: XML-RPC" << std::endl;
  1358. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1359. " Using XML-RPC submit method" << std::endl,
  1360. this->Quiet);
  1361. std::string url = this->CTest->GetCTestConfiguration("DropSite");
  1362. prefix = this->CTest->GetCTestConfiguration("DropLocation");
  1363. if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
  1364. this->CTest->GetCurrentTag(),
  1365. files, prefix, url)) {
  1366. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1367. " Problems when submitting via XML-RPC" << std::endl);
  1368. ofs << " Problems when submitting via XML-RPC" << std::endl;
  1369. return -1;
  1370. }
  1371. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1372. " Submission successful" << std::endl, this->Quiet);
  1373. ofs << " Submission successful" << std::endl;
  1374. return 0;
  1375. #else
  1376. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1377. " Submission method \"xmlrpc\" not compiled into CTest!"
  1378. << std::endl);
  1379. return -1;
  1380. #endif
  1381. } else if (dropMethod == "scp") {
  1382. std::string url;
  1383. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1384. url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
  1385. }
  1386. url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
  1387. this->CTest->GetCTestConfiguration("DropLocation");
  1388. // change to the build directory so that we can uses a relative path
  1389. // on windows since scp doesn't support "c:" a drive in the path
  1390. cmWorkingDirectory workdir(buildDirectory);
  1391. if (workdir.Failed()) {
  1392. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1393. " Failed to change directory to "
  1394. << buildDirectory << " : "
  1395. << std::strerror(workdir.GetLastResult()) << std::endl);
  1396. ofs << " Failed to change directory to " << buildDirectory << " : "
  1397. << std::strerror(workdir.GetLastResult()) << std::endl;
  1398. return -1;
  1399. }
  1400. if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
  1401. "Testing/" + this->CTest->GetCurrentTag(), files,
  1402. prefix, url)) {
  1403. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1404. " Problems when submitting via SCP" << std::endl);
  1405. ofs << " Problems when submitting via SCP" << std::endl;
  1406. return -1;
  1407. }
  1408. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1409. " Submission successful" << std::endl, this->Quiet);
  1410. ofs << " Submission successful" << std::endl;
  1411. return 0;
  1412. } else if (dropMethod == "cp") {
  1413. std::string location = this->CTest->GetCTestConfiguration("DropLocation");
  1414. // change to the build directory so that we can uses a relative path
  1415. // on windows since scp doesn't support "c:" a drive in the path
  1416. cmWorkingDirectory workdir(buildDirectory);
  1417. if (workdir.Failed()) {
  1418. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1419. " Failed to change directory to "
  1420. << buildDirectory << " : "
  1421. << std::strerror(workdir.GetLastResult()) << std::endl);
  1422. ofs << " Failed to change directory to " << buildDirectory << " : "
  1423. << std::strerror(workdir.GetLastResult()) << std::endl;
  1424. return -1;
  1425. }
  1426. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1427. " Change directory: " << buildDirectory << std::endl,
  1428. this->Quiet);
  1429. if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
  1430. prefix, location)) {
  1431. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1432. " Problems when submitting via CP" << std::endl);
  1433. ofs << " Problems when submitting via cp" << std::endl;
  1434. return -1;
  1435. }
  1436. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1437. " Submission successful" << std::endl, this->Quiet);
  1438. ofs << " Submission successful" << std::endl;
  1439. return 0;
  1440. }
  1441. cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown submission method: \""
  1442. << dropMethod << "\"" << std::endl);
  1443. return -1;
  1444. }
  1445. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  1446. {
  1447. std::string buildname =
  1448. cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
  1449. std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
  1450. buildname + "___" + this->CTest->GetCurrentTag() + "-" +
  1451. this->CTest->GetTestModelString() + "___XML___";
  1452. return name;
  1453. }
  1454. void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
  1455. {
  1456. // Check whether each part is selected.
  1457. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1458. p = cmCTest::Part(p + 1)) {
  1459. this->SubmitPart[p] =
  1460. (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
  1461. }
  1462. }
  1463. void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
  1464. {
  1465. this->Files.insert(files.begin(), files.end());
  1466. }