cmCTestSubmitHandler.cxx 61 KB

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