cmCTestSubmitHandler.cxx 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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. // Generate Done.xml right before it is submitted.
  418. // The reason for this is two-fold:
  419. // 1) It must be generated after some other part has been submitted
  420. // so we have a buildId to refer to in its contents.
  421. // 2) By generating Done.xml here its timestamp will be as late as
  422. // possible. This gives us a more accurate record of how long the
  423. // entire build took to complete.
  424. if (file == "Done.xml") {
  425. this->CTest->GenerateDoneFile();
  426. }
  427. if (!cmSystemTools::FileExists(local_file)) {
  428. cmCTestLog(this->CTest, ERROR_MESSAGE,
  429. " Cannot find file: " << local_file << std::endl);
  430. ::curl_easy_cleanup(curl);
  431. ::curl_slist_free_all(headers);
  432. ::curl_global_cleanup();
  433. return false;
  434. }
  435. unsigned long filelen = cmSystemTools::FileLength(local_file);
  436. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  437. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  438. " Upload file: " << local_file << " to "
  439. << upload_as << " Size: "
  440. << filelen << std::endl,
  441. this->Quiet);
  442. // specify target
  443. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  444. // CURLAUTH_BASIC is default, and here we allow additional methods,
  445. // including more secure ones
  446. ::curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  447. // now specify which file to upload
  448. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  449. // and give the size of the upload (optional)
  450. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  451. // and give curl the buffer for errors
  452. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  453. // specify handler for output
  454. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  455. cmCTestSubmitHandlerWriteMemoryCallback);
  456. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  457. cmCTestSubmitHandlerCurlDebugCallback);
  458. /* we pass our 'chunk' struct to the callback function */
  459. cmCTestSubmitHandlerVectorOfChar chunk;
  460. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  461. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  462. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  463. // Now run off and do what you've been told!
  464. res = ::curl_easy_perform(curl);
  465. if (!chunk.empty()) {
  466. cmCTestOptionalLog(this->CTest, DEBUG,
  467. "CURL output: ["
  468. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  469. << "]" << std::endl,
  470. this->Quiet);
  471. this->ParseResponse(chunk);
  472. }
  473. if (!chunkDebug.empty()) {
  474. cmCTestOptionalLog(
  475. this->CTest, DEBUG,
  476. "CURL debug output: ["
  477. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  478. << std::endl,
  479. this->Quiet);
  480. }
  481. // If curl failed for any reason, or checksum fails, wait and retry
  482. //
  483. if (res != CURLE_OK || this->HasErrors) {
  484. std::string retryDelay = this->GetOption("RetryDelay") == nullptr
  485. ? ""
  486. : this->GetOption("RetryDelay");
  487. std::string retryCount = this->GetOption("RetryCount") == nullptr
  488. ? ""
  489. : this->GetOption("RetryCount");
  490. auto delay = cmDuration(
  491. retryDelay.empty()
  492. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
  493. .c_str())
  494. : atoi(retryDelay.c_str()));
  495. int count = retryCount.empty()
  496. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
  497. .c_str())
  498. : atoi(retryCount.c_str());
  499. for (int i = 0; i < count; i++) {
  500. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  501. " Submit failed, waiting " << delay.count()
  502. << " seconds...\n",
  503. this->Quiet);
  504. auto stop = std::chrono::steady_clock::now() + delay;
  505. while (std::chrono::steady_clock::now() < stop) {
  506. cmSystemTools::Delay(100);
  507. }
  508. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  509. " Retry submission: Attempt "
  510. << (i + 1) << " of " << count << std::endl,
  511. this->Quiet);
  512. ::fclose(ftpfile);
  513. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  514. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  515. chunk.clear();
  516. chunkDebug.clear();
  517. this->HasErrors = false;
  518. res = ::curl_easy_perform(curl);
  519. if (!chunk.empty()) {
  520. cmCTestOptionalLog(
  521. this->CTest, DEBUG,
  522. "CURL output: ["
  523. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  524. << std::endl,
  525. this->Quiet);
  526. this->ParseResponse(chunk);
  527. }
  528. if (res == CURLE_OK && !this->HasErrors) {
  529. break;
  530. }
  531. }
  532. }
  533. fclose(ftpfile);
  534. if (res) {
  535. cmCTestLog(this->CTest, ERROR_MESSAGE,
  536. " Error when uploading file: " << local_file
  537. << std::endl);
  538. cmCTestLog(this->CTest, ERROR_MESSAGE,
  539. " Error message was: " << error_buffer << std::endl);
  540. *this->LogFile << " Error when uploading file: " << local_file
  541. << std::endl
  542. << " Error message was: " << error_buffer
  543. << std::endl;
  544. // avoid deref of begin for zero size array
  545. if (!chunk.empty()) {
  546. *this->LogFile << " Curl output was: "
  547. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  548. << std::endl;
  549. cmCTestLog(this->CTest, ERROR_MESSAGE,
  550. "CURL output: ["
  551. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  552. << std::endl);
  553. }
  554. ::curl_easy_cleanup(curl);
  555. ::curl_slist_free_all(headers);
  556. ::curl_global_cleanup();
  557. return false;
  558. }
  559. // always cleanup
  560. ::curl_easy_cleanup(curl);
  561. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  562. " Uploaded: " + local_file << std::endl,
  563. this->Quiet);
  564. }
  565. }
  566. ::curl_slist_free_all(headers);
  567. ::curl_global_cleanup();
  568. return true;
  569. }
  570. void cmCTestSubmitHandler::ParseResponse(
  571. cmCTestSubmitHandlerVectorOfChar chunk)
  572. {
  573. std::string output;
  574. output.append(chunk.begin(), chunk.end());
  575. if (output.find("<cdash") != std::string::npos) {
  576. ResponseParser parser;
  577. parser.Parse(output.c_str());
  578. if (parser.Status != ResponseParser::STATUS_OK) {
  579. this->HasErrors = true;
  580. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  581. " Submission failed: " << parser.Message << std::endl);
  582. return;
  583. }
  584. this->CTest->SetBuildID(parser.BuildID);
  585. }
  586. output = cmSystemTools::UpperCase(output);
  587. if (output.find("WARNING") != std::string::npos) {
  588. this->HasWarnings = true;
  589. }
  590. if (output.find("ERROR") != std::string::npos) {
  591. this->HasErrors = true;
  592. }
  593. if (this->HasWarnings || this->HasErrors) {
  594. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  595. " Server Response:\n"
  596. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
  597. }
  598. }
  599. bool cmCTestSubmitHandler::TriggerUsingHTTP(
  600. const std::vector<std::string>& files, const std::string& remoteprefix,
  601. const std::string& url)
  602. {
  603. CURL* curl;
  604. char error_buffer[1024];
  605. /* In windows, this will init the winsock stuff */
  606. ::curl_global_init(CURL_GLOBAL_ALL);
  607. for (std::string const& file : files) {
  608. /* get a curl handle */
  609. curl = curl_easy_init();
  610. if (curl) {
  611. // Using proxy
  612. if (this->HTTPProxyType > 0) {
  613. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  614. switch (this->HTTPProxyType) {
  615. case 2:
  616. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  617. break;
  618. case 3:
  619. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  620. break;
  621. default:
  622. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  623. if (!this->HTTPProxyAuth.empty()) {
  624. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  625. this->HTTPProxyAuth.c_str());
  626. }
  627. }
  628. }
  629. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  630. // and give curl the buffer for errors
  631. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  632. // specify handler for output
  633. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  634. cmCTestSubmitHandlerWriteMemoryCallback);
  635. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  636. cmCTestSubmitHandlerCurlDebugCallback);
  637. /* we pass our 'chunk' struct to the callback function */
  638. cmCTestSubmitHandlerVectorOfChar chunk;
  639. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  640. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  641. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  642. std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(file);
  643. std::string ofile;
  644. for (char c : rfile) {
  645. char hexCh[4] = { 0, 0, 0, 0 };
  646. hexCh[0] = c;
  647. switch (c) {
  648. case '+':
  649. case '?':
  650. case '/':
  651. case '\\':
  652. case '&':
  653. case ' ':
  654. case '=':
  655. case '%':
  656. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  657. ofile.append(hexCh);
  658. break;
  659. default:
  660. ofile.append(hexCh);
  661. }
  662. }
  663. std::string turl = url +
  664. ((url.find('?') == std::string::npos) ? '?' : '&') +
  665. "xmlfile=" + ofile;
  666. *this->LogFile << "Trigger url: " << turl << std::endl;
  667. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  668. " Trigger url: " << turl << std::endl, this->Quiet);
  669. curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  670. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  671. if (curl_easy_perform(curl)) {
  672. cmCTestLog(this->CTest, ERROR_MESSAGE,
  673. " Error when triggering: " << turl << std::endl);
  674. cmCTestLog(this->CTest, ERROR_MESSAGE,
  675. " Error message was: " << error_buffer << std::endl);
  676. *this->LogFile << "\tTriggering failed with error: " << error_buffer
  677. << std::endl
  678. << " Error message was: " << error_buffer
  679. << std::endl;
  680. if (!chunk.empty()) {
  681. *this->LogFile << " Curl output was: "
  682. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  683. << std::endl;
  684. cmCTestLog(this->CTest, ERROR_MESSAGE,
  685. "CURL output: ["
  686. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  687. << std::endl);
  688. }
  689. ::curl_easy_cleanup(curl);
  690. ::curl_global_cleanup();
  691. return false;
  692. }
  693. if (!chunk.empty()) {
  694. cmCTestOptionalLog(this->CTest, DEBUG,
  695. "CURL output: ["
  696. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  697. << "]" << std::endl,
  698. this->Quiet);
  699. }
  700. if (!chunkDebug.empty()) {
  701. cmCTestOptionalLog(
  702. this->CTest, DEBUG,
  703. "CURL debug output: ["
  704. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  705. << std::endl,
  706. this->Quiet);
  707. }
  708. // always cleanup
  709. ::curl_easy_cleanup(curl);
  710. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
  711. this->Quiet);
  712. }
  713. }
  714. ::curl_global_cleanup();
  715. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  716. " Dart server triggered..." << std::endl, this->Quiet);
  717. return true;
  718. }
  719. bool cmCTestSubmitHandler::SubmitUsingSCP(
  720. const std::string& scp_command, const std::string& localprefix,
  721. const std::vector<std::string>& files, const std::string& remoteprefix,
  722. const std::string& url)
  723. {
  724. if (scp_command.empty() || localprefix.empty() || files.empty() ||
  725. remoteprefix.empty() || url.empty()) {
  726. return false;
  727. }
  728. std::vector<const char*> argv;
  729. argv.push_back(scp_command.c_str()); // Scp command
  730. argv.push_back(scp_command.c_str()); // Dummy string for file
  731. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  732. argv.push_back(nullptr);
  733. cmsysProcess* cp = cmsysProcess_New();
  734. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  735. // cmsysProcess_SetTimeout(cp, timeout);
  736. int problems = 0;
  737. for (std::string const& file : files) {
  738. int retVal;
  739. std::string lfname = localprefix;
  740. cmSystemTools::ConvertToUnixSlashes(lfname);
  741. lfname += "/" + file;
  742. lfname = cmSystemTools::ConvertToOutputPath(lfname);
  743. argv[1] = lfname.c_str();
  744. std::string rfname = url + "/" + remoteprefix + file;
  745. argv[2] = rfname.c_str();
  746. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  747. "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  748. << argv[2] << "\"" << std::endl,
  749. this->Quiet);
  750. *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  751. << argv[2] << "\"" << std::endl;
  752. cmsysProcess_SetCommand(cp, &*argv.begin());
  753. cmsysProcess_Execute(cp);
  754. char* data;
  755. int length;
  756. cmProcessOutput processOutput;
  757. std::string strdata;
  758. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  759. processOutput.DecodeText(data, length, strdata);
  760. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  761. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  762. this->Quiet);
  763. }
  764. processOutput.DecodeText(std::string(), strdata);
  765. if (!strdata.empty()) {
  766. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  767. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  768. this->Quiet);
  769. }
  770. cmsysProcess_WaitForExit(cp, nullptr);
  771. int result = cmsysProcess_GetState(cp);
  772. if (result == cmsysProcess_State_Exited) {
  773. retVal = cmsysProcess_GetExitValue(cp);
  774. if (retVal != 0) {
  775. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  776. "\tSCP returned: " << retVal << std::endl,
  777. this->Quiet);
  778. *this->LogFile << "\tSCP returned: " << retVal << std::endl;
  779. problems++;
  780. }
  781. } else if (result == cmsysProcess_State_Exception) {
  782. retVal = cmsysProcess_GetExitException(cp);
  783. cmCTestLog(this->CTest, ERROR_MESSAGE,
  784. "\tThere was an exception: " << retVal << std::endl);
  785. *this->LogFile << "\tThere was an exception: " << retVal << std::endl;
  786. problems++;
  787. } else if (result == cmsysProcess_State_Expired) {
  788. cmCTestLog(this->CTest, ERROR_MESSAGE,
  789. "\tThere was a timeout" << std::endl);
  790. *this->LogFile << "\tThere was a timeout" << std::endl;
  791. problems++;
  792. } else if (result == cmsysProcess_State_Error) {
  793. cmCTestLog(this->CTest, ERROR_MESSAGE,
  794. "\tError executing SCP: " << cmsysProcess_GetErrorString(cp)
  795. << std::endl);
  796. *this->LogFile << "\tError executing SCP: "
  797. << cmsysProcess_GetErrorString(cp) << std::endl;
  798. problems++;
  799. }
  800. }
  801. cmsysProcess_Delete(cp);
  802. return problems == 0;
  803. }
  804. bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
  805. const std::vector<std::string>& files,
  806. const std::string& remoteprefix,
  807. const std::string& destination)
  808. {
  809. if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
  810. destination.empty()) {
  811. /* clang-format off */
  812. cmCTestLog(this->CTest, ERROR_MESSAGE,
  813. "Missing arguments for submit via cp:\n"
  814. << "\tlocalprefix: " << localprefix << "\n"
  815. << "\tNumber of files: " << files.size() << "\n"
  816. << "\tremoteprefix: " << remoteprefix << "\n"
  817. << "\tdestination: " << destination << std::endl);
  818. /* clang-format on */
  819. return false;
  820. }
  821. for (std::string const& file : files) {
  822. std::string lfname = localprefix;
  823. cmSystemTools::ConvertToUnixSlashes(lfname);
  824. lfname += "/" + file;
  825. std::string rfname = destination + "/" + remoteprefix + file;
  826. cmSystemTools::CopyFileAlways(lfname, rfname);
  827. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  828. " Copy file: " << lfname << " to " << rfname
  829. << std::endl,
  830. this->Quiet);
  831. }
  832. std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
  833. cmSystemTools::Touch(tagDoneFile, true);
  834. return true;
  835. }
  836. #if defined(CTEST_USE_XMLRPC)
  837. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  838. const std::string& localprefix, const std::vector<std::string>& files,
  839. const std::string& remoteprefix, const std::string& url)
  840. {
  841. xmlrpc_env env;
  842. char ctestString[] = "CTest";
  843. std::string ctestVersionString = cmVersion::GetCMakeVersion();
  844. char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
  845. std::string realURL = url + "/" + remoteprefix + "/Command/";
  846. /* Start up our XML-RPC client library. */
  847. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
  848. /* Initialize our error-handling environment. */
  849. xmlrpc_env_init(&env);
  850. /* Call the famous server at UserLand. */
  851. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  852. " Submitting to: " << realURL << " (" << remoteprefix
  853. << ")" << std::endl,
  854. this->Quiet);
  855. for (std::string const& file : files) {
  856. xmlrpc_value* result;
  857. std::string local_file = file;
  858. if (!cmSystemTools::FileExists(local_file)) {
  859. local_file = localprefix + "/" + file;
  860. }
  861. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  862. " Submit file: " << local_file << std::endl,
  863. this->Quiet);
  864. struct stat st;
  865. if (::stat(local_file.c_str(), &st)) {
  866. cmCTestLog(this->CTest, ERROR_MESSAGE,
  867. " Cannot find file: " << local_file << std::endl);
  868. return false;
  869. }
  870. // off_t can be bigger than size_t. fread takes size_t.
  871. // make sure the file is not too big.
  872. if (static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
  873. static_cast<off_t>(st.st_size)) {
  874. cmCTestLog(this->CTest, ERROR_MESSAGE,
  875. " File too big: " << local_file << std::endl);
  876. return false;
  877. }
  878. size_t fileSize = static_cast<size_t>(st.st_size);
  879. FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
  880. if (!fp) {
  881. cmCTestLog(this->CTest, ERROR_MESSAGE,
  882. " Cannot open file: " << local_file << std::endl);
  883. return false;
  884. }
  885. unsigned char* fileBuffer = new unsigned char[fileSize];
  886. if (fread(fileBuffer, 1, fileSize, fp) != fileSize) {
  887. delete[] fileBuffer;
  888. fclose(fp);
  889. cmCTestLog(this->CTest, ERROR_MESSAGE,
  890. " Cannot read file: " << local_file << std::endl);
  891. return false;
  892. }
  893. fclose(fp);
  894. char remoteCommand[] = "Submit.put";
  895. char* pRealURL = const_cast<char*>(realURL.c_str());
  896. result =
  897. xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer,
  898. static_cast<xmlrpc_int32>(fileSize));
  899. delete[] fileBuffer;
  900. if (env.fault_occurred) {
  901. cmCTestLog(this->CTest, ERROR_MESSAGE,
  902. " Submission problem: " << env.fault_string << " ("
  903. << env.fault_code << ")"
  904. << std::endl);
  905. xmlrpc_env_clean(&env);
  906. xmlrpc_client_cleanup();
  907. return false;
  908. }
  909. /* Dispose of our result value. */
  910. xmlrpc_DECREF(result);
  911. }
  912. /* Clean up our error-handling environment. */
  913. xmlrpc_env_clean(&env);
  914. /* Shutdown our XML-RPC client library. */
  915. xmlrpc_client_cleanup();
  916. return true;
  917. }
  918. #else
  919. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  920. std::string const& /*unused*/, std::vector<std::string> const& /*unused*/,
  921. std::string const& /*unused*/, std::string const& /*unused*/)
  922. {
  923. return false;
  924. }
  925. #endif
  926. void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
  927. std::string& url)
  928. {
  929. dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
  930. url = dropMethod;
  931. url += "://";
  932. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  933. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  934. cmCTestOptionalLog(
  935. this->CTest, HANDLER_OUTPUT,
  936. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
  937. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  938. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  939. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
  940. }
  941. url += "@";
  942. }
  943. url += this->CTest->GetCTestConfiguration("DropSite") +
  944. this->CTest->GetCTestConfiguration("DropLocation");
  945. }
  946. int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
  947. std::string const& typeString)
  948. {
  949. if (file.empty()) {
  950. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not specified\n");
  951. return -1;
  952. }
  953. if (!cmSystemTools::FileExists(file)) {
  954. cmCTestLog(this->CTest, ERROR_MESSAGE,
  955. "Upload file not found: '" << file << "'\n");
  956. return -1;
  957. }
  958. cmCTestCurl curl(this->CTest);
  959. curl.SetQuiet(this->Quiet);
  960. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  961. std::vector<std::string> args;
  962. cmSystemTools::ExpandListArgument(curlopt, args);
  963. curl.SetCurlOptions(args);
  964. curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  965. curl.SetHttpHeaders(this->HttpHeaders);
  966. std::string dropMethod;
  967. std::string url;
  968. this->ConstructCDashURL(dropMethod, url);
  969. std::string fields;
  970. std::string::size_type pos = url.find('?');
  971. if (pos != std::string::npos) {
  972. fields = url.substr(pos + 1);
  973. url = url.substr(0, pos);
  974. }
  975. if (!(dropMethod == "http" || dropMethod == "https")) {
  976. cmCTestLog(this->CTest, ERROR_MESSAGE,
  977. "Only http and https are supported for CDASH_UPLOAD\n");
  978. return -1;
  979. }
  980. bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
  981. // Get RETRY_COUNT and RETRY_DELAY values if they were set.
  982. std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
  983. ? ""
  984. : this->GetOption("RetryDelay");
  985. std::string retryCountString = this->GetOption("RetryCount") == nullptr
  986. ? ""
  987. : this->GetOption("RetryCount");
  988. auto retryDelay = std::chrono::seconds(0);
  989. if (!retryDelayString.empty()) {
  990. unsigned long retryDelayValue = 0;
  991. if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
  992. &retryDelayValue)) {
  993. cmCTestLog(this->CTest, WARNING,
  994. "Invalid value for 'RETRY_DELAY' : " << retryDelayString
  995. << std::endl);
  996. } else {
  997. retryDelay = std::chrono::seconds(retryDelayValue);
  998. }
  999. }
  1000. unsigned long retryCount = 0;
  1001. if (!retryCountString.empty()) {
  1002. if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
  1003. cmCTestLog(this->CTest, WARNING,
  1004. "Invalid value for 'RETRY_DELAY' : " << retryCountString
  1005. << std::endl);
  1006. }
  1007. }
  1008. std::string md5sum =
  1009. cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
  1010. // 1. request the buildid and check to see if the file
  1011. // has already been uploaded
  1012. // TODO I added support for subproject. You would need to add
  1013. // a "&subproject=subprojectname" to the first POST.
  1014. cmCTestScriptHandler* ch =
  1015. static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
  1016. cmake* cm = ch->GetCMake();
  1017. const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
  1018. // TODO: Encode values for a URL instead of trusting caller.
  1019. std::ostringstream str;
  1020. if (subproject) {
  1021. str << "subproject=" << curl.Escape(subproject) << "&";
  1022. }
  1023. auto timeNow =
  1024. std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  1025. str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
  1026. << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1027. << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1028. << "build="
  1029. << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
  1030. << "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
  1031. << "&"
  1032. << "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  1033. << "starttime=" << timeNow << "&"
  1034. << "endtime=" << timeNow << "&"
  1035. << "datafilesmd5[0]=" << md5sum << "&"
  1036. << "type=" << curl.Escape(typeString);
  1037. if (!fields.empty()) {
  1038. fields += '&';
  1039. }
  1040. fields += str.str();
  1041. cmCTestOptionalLog(this->CTest, DEBUG,
  1042. "fields: " << fields << "\nurl:" << url
  1043. << "\nfile: " << file << "\n",
  1044. this->Quiet);
  1045. std::string response;
  1046. bool requestSucceeded = curl.HttpRequest(url, fields, response);
  1047. if (!internalTest && !requestSucceeded) {
  1048. // If request failed, wait and retry.
  1049. for (unsigned long i = 0; i < retryCount; i++) {
  1050. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1051. " Request failed, waiting " << retryDelay.count()
  1052. << " seconds...\n",
  1053. this->Quiet);
  1054. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1055. while (std::chrono::steady_clock::now() < stop) {
  1056. cmSystemTools::Delay(100);
  1057. }
  1058. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1059. " Retry request: Attempt "
  1060. << (i + 1) << " of " << retryCount << std::endl,
  1061. this->Quiet);
  1062. requestSucceeded = curl.HttpRequest(url, fields, response);
  1063. if (requestSucceeded) {
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. if (!internalTest && !requestSucceeded) {
  1069. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1070. "Error in HttpRequest\n"
  1071. << response);
  1072. return -1;
  1073. }
  1074. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1075. "Request upload response: [" << response << "]\n",
  1076. this->Quiet);
  1077. Json::Value json;
  1078. Json::Reader reader;
  1079. if (!internalTest && !reader.parse(response, json)) {
  1080. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1081. "error parsing json string ["
  1082. << response << "]\n"
  1083. << reader.getFormattedErrorMessages() << "\n");
  1084. return -1;
  1085. }
  1086. if (!internalTest && json["status"].asInt() != 0) {
  1087. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1088. "Bad status returned from CDash: " << json["status"].asInt());
  1089. return -1;
  1090. }
  1091. if (!internalTest) {
  1092. if (json["datafilesmd5"].isArray()) {
  1093. int datares = json["datafilesmd5"][0].asInt();
  1094. if (datares == 1) {
  1095. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1096. "File already exists on CDash, skip upload "
  1097. << file << "\n",
  1098. this->Quiet);
  1099. return 0;
  1100. }
  1101. } else {
  1102. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1103. "bad datafilesmd5 value in response " << response << "\n");
  1104. return -1;
  1105. }
  1106. }
  1107. std::string upload_as = cmSystemTools::GetFilenameName(file);
  1108. std::ostringstream fstr;
  1109. fstr << "type=" << curl.Escape(typeString) << "&"
  1110. << "md5=" << md5sum << "&"
  1111. << "filename=" << curl.Escape(upload_as) << "&"
  1112. << "buildid=" << json["buildid"].asString();
  1113. bool uploadSucceeded = false;
  1114. if (!internalTest) {
  1115. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1116. }
  1117. if (!uploadSucceeded) {
  1118. // If upload failed, wait and retry.
  1119. for (unsigned long i = 0; i < retryCount; i++) {
  1120. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1121. " Upload failed, waiting " << retryDelay.count()
  1122. << " seconds...\n",
  1123. this->Quiet);
  1124. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1125. while (std::chrono::steady_clock::now() < stop) {
  1126. cmSystemTools::Delay(100);
  1127. }
  1128. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1129. " Retry upload: Attempt "
  1130. << (i + 1) << " of " << retryCount << std::endl,
  1131. this->Quiet);
  1132. if (!internalTest) {
  1133. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1134. }
  1135. if (uploadSucceeded) {
  1136. break;
  1137. }
  1138. }
  1139. }
  1140. if (!uploadSucceeded) {
  1141. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1142. "error uploading to CDash. " << file << " " << url << " "
  1143. << fstr.str());
  1144. return -1;
  1145. }
  1146. if (!reader.parse(response, json)) {
  1147. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1148. "error parsing json string ["
  1149. << response << "]\n"
  1150. << reader.getFormattedErrorMessages() << "\n");
  1151. return -1;
  1152. }
  1153. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1154. "Upload file response: [" << response << "]\n",
  1155. this->Quiet);
  1156. return 0;
  1157. }
  1158. int cmCTestSubmitHandler::ProcessHandler()
  1159. {
  1160. const char* cdashUploadFile = this->GetOption("CDashUploadFile");
  1161. const char* cdashUploadType = this->GetOption("CDashUploadType");
  1162. if (cdashUploadFile && cdashUploadType) {
  1163. return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
  1164. }
  1165. std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
  1166. // cdash does not need to trigger so just return true
  1167. if (!iscdash.empty()) {
  1168. this->CDash = true;
  1169. }
  1170. const std::string& buildDirectory =
  1171. this->CTest->GetCTestConfiguration("BuildDirectory");
  1172. if (buildDirectory.empty()) {
  1173. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1174. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  1175. << std::endl);
  1176. return -1;
  1177. }
  1178. if (getenv("HTTP_PROXY")) {
  1179. this->HTTPProxyType = 1;
  1180. this->HTTPProxy = getenv("HTTP_PROXY");
  1181. if (getenv("HTTP_PROXY_PORT")) {
  1182. this->HTTPProxy += ":";
  1183. this->HTTPProxy += getenv("HTTP_PROXY_PORT");
  1184. }
  1185. if (getenv("HTTP_PROXY_TYPE")) {
  1186. std::string type = getenv("HTTP_PROXY_TYPE");
  1187. // HTTP/SOCKS4/SOCKS5
  1188. if (type == "HTTP") {
  1189. this->HTTPProxyType = 1;
  1190. } else if (type == "SOCKS4") {
  1191. this->HTTPProxyType = 2;
  1192. } else if (type == "SOCKS5") {
  1193. this->HTTPProxyType = 3;
  1194. }
  1195. }
  1196. if (getenv("HTTP_PROXY_USER")) {
  1197. this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  1198. }
  1199. if (getenv("HTTP_PROXY_PASSWD")) {
  1200. this->HTTPProxyAuth += ":";
  1201. this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  1202. }
  1203. }
  1204. if (getenv("FTP_PROXY")) {
  1205. this->FTPProxyType = 1;
  1206. this->FTPProxy = getenv("FTP_PROXY");
  1207. if (getenv("FTP_PROXY_PORT")) {
  1208. this->FTPProxy += ":";
  1209. this->FTPProxy += getenv("FTP_PROXY_PORT");
  1210. }
  1211. if (getenv("FTP_PROXY_TYPE")) {
  1212. std::string type = getenv("FTP_PROXY_TYPE");
  1213. // HTTP/SOCKS4/SOCKS5
  1214. if (type == "HTTP") {
  1215. this->FTPProxyType = 1;
  1216. } else if (type == "SOCKS4") {
  1217. this->FTPProxyType = 2;
  1218. } else if (type == "SOCKS5") {
  1219. this->FTPProxyType = 3;
  1220. }
  1221. }
  1222. }
  1223. if (!this->HTTPProxy.empty()) {
  1224. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1225. " Use HTTP Proxy: " << this->HTTPProxy << std::endl,
  1226. this->Quiet);
  1227. }
  1228. if (!this->FTPProxy.empty()) {
  1229. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1230. " Use FTP Proxy: " << this->FTPProxy << std::endl,
  1231. this->Quiet);
  1232. }
  1233. cmGeneratedFileStream ofs;
  1234. this->StartLogFile("Submit", ofs);
  1235. std::vector<std::string> files;
  1236. std::string prefix = this->GetSubmitResultsPrefix();
  1237. if (!this->Files.empty()) {
  1238. // Submit the explicitly selected files:
  1239. //
  1240. files.insert(files.end(), this->Files.begin(), this->Files.end());
  1241. }
  1242. // Add to the list of files to submit from any selected, existing parts:
  1243. //
  1244. // TODO:
  1245. // Check if test is enabled
  1246. this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
  1247. this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
  1248. this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
  1249. this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
  1250. if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
  1251. std::vector<std::string> gfiles;
  1252. std::string gpath =
  1253. buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
  1254. std::string::size_type glen = gpath.size() + 1;
  1255. gpath = gpath + "/CoverageLog*";
  1256. cmCTestOptionalLog(this->CTest, DEBUG,
  1257. "Globbing for: " << gpath << std::endl, this->Quiet);
  1258. if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
  1259. for (std::string& gfile : gfiles) {
  1260. gfile = gfile.substr(glen);
  1261. cmCTestOptionalLog(this->CTest, DEBUG,
  1262. "Glob file: " << gfile << std::endl, this->Quiet);
  1263. this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
  1264. }
  1265. } else {
  1266. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
  1267. }
  1268. }
  1269. this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
  1270. this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
  1271. this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
  1272. this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
  1273. // Query parts for files to submit.
  1274. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1275. p = cmCTest::Part(p + 1)) {
  1276. // Skip parts we are not submitting.
  1277. if (!this->SubmitPart[p]) {
  1278. continue;
  1279. }
  1280. // Submit files from this part.
  1281. std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
  1282. files.insert(files.end(), pfiles.begin(), pfiles.end());
  1283. }
  1284. // Make sure files are unique, but preserve order.
  1285. {
  1286. // This endPos intermediate is needed to work around non-conformant C++11
  1287. // standard libraries that have erase(iterator,iterator) instead of
  1288. // erase(const_iterator,const_iterator).
  1289. size_t endPos = cmRemoveDuplicates(files) - files.cbegin();
  1290. files.erase(files.begin() + endPos, files.end());
  1291. }
  1292. // Submit Done.xml last
  1293. if (this->SubmitPart[cmCTest::PartDone]) {
  1294. files.push_back("Done.xml");
  1295. }
  1296. if (ofs) {
  1297. ofs << "Upload files:" << std::endl;
  1298. int cnt = 0;
  1299. for (std::string const& file : files) {
  1300. ofs << cnt << "\t" << file << std::endl;
  1301. cnt++;
  1302. }
  1303. }
  1304. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1305. "Submit files (using "
  1306. << this->CTest->GetCTestConfiguration("DropMethod")
  1307. << ")" << std::endl,
  1308. this->Quiet);
  1309. const char* specificTrack = this->CTest->GetSpecificTrack();
  1310. if (specificTrack) {
  1311. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1312. " Send to track: " << specificTrack << std::endl,
  1313. this->Quiet);
  1314. }
  1315. this->SetLogFile(&ofs);
  1316. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  1317. if (dropMethod.empty() || dropMethod == "ftp") {
  1318. ofs << "Using drop method: FTP" << std::endl;
  1319. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1320. " Using FTP submit method" << std::endl
  1321. << " Drop site: ftp://",
  1322. this->Quiet);
  1323. std::string url = "ftp://";
  1324. url += cmCTest::MakeURLSafe(
  1325. this->CTest->GetCTestConfiguration("DropSiteUser")) +
  1326. ":" +
  1327. cmCTest::MakeURLSafe(
  1328. this->CTest->GetCTestConfiguration("DropSitePassword")) +
  1329. "@" + this->CTest->GetCTestConfiguration("DropSite") +
  1330. cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
  1331. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1332. cmCTestOptionalLog(
  1333. this->CTest, HANDLER_OUTPUT,
  1334. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1335. this->Quiet);
  1336. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1337. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1338. this->Quiet);
  1339. }
  1340. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1341. }
  1342. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1343. this->CTest->GetCTestConfiguration("DropSite")
  1344. << this->CTest->GetCTestConfiguration("DropLocation")
  1345. << std::endl,
  1346. this->Quiet);
  1347. if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
  1348. this->CTest->GetCurrentTag(),
  1349. files, prefix, url)) {
  1350. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1351. " Problems when submitting via FTP" << std::endl);
  1352. ofs << " Problems when submitting via FTP" << std::endl;
  1353. return -1;
  1354. }
  1355. if (!this->CDash) {
  1356. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1357. " Using HTTP trigger method"
  1358. << std::endl
  1359. << " Trigger site: "
  1360. << this->CTest->GetCTestConfiguration("TriggerSite")
  1361. << std::endl,
  1362. this->Quiet);
  1363. if (!this->TriggerUsingHTTP(
  1364. files, prefix,
  1365. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1366. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1367. " Problems when triggering via HTTP" << std::endl);
  1368. ofs << " Problems when triggering via HTTP" << 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. }
  1376. } else if (dropMethod == "http" || dropMethod == "https") {
  1377. std::string url = dropMethod;
  1378. url += "://";
  1379. ofs << "Using drop method: " << dropMethod << std::endl;
  1380. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1381. " Using HTTP submit method" << std::endl
  1382. << " Drop site:" << url,
  1383. this->Quiet);
  1384. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1385. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  1386. cmCTestOptionalLog(
  1387. this->CTest, HANDLER_OUTPUT,
  1388. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1389. this->Quiet);
  1390. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1391. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  1392. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1393. this->Quiet);
  1394. }
  1395. url += "@";
  1396. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1397. }
  1398. url += this->CTest->GetCTestConfiguration("DropSite") +
  1399. this->CTest->GetCTestConfiguration("DropLocation");
  1400. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1401. this->CTest->GetCTestConfiguration("DropSite")
  1402. << this->CTest->GetCTestConfiguration("DropLocation")
  1403. << std::endl,
  1404. this->Quiet);
  1405. if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
  1406. this->CTest->GetCurrentTag(),
  1407. files, prefix, url)) {
  1408. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1409. " Problems when submitting via HTTP" << std::endl);
  1410. ofs << " Problems when submitting via HTTP" << std::endl;
  1411. return -1;
  1412. }
  1413. if (!this->CDash) {
  1414. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1415. " Using HTTP trigger method"
  1416. << std::endl
  1417. << " Trigger site: "
  1418. << this->CTest->GetCTestConfiguration("TriggerSite")
  1419. << std::endl,
  1420. this->Quiet);
  1421. if (!this->TriggerUsingHTTP(
  1422. files, prefix,
  1423. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1424. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1425. " Problems when triggering via HTTP" << std::endl);
  1426. ofs << " Problems when triggering via HTTP" << std::endl;
  1427. return -1;
  1428. }
  1429. }
  1430. if (this->HasErrors) {
  1431. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  1432. " Errors occurred during "
  1433. "submission."
  1434. << std::endl);
  1435. ofs << " Errors occurred during submission. " << std::endl;
  1436. } else {
  1437. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1438. " Submission successful"
  1439. << (this->HasWarnings ? ", with warnings." : "")
  1440. << std::endl,
  1441. this->Quiet);
  1442. ofs << " Submission successful"
  1443. << (this->HasWarnings ? ", with warnings." : "") << std::endl;
  1444. }
  1445. return 0;
  1446. } else if (dropMethod == "xmlrpc") {
  1447. #if defined(CTEST_USE_XMLRPC)
  1448. ofs << "Using drop method: XML-RPC" << std::endl;
  1449. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1450. " Using XML-RPC submit method" << std::endl,
  1451. this->Quiet);
  1452. std::string url = this->CTest->GetCTestConfiguration("DropSite");
  1453. prefix = this->CTest->GetCTestConfiguration("DropLocation");
  1454. if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
  1455. this->CTest->GetCurrentTag(),
  1456. files, prefix, url)) {
  1457. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1458. " Problems when submitting via XML-RPC" << std::endl);
  1459. ofs << " Problems when submitting via XML-RPC" << std::endl;
  1460. return -1;
  1461. }
  1462. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1463. " Submission successful" << std::endl, this->Quiet);
  1464. ofs << " Submission successful" << std::endl;
  1465. return 0;
  1466. #else
  1467. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1468. " Submission method \"xmlrpc\" not compiled into CTest!"
  1469. << std::endl);
  1470. return -1;
  1471. #endif
  1472. } else if (dropMethod == "scp") {
  1473. std::string url;
  1474. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1475. url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
  1476. }
  1477. url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
  1478. this->CTest->GetCTestConfiguration("DropLocation");
  1479. // change to the build directory so that we can uses a relative path
  1480. // on windows since scp doesn't support "c:" a drive in the path
  1481. cmWorkingDirectory workdir(buildDirectory);
  1482. if (workdir.Failed()) {
  1483. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1484. " Failed to change directory to "
  1485. << buildDirectory << " : "
  1486. << std::strerror(workdir.GetLastResult()) << std::endl);
  1487. ofs << " Failed to change directory to " << buildDirectory << " : "
  1488. << std::strerror(workdir.GetLastResult()) << std::endl;
  1489. return -1;
  1490. }
  1491. if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
  1492. "Testing/" + this->CTest->GetCurrentTag(), files,
  1493. prefix, url)) {
  1494. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1495. " Problems when submitting via SCP" << std::endl);
  1496. ofs << " Problems when submitting via SCP" << std::endl;
  1497. return -1;
  1498. }
  1499. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1500. " Submission successful" << std::endl, this->Quiet);
  1501. ofs << " Submission successful" << std::endl;
  1502. return 0;
  1503. } else if (dropMethod == "cp") {
  1504. std::string location = this->CTest->GetCTestConfiguration("DropLocation");
  1505. // change to the build directory so that we can uses a relative path
  1506. // on windows since scp doesn't support "c:" a drive in the path
  1507. cmWorkingDirectory workdir(buildDirectory);
  1508. if (workdir.Failed()) {
  1509. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1510. " Failed to change directory to "
  1511. << buildDirectory << " : "
  1512. << std::strerror(workdir.GetLastResult()) << std::endl);
  1513. ofs << " Failed to change directory to " << buildDirectory << " : "
  1514. << std::strerror(workdir.GetLastResult()) << std::endl;
  1515. return -1;
  1516. }
  1517. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1518. " Change directory: " << buildDirectory << std::endl,
  1519. this->Quiet);
  1520. if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
  1521. prefix, location)) {
  1522. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1523. " Problems when submitting via CP" << std::endl);
  1524. ofs << " Problems when submitting via cp" << std::endl;
  1525. return -1;
  1526. }
  1527. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1528. " Submission successful" << std::endl, this->Quiet);
  1529. ofs << " Submission successful" << std::endl;
  1530. return 0;
  1531. }
  1532. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1533. " Unknown submission method: \"" << dropMethod << "\""
  1534. << std::endl);
  1535. return -1;
  1536. }
  1537. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  1538. {
  1539. std::string buildname =
  1540. cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
  1541. std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
  1542. buildname + "___" + this->CTest->GetCurrentTag() + "-" +
  1543. this->CTest->GetTestModelString() + "___XML___";
  1544. return name;
  1545. }
  1546. void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
  1547. {
  1548. // Check whether each part is selected.
  1549. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1550. p = cmCTest::Part(p + 1)) {
  1551. this->SubmitPart[p] =
  1552. (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
  1553. }
  1554. }
  1555. void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
  1556. {
  1557. this->Files.insert(files.begin(), files.end());
  1558. }