cmCTestLaunch.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestLaunch.h"
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmSystemTools.h"
  13. #include "cmXMLWriter.h"
  14. #include "cmake.h"
  15. #include <cmsys/MD5.h>
  16. #include <cmsys/Process.h>
  17. #include <cmsys/RegularExpression.hxx>
  18. #include <cmsys/FStream.hxx>
  19. #ifdef _WIN32
  20. #include <io.h> // for _setmode
  21. #include <fcntl.h> // for _O_BINARY
  22. #include <stdio.h> // for std{out,err} and fileno
  23. #endif
  24. //----------------------------------------------------------------------------
  25. cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv)
  26. {
  27. this->Passthru = true;
  28. this->Process = 0;
  29. this->ExitCode = 1;
  30. this->CWD = cmSystemTools::GetCurrentWorkingDirectory();
  31. if(!this->ParseArguments(argc, argv))
  32. {
  33. return;
  34. }
  35. this->ComputeFileNames();
  36. this->ScrapeRulesLoaded = false;
  37. this->HaveOut = false;
  38. this->HaveErr = false;
  39. this->Process = cmsysProcess_New();
  40. }
  41. //----------------------------------------------------------------------------
  42. cmCTestLaunch::~cmCTestLaunch()
  43. {
  44. cmsysProcess_Delete(this->Process);
  45. if(!this->Passthru)
  46. {
  47. cmSystemTools::RemoveFile(this->LogOut);
  48. cmSystemTools::RemoveFile(this->LogErr);
  49. }
  50. }
  51. //----------------------------------------------------------------------------
  52. bool cmCTestLaunch::ParseArguments(int argc, const char* const* argv)
  53. {
  54. // Launcher options occur first and are separated from the real
  55. // command line by a '--' option.
  56. enum Doing { DoingNone,
  57. DoingOutput,
  58. DoingSource,
  59. DoingLanguage,
  60. DoingTargetName,
  61. DoingTargetType,
  62. DoingBuildDir,
  63. DoingCount,
  64. DoingFilterPrefix };
  65. Doing doing = DoingNone;
  66. int arg0 = 0;
  67. for(int i=1; !arg0 && i < argc; ++i)
  68. {
  69. const char* arg = argv[i];
  70. if(strcmp(arg, "--") == 0)
  71. {
  72. arg0 = i+1;
  73. }
  74. else if(strcmp(arg, "--output") == 0)
  75. {
  76. doing = DoingOutput;
  77. }
  78. else if(strcmp(arg, "--source") == 0)
  79. {
  80. doing = DoingSource;
  81. }
  82. else if(strcmp(arg, "--language") == 0)
  83. {
  84. doing = DoingLanguage;
  85. }
  86. else if(strcmp(arg, "--target-name") == 0)
  87. {
  88. doing = DoingTargetName;
  89. }
  90. else if(strcmp(arg, "--target-type") == 0)
  91. {
  92. doing = DoingTargetType;
  93. }
  94. else if(strcmp(arg, "--build-dir") == 0)
  95. {
  96. doing = DoingBuildDir;
  97. }
  98. else if(strcmp(arg, "--filter-prefix") == 0)
  99. {
  100. doing = DoingFilterPrefix;
  101. }
  102. else if(doing == DoingOutput)
  103. {
  104. this->OptionOutput = arg;
  105. doing = DoingNone;
  106. }
  107. else if(doing == DoingSource)
  108. {
  109. this->OptionSource = arg;
  110. doing = DoingNone;
  111. }
  112. else if(doing == DoingLanguage)
  113. {
  114. this->OptionLanguage = arg;
  115. if(this->OptionLanguage == "CXX")
  116. {
  117. this->OptionLanguage = "C++";
  118. }
  119. doing = DoingNone;
  120. }
  121. else if(doing == DoingTargetName)
  122. {
  123. this->OptionTargetName = arg;
  124. doing = DoingNone;
  125. }
  126. else if(doing == DoingTargetType)
  127. {
  128. this->OptionTargetType = arg;
  129. doing = DoingNone;
  130. }
  131. else if(doing == DoingBuildDir)
  132. {
  133. this->OptionBuildDir = arg;
  134. doing = DoingNone;
  135. }
  136. else if(doing == DoingFilterPrefix)
  137. {
  138. this->OptionFilterPrefix = arg;
  139. doing = DoingNone;
  140. }
  141. }
  142. // Extract the real command line.
  143. if(arg0)
  144. {
  145. this->RealArgC = argc - arg0;
  146. this->RealArgV = argv + arg0;
  147. for(int i=0; i < this->RealArgC; ++i)
  148. {
  149. this->HandleRealArg(this->RealArgV[i]);
  150. }
  151. return true;
  152. }
  153. else
  154. {
  155. this->RealArgC = 0;
  156. this->RealArgV = 0;
  157. std::cerr << "No launch/command separator ('--') found!\n";
  158. return false;
  159. }
  160. }
  161. //----------------------------------------------------------------------------
  162. void cmCTestLaunch::HandleRealArg(const char* arg)
  163. {
  164. #ifdef _WIN32
  165. // Expand response file arguments.
  166. if(arg[0] == '@' && cmSystemTools::FileExists(arg+1))
  167. {
  168. cmsys::ifstream fin(arg+1);
  169. std::string line;
  170. while(cmSystemTools::GetLineFromStream(fin, line))
  171. {
  172. cmSystemTools::ParseWindowsCommandLine(line.c_str(), this->RealArgs);
  173. }
  174. return;
  175. }
  176. #endif
  177. this->RealArgs.push_back(arg);
  178. }
  179. //----------------------------------------------------------------------------
  180. void cmCTestLaunch::ComputeFileNames()
  181. {
  182. // We just passthru the behavior of the real command unless the
  183. // CTEST_LAUNCH_LOGS environment variable is set.
  184. const char* d = getenv("CTEST_LAUNCH_LOGS");
  185. if(!(d && *d))
  186. {
  187. return;
  188. }
  189. this->Passthru = false;
  190. // The environment variable specifies the directory into which we
  191. // generate build logs.
  192. this->LogDir = d;
  193. cmSystemTools::ConvertToUnixSlashes(this->LogDir);
  194. this->LogDir += "/";
  195. // We hash the input command working dir and command line to obtain
  196. // a repeatable and (probably) unique name for log files.
  197. char hash[32];
  198. cmsysMD5* md5 = cmsysMD5_New();
  199. cmsysMD5_Initialize(md5);
  200. cmsysMD5_Append(md5, (unsigned char const*)(this->CWD.c_str()), -1);
  201. for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
  202. ai != this->RealArgs.end(); ++ai)
  203. {
  204. cmsysMD5_Append(md5, (unsigned char const*)ai->c_str(), -1);
  205. }
  206. cmsysMD5_FinalizeHex(md5, hash);
  207. cmsysMD5_Delete(md5);
  208. this->LogHash.assign(hash, 32);
  209. // We store stdout and stderr in temporary log files.
  210. this->LogOut = this->LogDir;
  211. this->LogOut += "launch-";
  212. this->LogOut += this->LogHash;
  213. this->LogOut += "-out.txt";
  214. this->LogErr = this->LogDir;
  215. this->LogErr += "launch-";
  216. this->LogErr += this->LogHash;
  217. this->LogErr += "-err.txt";
  218. }
  219. //----------------------------------------------------------------------------
  220. void cmCTestLaunch::RunChild()
  221. {
  222. // Ignore noopt make rules
  223. if(this->RealArgs.empty() || this->RealArgs[0] == ":")
  224. {
  225. this->ExitCode = 0;
  226. return;
  227. }
  228. // Prepare to run the real command.
  229. cmsysProcess* cp = this->Process;
  230. cmsysProcess_SetCommand(cp, this->RealArgV);
  231. cmsys::ofstream fout;
  232. cmsys::ofstream ferr;
  233. if(this->Passthru)
  234. {
  235. // In passthru mode we just share the output pipes.
  236. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
  237. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
  238. }
  239. else
  240. {
  241. // In full mode we record the child output pipes to log files.
  242. fout.open(this->LogOut.c_str(),
  243. std::ios::out | std::ios::binary);
  244. ferr.open(this->LogErr.c_str(),
  245. std::ios::out | std::ios::binary);
  246. }
  247. #ifdef _WIN32
  248. // Do this so that newline transformation is not done when writing to cout
  249. // and cerr below.
  250. _setmode(fileno(stdout), _O_BINARY);
  251. _setmode(fileno(stderr), _O_BINARY);
  252. #endif
  253. // Run the real command.
  254. cmsysProcess_Execute(cp);
  255. // Record child stdout and stderr if necessary.
  256. if(!this->Passthru)
  257. {
  258. char* data = 0;
  259. int length = 0;
  260. while(int p = cmsysProcess_WaitForData(cp, &data, &length, 0))
  261. {
  262. if(p == cmsysProcess_Pipe_STDOUT)
  263. {
  264. fout.write(data, length);
  265. std::cout.write(data, length);
  266. this->HaveOut = true;
  267. }
  268. else if(p == cmsysProcess_Pipe_STDERR)
  269. {
  270. ferr.write(data, length);
  271. std::cerr.write(data, length);
  272. this->HaveErr = true;
  273. }
  274. }
  275. }
  276. // Wait for the real command to finish.
  277. cmsysProcess_WaitForExit(cp, 0);
  278. this->ExitCode = cmsysProcess_GetExitValue(cp);
  279. }
  280. //----------------------------------------------------------------------------
  281. int cmCTestLaunch::Run()
  282. {
  283. if(!this->Process)
  284. {
  285. std::cerr << "Could not allocate cmsysProcess instance!\n";
  286. return -1;
  287. }
  288. this->RunChild();
  289. if(this->CheckResults())
  290. {
  291. return this->ExitCode;
  292. }
  293. this->LoadConfig();
  294. this->WriteXML();
  295. return this->ExitCode;
  296. }
  297. //----------------------------------------------------------------------------
  298. void cmCTestLaunch::LoadLabels()
  299. {
  300. if(this->OptionBuildDir.empty() || this->OptionTargetName.empty())
  301. {
  302. return;
  303. }
  304. // Labels are listed in per-target files.
  305. std::string fname = this->OptionBuildDir;
  306. fname += cmake::GetCMakeFilesDirectory();
  307. fname += "/";
  308. fname += this->OptionTargetName;
  309. fname += ".dir/Labels.txt";
  310. // We are interested in per-target labels for this source file.
  311. std::string source = this->OptionSource;
  312. cmSystemTools::ConvertToUnixSlashes(source);
  313. // Load the labels file.
  314. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
  315. if(!fin) { return; }
  316. bool inTarget = true;
  317. bool inSource = false;
  318. std::string line;
  319. while(cmSystemTools::GetLineFromStream(fin, line))
  320. {
  321. if(line.empty() || line[0] == '#')
  322. {
  323. // Ignore blank and comment lines.
  324. continue;
  325. }
  326. else if(line[0] == ' ')
  327. {
  328. // Label lines appear indented by one space.
  329. if(inTarget || inSource)
  330. {
  331. this->Labels.insert(line.c_str()+1);
  332. }
  333. }
  334. else if(!this->OptionSource.empty() && !inSource)
  335. {
  336. // Non-indented lines specify a source file name. The first one
  337. // is the end of the target-wide labels. Use labels following a
  338. // matching source.
  339. inTarget = false;
  340. inSource = this->SourceMatches(line, source);
  341. }
  342. else
  343. {
  344. return;
  345. }
  346. }
  347. }
  348. //----------------------------------------------------------------------------
  349. bool cmCTestLaunch::SourceMatches(std::string const& lhs,
  350. std::string const& rhs)
  351. {
  352. // TODO: Case sensitivity, UseRelativePaths, etc. Note that both
  353. // paths in the comparison get generated by CMake. This is done for
  354. // every source in the target, so it should be efficient (cannot use
  355. // cmSystemTools::IsSameFile).
  356. return lhs == rhs;
  357. }
  358. //----------------------------------------------------------------------------
  359. bool cmCTestLaunch::IsError() const
  360. {
  361. return this->ExitCode != 0;
  362. }
  363. //----------------------------------------------------------------------------
  364. void cmCTestLaunch::WriteXML()
  365. {
  366. // Name the xml file.
  367. std::string logXML = this->LogDir;
  368. logXML += this->IsError()? "error-" : "warning-";
  369. logXML += this->LogHash;
  370. logXML += ".xml";
  371. // Use cmGeneratedFileStream to atomically create the report file.
  372. cmGeneratedFileStream fxml(logXML.c_str());
  373. cmXMLWriter xml(fxml, 2);
  374. xml.StartElement("Failure");
  375. xml.Attribute("type", this->IsError() ? "Error" : "Warning");
  376. this->WriteXMLAction(xml);
  377. this->WriteXMLCommand(xml);
  378. this->WriteXMLResult(xml);
  379. this->WriteXMLLabels(xml);
  380. xml.EndElement(); // Failure
  381. }
  382. //----------------------------------------------------------------------------
  383. void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
  384. {
  385. xml.Comment("Meta-information about the build action");
  386. xml.StartElement("Action");
  387. // TargetName
  388. if(!this->OptionTargetName.empty())
  389. {
  390. xml.Element("TargetName", this->OptionTargetName);
  391. }
  392. // Language
  393. if(!this->OptionLanguage.empty())
  394. {
  395. xml.Element("Language", this->OptionLanguage);
  396. }
  397. // SourceFile
  398. if(!this->OptionSource.empty())
  399. {
  400. std::string source = this->OptionSource;
  401. cmSystemTools::ConvertToUnixSlashes(source);
  402. // If file is in source tree use its relative location.
  403. if(cmSystemTools::FileIsFullPath(this->SourceDir.c_str()) &&
  404. cmSystemTools::FileIsFullPath(source.c_str()) &&
  405. cmSystemTools::IsSubDirectory(source,
  406. this->SourceDir))
  407. {
  408. source = cmSystemTools::RelativePath(this->SourceDir.c_str(),
  409. source.c_str());
  410. }
  411. xml.Element("SourceFile", source);
  412. }
  413. // OutputFile
  414. if(!this->OptionOutput.empty())
  415. {
  416. xml.Element("OutputFile", this->OptionOutput);
  417. }
  418. // OutputType
  419. const char* outputType = 0;
  420. if(!this->OptionTargetType.empty())
  421. {
  422. if(this->OptionTargetType == "EXECUTABLE")
  423. {
  424. outputType = "executable";
  425. }
  426. else if(this->OptionTargetType == "SHARED_LIBRARY")
  427. {
  428. outputType = "shared library";
  429. }
  430. else if(this->OptionTargetType == "MODULE_LIBRARY")
  431. {
  432. outputType = "module library";
  433. }
  434. else if(this->OptionTargetType == "STATIC_LIBRARY")
  435. {
  436. outputType = "static library";
  437. }
  438. }
  439. else if(!this->OptionSource.empty())
  440. {
  441. outputType = "object file";
  442. }
  443. if(outputType)
  444. {
  445. xml.Element("OutputType", outputType);
  446. }
  447. xml.EndElement(); // Action
  448. }
  449. //----------------------------------------------------------------------------
  450. void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml)
  451. {
  452. xml.Comment("Details of command");
  453. xml.StartElement("Command");
  454. if(!this->CWD.empty())
  455. {
  456. xml.Element("WorkingDirectory", this->CWD);
  457. }
  458. for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
  459. ai != this->RealArgs.end(); ++ai)
  460. {
  461. xml.Element("Argument", *ai);
  462. }
  463. xml.EndElement(); // Command
  464. }
  465. //----------------------------------------------------------------------------
  466. void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml)
  467. {
  468. xml.Comment("Result of command");
  469. xml.StartElement("Result");
  470. // StdOut
  471. xml.StartElement("StdOut");
  472. this->DumpFileToXML(xml, this->LogOut);
  473. xml.EndElement(); // StdOut
  474. // StdErr
  475. xml.StartElement("StdErr");
  476. this->DumpFileToXML(xml, this->LogErr);
  477. xml.EndElement(); // StdErr
  478. // ExitCondition
  479. xml.StartElement("ExitCondition");
  480. cmsysProcess* cp = this->Process;
  481. switch (cmsysProcess_GetState(cp))
  482. {
  483. case cmsysProcess_State_Starting:
  484. xml.Content("No process has been executed"); break;
  485. case cmsysProcess_State_Executing:
  486. xml.Content("The process is still executing"); break;
  487. case cmsysProcess_State_Disowned:
  488. xml.Content("Disowned"); break;
  489. case cmsysProcess_State_Killed:
  490. xml.Content("Killed by parent"); break;
  491. case cmsysProcess_State_Expired:
  492. xml.Content("Killed when timeout expired"); break;
  493. case cmsysProcess_State_Exited:
  494. xml.Content(this->ExitCode); break;
  495. case cmsysProcess_State_Exception:
  496. xml.Content("Terminated abnormally: ");
  497. xml.Content(cmsysProcess_GetExceptionString(cp)); break;
  498. case cmsysProcess_State_Error:
  499. xml.Content("Error administrating child process: ");
  500. xml.Content(cmsysProcess_GetErrorString(cp)); break;
  501. };
  502. xml.EndElement(); // ExitCondition
  503. xml.EndElement(); // Result
  504. }
  505. //----------------------------------------------------------------------------
  506. void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml)
  507. {
  508. this->LoadLabels();
  509. if(!this->Labels.empty())
  510. {
  511. xml.Comment("Interested parties");
  512. xml.StartElement("Labels");
  513. for(std::set<std::string>::const_iterator li = this->Labels.begin();
  514. li != this->Labels.end(); ++li)
  515. {
  516. xml.Element("Label", *li);
  517. }
  518. xml.EndElement(); // Labels
  519. }
  520. }
  521. //----------------------------------------------------------------------------
  522. void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml,
  523. std::string const& fname)
  524. {
  525. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
  526. std::string line;
  527. const char* sep = "";
  528. while(cmSystemTools::GetLineFromStream(fin, line))
  529. {
  530. if(MatchesFilterPrefix(line))
  531. {
  532. continue;
  533. }
  534. xml.Content(sep);
  535. xml.Content(line);
  536. sep = "\n";
  537. }
  538. }
  539. //----------------------------------------------------------------------------
  540. bool cmCTestLaunch::CheckResults()
  541. {
  542. // Skip XML in passthru mode.
  543. if(this->Passthru)
  544. {
  545. return true;
  546. }
  547. // We always report failure for error conditions.
  548. if(this->IsError())
  549. {
  550. return false;
  551. }
  552. // Scrape the output logs to look for warnings.
  553. if((this->HaveErr && this->ScrapeLog(this->LogErr)) ||
  554. (this->HaveOut && this->ScrapeLog(this->LogOut)))
  555. {
  556. return false;
  557. }
  558. return true;
  559. }
  560. //----------------------------------------------------------------------------
  561. void cmCTestLaunch::LoadScrapeRules()
  562. {
  563. if(this->ScrapeRulesLoaded)
  564. {
  565. return;
  566. }
  567. this->ScrapeRulesLoaded = true;
  568. // Common compiler warning formats. These are much simpler than the
  569. // full log-scraping expressions because we do not need to extract
  570. // file and line information.
  571. this->RegexWarning.push_back("(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]");
  572. this->RegexWarning.push_back("(^|[ :])[Rr][Ee][Mm][Aa][Rr][Kk]");
  573. this->RegexWarning.push_back("(^|[ :])[Nn][Oo][Tt][Ee]");
  574. // Load custom match rules given to us by CTest.
  575. this->LoadScrapeRules("Warning", this->RegexWarning);
  576. this->LoadScrapeRules("WarningSuppress", this->RegexWarningSuppress);
  577. }
  578. //----------------------------------------------------------------------------
  579. void
  580. cmCTestLaunch
  581. ::LoadScrapeRules(const char* purpose,
  582. std::vector<cmsys::RegularExpression>& regexps)
  583. {
  584. std::string fname = this->LogDir;
  585. fname += "Custom";
  586. fname += purpose;
  587. fname += ".txt";
  588. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
  589. std::string line;
  590. cmsys::RegularExpression rex;
  591. while(cmSystemTools::GetLineFromStream(fin, line))
  592. {
  593. if(rex.compile(line.c_str()))
  594. {
  595. regexps.push_back(rex);
  596. }
  597. }
  598. }
  599. //----------------------------------------------------------------------------
  600. bool cmCTestLaunch::ScrapeLog(std::string const& fname)
  601. {
  602. this->LoadScrapeRules();
  603. // Look for log file lines matching warning expressions but not
  604. // suppression expressions.
  605. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
  606. std::string line;
  607. while(cmSystemTools::GetLineFromStream(fin, line))
  608. {
  609. if(MatchesFilterPrefix(line))
  610. {
  611. continue;
  612. }
  613. if(this->Match(line, this->RegexWarning) &&
  614. !this->Match(line, this->RegexWarningSuppress))
  615. {
  616. return true;
  617. }
  618. }
  619. return false;
  620. }
  621. //----------------------------------------------------------------------------
  622. bool cmCTestLaunch::Match(std::string const& line,
  623. std::vector<cmsys::RegularExpression>& regexps)
  624. {
  625. for(std::vector<cmsys::RegularExpression>::iterator ri = regexps.begin();
  626. ri != regexps.end(); ++ri)
  627. {
  628. if(ri->find(line.c_str()))
  629. {
  630. return true;
  631. }
  632. }
  633. return false;
  634. }
  635. //----------------------------------------------------------------------------
  636. bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const
  637. {
  638. if(!this->OptionFilterPrefix.empty() && cmSystemTools::StringStartsWith(
  639. line.c_str(), this->OptionFilterPrefix.c_str()))
  640. {
  641. return true;
  642. }
  643. return false;
  644. }
  645. //----------------------------------------------------------------------------
  646. int cmCTestLaunch::Main(int argc, const char* const argv[])
  647. {
  648. if(argc == 2)
  649. {
  650. std::cerr << "ctest --launch: this mode is for internal CTest use only"
  651. << std::endl;
  652. return 1;
  653. }
  654. cmCTestLaunch self(argc, argv);
  655. return self.Run();
  656. }
  657. //----------------------------------------------------------------------------
  658. #include "cmGlobalGenerator.h"
  659. #include "cmLocalGenerator.h"
  660. #include "cmMakefile.h"
  661. #include "cmake.h"
  662. #include <cmsys/auto_ptr.hxx>
  663. void cmCTestLaunch::LoadConfig()
  664. {
  665. cmake cm;
  666. cm.SetHomeDirectory("");
  667. cm.SetHomeOutputDirectory("");
  668. cmGlobalGenerator gg(&cm);
  669. cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
  670. cmsys::auto_ptr<cmLocalGenerator> lg(
  671. gg.CreateLocalGenerator(mf.get()));
  672. std::string fname = this->LogDir;
  673. fname += "CTestLaunchConfig.cmake";
  674. if(cmSystemTools::FileExists(fname.c_str()) &&
  675. mf->ReadListFile(fname.c_str()))
  676. {
  677. this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
  678. cmSystemTools::ConvertToUnixSlashes(this->SourceDir);
  679. }
  680. }