cmCTestSubmitHandler.cxx 61 KB

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