cmCTestLaunch.cxx 20 KB

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