PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/booc/CommandLineParser.cs

http://github.com/bamboo/boo
C# | 835 lines | 724 code | 85 blank | 26 comment | 100 complexity | 0123e5b945013d422fde42c5e43a7f7d MD5 | raw file
Possible License(s): GPL-2.0
  1. #region license
  2. // Copyright (c) 2009 Rodrigo B. de Oliveira (rbo@acm.org)
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without modification,
  6. // are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Rodrigo B. de Oliveira nor the names of its
  14. // contributors may be used to endorse or promote products derived from this
  15. // software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #endregion
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Diagnostics;
  31. using System.Globalization;
  32. using System.IO;
  33. using System.Linq;
  34. using System.Reflection;
  35. using System.Threading;
  36. using Boo.Lang.Compiler;
  37. using Boo.Lang.Compiler.Ast.Visitors;
  38. using Boo.Lang.Compiler.IO;
  39. using Boo.Lang.Compiler.Pipelines;
  40. using Boo.Lang.Compiler.Resources;
  41. using Boo.Lang.Compiler.TypeSystem.Services;
  42. using Boo.Lang.Compiler.Util;
  43. using Boo.Lang.Environments;
  44. using Boo.Lang.Resources;
  45. namespace booc
  46. {
  47. public class CommandLineParser
  48. {
  49. public static void ParseInto(CompilerParameters options, params string[] commandLine)
  50. {
  51. new CommandLineParser(commandLine, options);
  52. }
  53. readonly CompilerParameters _options;
  54. readonly Set<string> _processedResponseFiles = new Set<string>();
  55. readonly List<string> _references = new List<string>();
  56. readonly List<string> _packages = new List<string>();
  57. bool _noConfig;
  58. string _pipelineName;
  59. bool _debugSteps;
  60. private CommandLineParser(IEnumerable<string> args, CompilerParameters options)
  61. {
  62. _options = options;
  63. _options.GenerateInMemory = false;
  64. var tempLibPaths = _options.LibPaths.ToArray();
  65. _options.LibPaths.Clear();
  66. Parse(args);
  67. //move standard libpaths below any new ones:
  68. _options.LibPaths.Extend(tempLibPaths);
  69. if (_options.StdLib)
  70. _options.LoadDefaultReferences();
  71. else if (!_noConfig)
  72. _references.Insert(0, "mscorlib");
  73. LoadReferences();
  74. ConfigurePipeline();
  75. if (_options.TraceInfo)
  76. {
  77. _options.Pipeline.BeforeStep += OnBeforeStep;
  78. _options.Pipeline.AfterStep += OnAfterStep;
  79. }
  80. }
  81. void Parse(IEnumerable<string> commandLine)
  82. {
  83. var noLogo = false;
  84. var args = ExpandResponseFiles(commandLine.Select(s => StripQuotes(s)));
  85. AddDefaultResponseFile(args);
  86. foreach (var arg in args)
  87. {
  88. if ("-" == arg)
  89. {
  90. _options.Input.Add(new StringInput("<stdin>", Consume(Console.In)));
  91. continue;
  92. }
  93. if (!IsFlag(arg))
  94. {
  95. _options.Input.Add(new FileInput(StripQuotes(arg)));
  96. continue;
  97. }
  98. if ("-utf8" == arg)
  99. continue;
  100. switch (arg[1])
  101. {
  102. case 'h':
  103. {
  104. if (arg == "-help" || arg == "-h")
  105. Help();
  106. break;
  107. }
  108. case 'w':
  109. {
  110. if (arg == "-wsa")
  111. _options.WhiteSpaceAgnostic = true;
  112. else if (arg == "-warnaserror")
  113. _options.WarnAsError = true;
  114. else if (arg.StartsWith("-warnaserror:"))
  115. {
  116. string warnings = ValueOf(arg);
  117. foreach (string warning in warnings.Split(','))
  118. _options.EnableWarningAsError(warning);
  119. }
  120. else if (arg.StartsWith("-warn:"))
  121. {
  122. var warnings = ValueOf(arg);
  123. foreach (string warning in warnings.Split(','))
  124. _options.EnableWarning(warning);
  125. }
  126. else
  127. InvalidOption(arg);
  128. break;
  129. }
  130. case 'v':
  131. {
  132. _options.TraceLevel = TraceLevel.Warning;
  133. if (arg.Length > 2)
  134. {
  135. switch (arg.Substring(1))
  136. {
  137. case "vv":
  138. {
  139. _options.TraceLevel = TraceLevel.Info;
  140. MonitorAppDomain();
  141. break;
  142. }
  143. case "vvv":
  144. {
  145. _options.TraceLevel = TraceLevel.Verbose;
  146. break;
  147. }
  148. }
  149. }
  150. else
  151. {
  152. _options.TraceLevel = TraceLevel.Warning;
  153. }
  154. break;
  155. }
  156. case 'r':
  157. {
  158. if (arg.IndexOf(":") > 2 && arg.Substring(1, 9) != "reference")
  159. {
  160. switch (arg.Substring(1, 8))
  161. {
  162. case "resource":
  163. {
  164. AddResource(ValueOf(arg));
  165. break;
  166. }
  167. default:
  168. {
  169. InvalidOption(arg);
  170. break;
  171. }
  172. }
  173. }
  174. else
  175. {
  176. var assemblies = ValueOf(arg);
  177. foreach (var assemblyName in assemblies.Split(','))
  178. _references.Add(assemblyName);
  179. }
  180. break;
  181. }
  182. case 'l':
  183. {
  184. switch (arg.Substring(1, 3))
  185. {
  186. case "lib":
  187. {
  188. ParseLib(arg);
  189. break;
  190. }
  191. default:
  192. {
  193. InvalidOption(arg);
  194. break;
  195. }
  196. }
  197. break;
  198. }
  199. case 'n':
  200. {
  201. if (arg == "-nologo")
  202. noLogo = true;
  203. else if (arg == "-noconfig")
  204. _noConfig = true;
  205. else if (arg == "-nostdlib")
  206. _options.StdLib = false;
  207. else if (arg == "-nowarn")
  208. _options.NoWarn = true;
  209. else if (arg.StartsWith("-nowarn:"))
  210. {
  211. string warnings = ValueOf(arg);
  212. foreach (string warning in warnings.Split(','))
  213. _options.DisableWarning(warning);
  214. }
  215. else
  216. InvalidOption(arg);
  217. break;
  218. }
  219. case 'o':
  220. {
  221. _options.OutputAssembly = ValueOf(arg);
  222. break;
  223. }
  224. case 't':
  225. {
  226. string targetType = ValueOf(arg);
  227. switch (targetType)
  228. {
  229. case "library":
  230. {
  231. _options.OutputType = CompilerOutputType.Library;
  232. break;
  233. }
  234. case "exe":
  235. {
  236. _options.OutputType = CompilerOutputType.ConsoleApplication;
  237. break;
  238. }
  239. case "winexe":
  240. {
  241. _options.OutputType = CompilerOutputType.WindowsApplication;
  242. break;
  243. }
  244. default:
  245. {
  246. InvalidOption(arg);
  247. break;
  248. }
  249. }
  250. break;
  251. }
  252. case 'p':
  253. {
  254. if (arg.StartsWith("-pkg:"))
  255. {
  256. string packages = ValueOf(arg);
  257. _packages.Add(packages);
  258. }
  259. else if (arg.StartsWith("-platform:"))
  260. {
  261. string arch = ValueOf(arg).ToLowerInvariant();
  262. switch (arch)
  263. {
  264. case "anycpu":
  265. break;
  266. case "x86":
  267. _options.Platform = "x86";
  268. break;
  269. case "x64":
  270. _options.Platform = "x64";
  271. break;
  272. case "itanium":
  273. _options.Platform = "itanium";
  274. break;
  275. default:
  276. InvalidOption(arg, "Valid platform types are: `anycpu', `x86', `x64' or `itanium'.");
  277. break;
  278. }
  279. }
  280. else if (arg.StartsWith("-p:"))
  281. {
  282. _pipelineName = StripQuotes(arg.Substring(3));
  283. }
  284. else
  285. {
  286. InvalidOption(arg);
  287. }
  288. break;
  289. }
  290. case 'c':
  291. {
  292. switch (arg.Substring(1))
  293. {
  294. case "checked":
  295. case "checked+":
  296. {
  297. _options.Checked = true;
  298. break;
  299. }
  300. case "checked-":
  301. {
  302. _options.Checked = false;
  303. break;
  304. }
  305. default:
  306. {
  307. string culture = arg.Substring(3);
  308. Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture);
  309. break;
  310. }
  311. }
  312. break;
  313. }
  314. case 's':
  315. {
  316. switch (arg.Substring(1, 6))
  317. {
  318. case "srcdir":
  319. {
  320. string path = StripQuotes(arg.Substring(8));
  321. AddFilesForPath(path, _options);
  322. break;
  323. }
  324. case "strict-":
  325. break;
  326. case "strict":
  327. case "strict+":
  328. {
  329. _options.Strict = true;
  330. break;
  331. }
  332. default:
  333. {
  334. InvalidOption(arg);
  335. break;
  336. }
  337. }
  338. break;
  339. }
  340. case 'k':
  341. {
  342. if (arg.Substring(1, 7) == "keyfile")
  343. {
  344. _options.KeyFile = StripQuotes(arg.Substring(9));
  345. }
  346. else if (arg.Substring(1, 12) == "keycontainer")
  347. {
  348. _options.KeyContainer = StripQuotes(arg.Substring(14));
  349. }
  350. else
  351. {
  352. InvalidOption(arg);
  353. }
  354. break;
  355. }
  356. case 'd':
  357. {
  358. switch (arg.Substring(1))
  359. {
  360. case "debug":
  361. case "debug+":
  362. {
  363. _options.Debug = true;
  364. break;
  365. }
  366. case "debug-":
  367. {
  368. _options.Debug = false;
  369. break;
  370. }
  371. case "ducky":
  372. {
  373. _options.Ducky = true;
  374. break;
  375. }
  376. case "debug-steps":
  377. {
  378. _debugSteps = true;
  379. break;
  380. }
  381. case "delaysign":
  382. {
  383. _options.DelaySign = true;
  384. break;
  385. }
  386. default:
  387. {
  388. if (arg.StartsWith("-d:") || arg.StartsWith("-define:"))
  389. {
  390. string[] symbols = ValueOf(arg).Split(",".ToCharArray());
  391. foreach (string symbol in symbols)
  392. {
  393. string[] s_v = symbol.Split("=".ToCharArray(), 2);
  394. if (s_v[0].Length < 1) continue;
  395. if (_options.Defines.ContainsKey(s_v[0]))
  396. {
  397. _options.Defines[s_v[0]] = (s_v.Length > 1) ? s_v[1] : null;
  398. TraceInfo("REPLACED DEFINE '" + s_v[0] + "' WITH VALUE '" + ((s_v.Length > 1) ? s_v[1] : string.Empty) + "'");
  399. }
  400. else
  401. {
  402. _options.Defines.Add(s_v[0], (s_v.Length > 1) ? s_v[1] : null);
  403. TraceInfo("ADDED DEFINE '" + s_v[0] + "' WITH VALUE '" + ((s_v.Length > 1) ? s_v[1] : string.Empty) + "'");
  404. }
  405. }
  406. }
  407. else
  408. {
  409. InvalidOption(arg);
  410. }
  411. break;
  412. }
  413. }
  414. break;
  415. }
  416. case 'e':
  417. {
  418. switch (arg.Substring(1, 8))
  419. {
  420. case "embedres":
  421. {
  422. EmbedResource(ValueOf(arg));
  423. break;
  424. }
  425. default:
  426. {
  427. InvalidOption(arg);
  428. break;
  429. }
  430. }
  431. break;
  432. }
  433. case 'u':
  434. {
  435. if (arg == "-unsafe")
  436. _options.Unsafe = true;
  437. else
  438. InvalidOption(arg);
  439. break;
  440. }
  441. case 'x':
  442. {
  443. if (arg.Substring(1).StartsWith("x-type-inference-rule-attribute"))
  444. {
  445. var attribute = ValueOf(arg);
  446. _options.Environment = new DeferredEnvironment { { typeof(TypeInferenceRuleProvider), () => new CustomTypeInferenceRuleProvider(attribute) } };
  447. }
  448. else
  449. {
  450. InvalidOption(arg);
  451. }
  452. break;
  453. }
  454. default:
  455. {
  456. if (arg == "--help")
  457. {
  458. Help();
  459. }
  460. else
  461. {
  462. InvalidOption(arg);
  463. }
  464. break;
  465. }
  466. }
  467. }
  468. if (!noLogo)
  469. {
  470. DoLogo();
  471. }
  472. }
  473. private static string ValueOf(string arg)
  474. {
  475. return StripQuotes(arg.Substring(arg.IndexOf(":") + 1));
  476. }
  477. private void ParseLib(string arg)
  478. {
  479. var paths = TrimAdditionalQuote(ValueOf(arg)); // TrimAdditionalQuote to work around nant bug with spaces on lib path
  480. if (string.IsNullOrEmpty(paths))
  481. {
  482. Console.Error.WriteLine(string.Format(Boo.Lang.Resources.StringResources.BooC_BadLibPath, arg));
  483. return;
  484. }
  485. foreach (var dir in paths.Split(','))
  486. {
  487. if (Directory.Exists(dir))
  488. _options.LibPaths.Add(dir);
  489. else
  490. Console.Error.WriteLine(string.Format(Boo.Lang.Resources.StringResources.BooC_BadLibPath, dir));
  491. }
  492. }
  493. static void DoLogo()
  494. {
  495. Console.WriteLine("Boo Compiler version {0} ({1})",
  496. Boo.Lang.Builtins.BooVersion, Boo.Lang.Runtime.RuntimeServices.RuntimeDisplayName);
  497. }
  498. static void Help()
  499. {
  500. Console.WriteLine(
  501. "Usage: booc [options] file1 ...\n" +
  502. "Options:\n" +
  503. " -c:CULTURE Sets the UI culture to be CULTURE\n" +
  504. " -checked[+|-] Turns on or off checked operations (default: +)\n" +
  505. " -debug[+|-] Generate debugging information (default: +)\n" +
  506. " -define:S1[,Sn] Defines symbols S1..Sn with optional values (=val) (-d:)\n" +
  507. " -delaysign Delays assembly signing\n" +
  508. " -ducky Turns on duck typing by default\n" +
  509. " -embedres:FILE[,ID] Embeds FILE with the optional ID\n" +
  510. " -keycontainer:NAME The key pair container used to strongname the assembly\n" +
  511. " -keyfile:FILE The strongname key file used to strongname the assembly\n" +
  512. " -lib:DIRS Adds the comma-separated DIRS to the assembly search path\n" +
  513. " -noconfig Does not load the standard configuration\n" +
  514. " -nologo Does not display the compiler logo\n" +
  515. " -nostdlib Does not reference any of the default libraries\n" +
  516. " -nowarn[:W1,Wn] Suppress all or a list of compiler warnings\n" +
  517. " -o:FILE Sets the output file name to FILE\n" +
  518. " -p:PIPELINE Sets the pipeline to PIPELINE\n" +
  519. " -pkg:P1[,Pn] References packages P1..Pn (on supported platforms)\n" +
  520. " -platform:ARCH Specifies target platform (anycpu, x86, x64 or itanium)\n" +
  521. " -reference:A1[,An] References assemblies (-r:)\n" +
  522. " -resource:FILE[,ID] Embeds FILE as a resource\n" +
  523. " -srcdir:DIR Adds DIR as a directory where sources can be found\n" +
  524. " -strict Turns on strict mode.\n" +
  525. " -target:TYPE Sets the target type (exe, library or winexe) (-t:)\n" +
  526. " -unsafe Allows to compile unsafe code.\n" +
  527. " -utf8 Source file(s) are in utf8 format\n" +
  528. " -v, -vv, -vvv Sets verbosity level from warnings to very detailed\n" +
  529. " -warn:W1[,Wn] Enables a list of optional warnings.\n" +
  530. " -warnaserror[:W1,Wn] Treats all or a list of warnings as errors\n" +
  531. " -wsa Enables white-space-agnostic build\n"
  532. );
  533. }
  534. private void EmbedResource(string resourceFile)
  535. {
  536. int comma = resourceFile.LastIndexOf(',');
  537. if (comma >= 0)
  538. {
  539. string resourceName = resourceFile.Substring(comma + 1);
  540. resourceFile = resourceFile.Substring(0, comma);
  541. _options.Resources.Add(new NamedEmbeddedFileResource(resourceFile, resourceName));
  542. }
  543. else
  544. {
  545. _options.Resources.Add(new EmbeddedFileResource(resourceFile));
  546. }
  547. }
  548. private void AddResource(string resourceFile)
  549. {
  550. int comma = resourceFile.LastIndexOf(',');
  551. if (comma >= 0)
  552. {
  553. string resourceName = resourceFile.Substring(comma + 1);
  554. resourceFile = resourceFile.Substring(0, comma);
  555. _options.Resources.Add(new NamedFileResource(resourceFile, resourceName));
  556. }
  557. else
  558. {
  559. _options.Resources.Add(new FileResource(resourceFile));
  560. }
  561. }
  562. private void ConfigurePipeline()
  563. {
  564. var pipeline = _pipelineName != null ? CompilerPipeline.GetPipeline(_pipelineName) : new CompileToFile();
  565. _options.Pipeline = pipeline;
  566. if (_debugSteps)
  567. {
  568. var stepDebugger = new StepDebugger();
  569. pipeline.BeforeStep += stepDebugger.BeforeStep;
  570. pipeline.AfterStep += stepDebugger.AfterStep;
  571. }
  572. }
  573. private static string StripQuotes(string s)
  574. {
  575. if (s.Length > 1 && (IsDelimitedBy(s, "\"") || IsDelimitedBy(s, "'")))
  576. return s.Substring(1, s.Length - 2);
  577. return s;
  578. }
  579. private static bool IsDelimitedBy(string s, string delimiter)
  580. {
  581. return s.StartsWith(delimiter) && s.EndsWith(delimiter);
  582. }
  583. private static string TrimAdditionalQuote(string s)
  584. {
  585. return s.EndsWith("\"") ? s.Substring(0, s.Length - 1) : s;
  586. }
  587. private class StepDebugger
  588. {
  589. private string _last;
  590. private Stopwatch _stopWatch;
  591. public void BeforeStep(object sender, CompilerStepEventArgs args)
  592. {
  593. _stopWatch = Stopwatch.StartNew();
  594. }
  595. public void AfterStep(object sender, CompilerStepEventArgs args)
  596. {
  597. _stopWatch.Stop();
  598. Console.WriteLine("********* {0} - {1} *********", args.Step, _stopWatch.Elapsed);
  599. var writer = new StringWriter();
  600. args.Context.CompileUnit.Accept(new BooPrinterVisitor(writer, BooPrinterVisitor.PrintOptions.PrintLocals));
  601. var code = writer.ToString();
  602. if (code != _last)
  603. Console.WriteLine(code);
  604. else
  605. Console.WriteLine("no changes");
  606. _last = code;
  607. }
  608. }
  609. List<string> LoadResponseFile(string file)
  610. {
  611. file = Path.GetFullPath(file);
  612. if (_processedResponseFiles.Contains(file))
  613. throw new ApplicationException(string.Format(Boo.Lang.Resources.StringResources.BCE0500, file));
  614. _processedResponseFiles.Add(file);
  615. if (!File.Exists(file))
  616. throw new ApplicationException(string.Format(Boo.Lang.Resources.StringResources.BCE0501, file));
  617. var arglist = new List<string>();
  618. try
  619. {
  620. using (var sr = new StreamReader(file))
  621. {
  622. string line;
  623. while ((line = sr.ReadLine()) != null)
  624. {
  625. line = line.Trim();
  626. if (line.Length > 0 && line[0] != '#')
  627. {
  628. if (line.StartsWith("@") && line.Length > 2)
  629. arglist.AddRange(LoadResponseFile(line.Substring(1)));
  630. else
  631. arglist.Add(StripQuotes(line));
  632. }
  633. }
  634. }
  635. }
  636. catch (ApplicationException)
  637. {
  638. throw;
  639. }
  640. catch (Exception x)
  641. {
  642. throw new ApplicationException(string.Format(Boo.Lang.Resources.StringResources.BCE0502, file), x);
  643. }
  644. return arglist;
  645. }
  646. List<string> ExpandResponseFiles(IEnumerable<string> args)
  647. {
  648. var result = new List<string>();
  649. foreach (var arg in args)
  650. {
  651. if (arg.StartsWith("@") && arg.Length > 2)
  652. result.AddRange(LoadResponseFile(arg.Substring(1)));
  653. else
  654. result.Add(arg);
  655. }
  656. return result;
  657. }
  658. void AddDefaultResponseFile(List<string> args)
  659. {
  660. if (!args.Contains("-noconfig"))
  661. {
  662. string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "booc.rsp");
  663. if (File.Exists(file))
  664. args.InsertRange(0, LoadResponseFile(file));
  665. }
  666. }
  667. Stopwatch stepStopwatch;
  668. void OnBeforeStep(object sender, CompilerStepEventArgs args)
  669. {
  670. args.Context.TraceEnter("Entering {0}", args.Step);
  671. stepStopwatch = Stopwatch.StartNew();
  672. }
  673. void OnAfterStep(object sender, CompilerStepEventArgs args)
  674. {
  675. stepStopwatch.Stop();
  676. args.Context.TraceLeave("Leaving {0} ({1}ms)", args.Step, stepStopwatch.ElapsedMilliseconds);
  677. }
  678. void InvalidOption(string arg)
  679. {
  680. InvalidOption(arg, null);
  681. }
  682. void InvalidOption(string arg, string message)
  683. {
  684. Console.Error.WriteLine(StringResources.BooC_InvalidOption, arg, message);
  685. }
  686. static bool IsFlag(string arg)
  687. {
  688. return arg[0] == '-';
  689. }
  690. static void AddFilesForPath(string path, CompilerParameters options)
  691. {
  692. foreach (var fname in Directory.GetFiles(path, "*.boo"))
  693. {
  694. if (!fname.EndsWith(".boo")) continue;
  695. options.Input.Add(new FileInput(Path.GetFullPath(fname)));
  696. }
  697. foreach (var dirName in Directory.GetDirectories(path))
  698. AddFilesForPath(dirName, options);
  699. }
  700. void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
  701. {
  702. TraceInfo("ASSEMBLY LOADED: " + GetAssemblyLocation(args.LoadedAssembly));
  703. }
  704. static string GetAssemblyLocation(Assembly a)
  705. {
  706. string loc;
  707. try
  708. {
  709. loc = a.Location;
  710. }
  711. catch (Exception)
  712. {
  713. loc = "<dynamic>" + a.FullName;
  714. }
  715. return loc;
  716. }
  717. void MonitorAppDomain()
  718. {
  719. if (_options.TraceInfo)
  720. {
  721. AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
  722. foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
  723. TraceInfo("ASSEMBLY AT STARTUP: " + GetAssemblyLocation(a));
  724. }
  725. }
  726. private void TraceInfo(string s)
  727. {
  728. if (_options.TraceInfo)
  729. Console.Error.WriteLine(s);
  730. }
  731. static string Consume(TextReader reader)
  732. {
  733. var writer = new StringWriter();
  734. var line = reader.ReadLine();
  735. while (null != line)
  736. {
  737. writer.WriteLine(line);
  738. line = reader.ReadLine();
  739. }
  740. return writer.ToString();
  741. }
  742. void LoadReferences()
  743. {
  744. foreach (var r in _references)
  745. _options.References.Add(_options.LoadAssembly(r, true));
  746. foreach (var p in _packages)
  747. _options.LoadReferencesFromPackage(p);
  748. }
  749. }
  750. }