PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/booc/App.cs

https://github.com/boo/boo-lang
C# | 903 lines | 782 code | 86 blank | 35 comment | 97 complexity | 4d69299799e06e49822c04cb24c0e557 MD5 | raw file
Possible License(s): GPL-2.0
  1. #region license
  2. // Copyright (c) 2004, 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.Text;
  30. using System.Collections;
  31. using System.Diagnostics;
  32. using System.IO;
  33. using System.Globalization;
  34. using System.Threading;
  35. using Boo.Lang.Compiler.Ast.Visitors;
  36. using Assembly = System.Reflection.Assembly;
  37. using Boo.Lang.Compiler;
  38. using Boo.Lang.Compiler.IO;
  39. using Boo.Lang.Compiler.Pipelines;
  40. using Boo.Lang.Compiler.Resources;
  41. using Boo.Lang;
  42. namespace BooC
  43. {
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. class App
  48. {
  49. ArrayList _responseFileList = new ArrayList();
  50. CompilerParameters _options = null;
  51. ArrayList _references = new ArrayList();
  52. ArrayList _packages = new ArrayList();
  53. bool _noConfig = false;
  54. string _pipelineName = null;
  55. bool _debugSteps = false;
  56. bool _whiteSpaceAgnostic = false;
  57. /// <summary>
  58. /// The main entry point for the application.
  59. /// </summary>
  60. [STAThread]
  61. static int Main(string[] args)
  62. {
  63. if (((IList)args).Contains("-utf8"))
  64. {
  65. using (StreamWriter writer = new StreamWriter(Console.OpenStandardError(), Encoding.UTF8))
  66. {
  67. // leave the byte order mark in its own line and out
  68. writer.WriteLine();
  69. Console.SetError(writer);
  70. return new App().Run(args);
  71. }
  72. }
  73. else
  74. {
  75. return new App().Run(args);
  76. }
  77. }
  78. public int Run(string[] args)
  79. {
  80. int resultCode = 127;
  81. AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);
  82. CheckBooCompiler();
  83. try
  84. {
  85. Stopwatch setupTime = Stopwatch.StartNew();
  86. _options = new CompilerParameters(false); //false means no stdlib loading yet
  87. _options.GenerateInMemory = false;
  88. ArrayList tempLibPaths = _options.LibPaths.Clone() as ArrayList;
  89. _options.LibPaths.Clear();
  90. BooCompiler compiler = new BooCompiler(_options);
  91. ParseOptions(args);
  92. if (0 == _options.Input.Count)
  93. {
  94. throw new ApplicationException(Boo.Lang.ResourceManager.GetString("BooC.NoInputSpecified"));
  95. }
  96. //move standard libpaths below any new ones:
  97. foreach(object o in tempLibPaths)
  98. _options.LibPaths.Add(o);
  99. if (_options.StdLib)
  100. {
  101. _options.LoadDefaultReferences();
  102. }
  103. else if (!_noConfig)
  104. {
  105. _references.Insert(0, "mscorlib");
  106. }
  107. LoadReferences();
  108. ConfigurePipeline();
  109. if (_options.TraceInfo)
  110. {
  111. compiler.Parameters.Pipeline.BeforeStep += new CompilerStepEventHandler(OnBeforeStep);
  112. compiler.Parameters.Pipeline.AfterStep += new CompilerStepEventHandler(OnAfterStep);
  113. }
  114. setupTime.Stop();
  115. Stopwatch processingTime = Stopwatch.StartNew();
  116. CompilerContext context = compiler.Run();
  117. processingTime.Stop();
  118. if (context.Warnings.Count > 0)
  119. {
  120. Console.Error.WriteLine(context.Warnings);
  121. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.Warnings", context.Warnings.Count));
  122. }
  123. if (context.Errors.Count > 0)
  124. {
  125. foreach (CompilerError error in context.Errors)
  126. {
  127. Console.Error.WriteLine(error.ToString(_options.TraceInfo));
  128. }
  129. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.Errors", context.Errors.Count));
  130. }
  131. else
  132. {
  133. resultCode = 0;
  134. }
  135. if (_options.TraceWarning)
  136. {
  137. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.ProcessingTime", _options.Input.Count, processingTime.ElapsedMilliseconds, setupTime.ElapsedMilliseconds));
  138. }
  139. }
  140. catch (Exception x)
  141. {
  142. object message = (_options.TraceWarning)
  143. ? (object)x : (object)x.Message;
  144. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.FatalError", message));
  145. }
  146. return resultCode;
  147. }
  148. void LoadReferences()
  149. {
  150. foreach (string r in _references)
  151. {
  152. _options.References.Add(_options.LoadAssembly(r, true));
  153. }
  154. foreach (string p in _packages)
  155. {
  156. _options.LoadReferencesFromPackage(p);
  157. }
  158. }
  159. void CheckBooCompiler()
  160. {
  161. string path = Path.Combine(Path.GetDirectoryName(
  162. Assembly.GetExecutingAssembly().Location),
  163. "Boo.Lang.Compiler.dll");
  164. if (File.Exists(path))
  165. {
  166. foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
  167. {
  168. if (a.FullName.StartsWith("Boo.Lang.Compiler"))
  169. {
  170. if (string.Compare(a.Location, path, true) != 0)
  171. {
  172. //can't use ResourceManager, boo.lang.dll may be out of date
  173. string msg=string.Format("WARNING: booc is not using the Boo.Lang.Compiler.dll next to booc.exe. Using '{0}' instead of '{1}'. You may need to remove boo dlls from the GAC using gacutil or Mscorcfg.",
  174. a.Location, path);
  175. //has to be all 1 line for things like msbuild that parse booc output.
  176. Console.Error.WriteLine(msg);
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. string Consume(TextReader reader)
  184. {
  185. StringWriter writer = new StringWriter();
  186. string line = reader.ReadLine();
  187. while (null != line)
  188. {
  189. writer.WriteLine(line);
  190. line = reader.ReadLine();
  191. }
  192. return writer.ToString();
  193. }
  194. void DoLogo()
  195. {
  196. Console.Write("Boo Compiler version "+Builtins.BooVersion.ToString());
  197. Console.WriteLine(" (CLR v"+Environment.Version.ToString()+")");
  198. }
  199. void Help ()
  200. {
  201. Console.WriteLine(
  202. "Usage is: booc [options] file1 ...\n" +
  203. "Options:\n" +
  204. " -c:CULTURE Sets the UI culture to be CULTURE\n" +
  205. " -debug[+|-] Generate debugging information (default: +)\n" +
  206. " -define:S1[,Sn] Defines symbols S1..Sn with optional values (=val) (-d:)\n" +
  207. " -delaysign Delays assembly signing\n" +
  208. " -ducky Turns on duck typing by default\n" +
  209. " -checked[+|-] Turns on or off checked operations (default: +)\n" +
  210. " -embedres:FILE[,ID] Embeds FILE with the optional ID\n"+
  211. " -lib:DIRS Adds the comma-separated DIRS to the assembly search path\n" +
  212. " -noconfig Does not load the standard configuration\n" +
  213. " -nostdlib Does not reference any of the default libraries\n" +
  214. " -nologo Does not display the compiler logo\n" +
  215. " -p:PIPELINE Sets the pipeline to PIPELINE\n" +
  216. " -o:FILE Sets the output file name to FILE\n" +
  217. " -keyfile:FILE The strongname key file used to strongname the assembly\n" +
  218. " -keycontainer:NAME The key pair container used to strongname the assembly\n" +
  219. " -reference:ASS References the specified assembly (-r:ASS)\n" +
  220. " -srcdir:DIR Adds DIR as a directory where sources can be found\n" +
  221. " -target:TYPE Sets the target type (exe, library or winexe)\n" +
  222. " -resource:FILE[,ID] Embeds FILE as a resource\n" +
  223. " -pkg:P1[,Pn] References packages P1..Pn (on supported platforms)\n" +
  224. " -utf8 Source file(s) are in utf8 format\n" +
  225. " -v, -vv, -vvv Sets verbosity level from warnings to very detailed\n" +
  226. " -wsa Enables white-space-agnostic build\n"
  227. );
  228. }
  229. void ParseOptions(string[] args)
  230. {
  231. bool noLogo = false;
  232. ArrayList arglist = new ArrayList(args);
  233. ExpandResponseFiles(ref arglist);
  234. AddDefaultResponseFile(ref arglist);
  235. foreach (string arg in arglist)
  236. {
  237. if ("-" == arg)
  238. {
  239. _options.Input.Add(new StringInput("<stdin>", Consume(Console.In)));
  240. continue;
  241. }
  242. if (!IsFlag(arg))
  243. {
  244. _options.Input.Add(new FileInput(StripQuotes(arg)));
  245. continue;
  246. }
  247. if ("-utf8" == arg) continue;
  248. switch (arg[1])
  249. {
  250. case 'h':
  251. {
  252. if (arg == "-help" || arg == "-h")
  253. {
  254. Help();
  255. }
  256. break;
  257. }
  258. case 'w':
  259. {
  260. if (arg == "-wsa")
  261. {
  262. _options.WhiteSpaceAgnostic = _whiteSpaceAgnostic = true;
  263. }
  264. else
  265. {
  266. InvalidOption(arg);
  267. }
  268. break;
  269. }
  270. case 'v':
  271. {
  272. _options.EnableTraceSwitch();
  273. _options.TraceLevel = TraceLevel.Warning;
  274. Trace.Listeners.Add(new TextWriterTraceListener(Console.Error));
  275. if (arg.Length > 2)
  276. {
  277. switch (arg.Substring(1))
  278. {
  279. case "vv":
  280. {
  281. _options.TraceLevel = TraceLevel.Info;
  282. MonitorAppDomain();
  283. break;
  284. }
  285. case "vvv":
  286. {
  287. _options.TraceLevel = TraceLevel.Verbose;
  288. break;
  289. }
  290. }
  291. }
  292. else
  293. {
  294. _options.TraceLevel = TraceLevel.Warning;
  295. }
  296. break;
  297. }
  298. case 'r':
  299. {
  300. if (arg.IndexOf(":") > 2 && arg.Substring(1, 9) != "reference")
  301. {
  302. switch (arg.Substring(1, 8))
  303. {
  304. case "resource":
  305. {
  306. int start = arg.IndexOf(":") + 1;
  307. AddResource(StripQuotes(arg.Substring(start)));
  308. break;
  309. }
  310. default:
  311. {
  312. InvalidOption(arg);
  313. break;
  314. }
  315. }
  316. }
  317. else
  318. {
  319. string assemblyName = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
  320. _references.Add(assemblyName);
  321. }
  322. break;
  323. }
  324. case 'l':
  325. {
  326. switch (arg.Substring(1, 3))
  327. {
  328. case "lib":
  329. {
  330. string paths = arg.Substring(arg.IndexOf(":")+1);
  331. if (paths == "")
  332. {
  333. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.BadLibPath", arg));
  334. break;
  335. }
  336. foreach(string dir in paths.Split(new Char[] {','}))
  337. {
  338. if (Directory.Exists(dir))
  339. {
  340. _options.LibPaths.Add(dir);
  341. }
  342. else
  343. {
  344. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.BadLibPath", dir));
  345. }
  346. }
  347. break;
  348. }
  349. default:
  350. {
  351. InvalidOption(arg);
  352. break;
  353. }
  354. }
  355. break;
  356. }
  357. case 'n':
  358. {
  359. if (arg == "-nologo")
  360. {
  361. noLogo = true;
  362. }
  363. else if (arg == "-noconfig")
  364. {
  365. _noConfig = true;
  366. }
  367. else if (arg == "-nostdlib")
  368. {
  369. _options.StdLib = false;
  370. }
  371. else
  372. {
  373. InvalidOption(arg);
  374. }
  375. break;
  376. }
  377. case 'o':
  378. {
  379. _options.OutputAssembly = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
  380. break;
  381. }
  382. case 't':
  383. {
  384. string targetType = arg.Substring(arg.IndexOf(":")+1);
  385. switch (targetType)
  386. {
  387. case "library":
  388. {
  389. _options.OutputType = CompilerOutputType.Library;
  390. break;
  391. }
  392. case "exe":
  393. {
  394. _options.OutputType = CompilerOutputType.ConsoleApplication;
  395. break;
  396. }
  397. case "winexe":
  398. {
  399. _options.OutputType = CompilerOutputType.WindowsApplication;
  400. break;
  401. }
  402. default:
  403. {
  404. InvalidOption(arg);
  405. break;
  406. }
  407. }
  408. break;
  409. }
  410. case 'p':
  411. {
  412. if (arg.StartsWith("-pkg:"))
  413. {
  414. string packages = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
  415. _packages.Add(packages);
  416. }
  417. else {
  418. _pipelineName = StripQuotes(arg.Substring(3));
  419. }
  420. break;
  421. }
  422. case 'c':
  423. {
  424. switch (arg.Substring(1))
  425. {
  426. case "checked":
  427. case "checked+":
  428. {
  429. _options.Checked = true;
  430. break;
  431. }
  432. case "checked-":
  433. {
  434. _options.Checked = false;
  435. break;
  436. }
  437. default:
  438. {
  439. string culture = arg.Substring(3);
  440. Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture);
  441. break;
  442. }
  443. }
  444. break;
  445. }
  446. case 's':
  447. {
  448. switch (arg.Substring(1, 6))
  449. {
  450. case "srcdir":
  451. {
  452. string path = StripQuotes(arg.Substring(8));
  453. AddFilesForPath(path, _options);
  454. break;
  455. }
  456. default:
  457. {
  458. InvalidOption(arg);
  459. break;
  460. }
  461. }
  462. break;
  463. }
  464. case 'k':
  465. {
  466. if (arg.Substring(1, 7) == "keyfile")
  467. {
  468. _options.KeyFile = StripQuotes(arg.Substring(9));
  469. }
  470. else if (arg.Substring(1, 12) == "keycontainer")
  471. {
  472. _options.KeyContainer = StripQuotes(arg.Substring(14));
  473. }
  474. else
  475. {
  476. InvalidOption(arg);
  477. }
  478. break;
  479. }
  480. case 'd':
  481. {
  482. switch (arg.Substring(1))
  483. {
  484. case "debug":
  485. case "debug+":
  486. {
  487. _options.Debug = true;
  488. break;
  489. }
  490. case "debug-":
  491. {
  492. _options.Debug = false;
  493. break;
  494. }
  495. case "ducky":
  496. {
  497. _options.Ducky = true;
  498. break;
  499. }
  500. case "debug-steps":
  501. {
  502. _debugSteps = true;
  503. break;
  504. }
  505. case "delaysign":
  506. {
  507. _options.DelaySign = true;
  508. break;
  509. }
  510. default:
  511. {
  512. if (arg.StartsWith("-d:") || arg.StartsWith("-define:"))
  513. {
  514. int skip = arg.StartsWith("-d:") ? 3 : 8;
  515. string[] symbols = StripQuotes(arg.Substring(skip)).Split(",".ToCharArray());
  516. foreach (string symbol in symbols)
  517. {
  518. string[] s_v = symbol.Split("=".ToCharArray(), 2);
  519. if (s_v[0].Length < 1) continue;
  520. if (_options.Defines.ContainsKey(s_v[0]))
  521. {
  522. _options.Defines[s_v[0]] = (s_v.Length > 1) ? s_v[1] : null;
  523. Trace.WriteLine("REPLACED DEFINE '"+s_v[0]+"' WITH VALUE '"+((s_v.Length > 1) ? s_v[1] : string.Empty) +"'");
  524. }
  525. else
  526. {
  527. _options.Defines.Add(s_v[0], (s_v.Length > 1) ? s_v[1] : null);
  528. Trace.WriteLine("ADDED DEFINE '"+s_v[0]+"' WITH VALUE '"+((s_v.Length > 1) ? s_v[1] : string.Empty) +"'");
  529. }
  530. }
  531. }
  532. else
  533. {
  534. InvalidOption(arg);
  535. }
  536. break;
  537. }
  538. }
  539. break;
  540. }
  541. case 'e':
  542. {
  543. switch (arg.Substring(1,8))
  544. {
  545. case "embedres":
  546. {
  547. if (!IsMono)
  548. {
  549. throw new ApplicationException("-embedres is only supported on mono. Try -resource.");
  550. }
  551. int start = arg.IndexOf(":") + 1;
  552. EmbedResource(StripQuotes(arg.Substring(start)));
  553. break;
  554. }
  555. default:
  556. {
  557. InvalidOption(arg);
  558. break;
  559. }
  560. }
  561. break;
  562. }
  563. default:
  564. {
  565. if (arg == "--help")
  566. {
  567. Help();
  568. }
  569. else
  570. {
  571. InvalidOption(arg);
  572. }
  573. break;
  574. }
  575. }
  576. }
  577. if (!noLogo)
  578. {
  579. DoLogo();
  580. }
  581. }
  582. private bool IsMono
  583. {
  584. get { return Type.GetType("System.MonoType", false) != null; }
  585. }
  586. private void EmbedResource(string resourceFile)
  587. {
  588. int comma = resourceFile.LastIndexOf(',');
  589. if (comma >= 0)
  590. {
  591. string resourceName = resourceFile.Substring(comma+1);
  592. resourceFile = resourceFile.Substring(0, comma);
  593. _options.Resources.Add(new NamedEmbeddedFileResource(resourceFile, resourceName));
  594. }
  595. else
  596. {
  597. _options.Resources.Add(new EmbeddedFileResource(resourceFile));
  598. }
  599. }
  600. private void AddResource(string resourceFile)
  601. {
  602. int comma = resourceFile.LastIndexOf(',');
  603. if (comma >= 0)
  604. {
  605. string resourceName = resourceFile.Substring(comma+1);
  606. resourceFile = resourceFile.Substring(0, comma);
  607. _options.Resources.Add(new NamedFileResource(resourceFile, resourceName));
  608. }
  609. else
  610. {
  611. _options.Resources.Add(new FileResource(resourceFile));
  612. }
  613. }
  614. private void ConfigurePipeline()
  615. {
  616. if (null != _pipelineName)
  617. {
  618. _options.Pipeline = CompilerPipeline.GetPipeline(_pipelineName);
  619. }
  620. else
  621. {
  622. _options.Pipeline = new CompileToFile();
  623. }
  624. if (_whiteSpaceAgnostic)
  625. {
  626. _options.Pipeline[0] = new Boo.Lang.Parser.WSABooParsingStep();
  627. }
  628. if (_debugSteps)
  629. {
  630. _options.Pipeline.AfterStep += new CompilerStepEventHandler(new StepDebugger().AfterStep);
  631. }
  632. }
  633. private string StripQuotes(string s)
  634. {
  635. if (s.Length > 1 && s.StartsWith("\"") && s.EndsWith("\""))
  636. {
  637. return s.Substring(1,s.Length-2);
  638. }
  639. return s;
  640. }
  641. private class StepDebugger
  642. {
  643. string _last;
  644. public void AfterStep(object sender, CompilerStepEventArgs args)
  645. {
  646. Console.WriteLine("********* {0} *********", args.Step);
  647. StringWriter writer = new StringWriter();
  648. args.Context.CompileUnit.Accept(new BooPrinterVisitor(writer, BooPrinterVisitor.PrintOptions.PrintLocals));
  649. string code = writer.ToString();
  650. if (code != _last)
  651. {
  652. Console.WriteLine(code);
  653. }
  654. else
  655. {
  656. Console.WriteLine("no changes");
  657. }
  658. _last = code;
  659. }
  660. }
  661. ArrayList LoadResponseFile(string file)
  662. {
  663. file = Path.GetFullPath(file);
  664. if (_responseFileList.Contains(file))
  665. {
  666. throw new ApplicationException(
  667. Boo.Lang.ResourceManager.Format("BCE0500", file));
  668. }
  669. _responseFileList.Add(file);
  670. if (!File.Exists(file))
  671. {
  672. throw new ApplicationException(Boo.Lang.ResourceManager.Format("BCE0501", file));
  673. }
  674. ArrayList arglist = new ArrayList();
  675. try
  676. {
  677. using (StreamReader sr = new StreamReader(file))
  678. {
  679. string line;
  680. while ((line = sr.ReadLine()) != null)
  681. {
  682. line = line.Trim();
  683. if (line.Length > 0 && line[0] != '#')
  684. {
  685. if (line.StartsWith("@") && line.Length > 2)
  686. {
  687. arglist.AddRange(LoadResponseFile(line.Substring(1)));
  688. }
  689. else
  690. {
  691. arglist.Add(line);
  692. }
  693. }
  694. }
  695. }
  696. }
  697. catch (ApplicationException)
  698. {
  699. throw;
  700. }
  701. catch (Exception x)
  702. {
  703. throw new ApplicationException(
  704. Boo.Lang.ResourceManager.Format("BCE0502", file),
  705. x);
  706. }
  707. return arglist;
  708. }
  709. void ExpandResponseFiles(ref ArrayList arglist)
  710. {
  711. ArrayList result = new ArrayList();
  712. foreach (string arg in arglist)
  713. {
  714. if (arg.StartsWith("@") && arg.Length > 2)
  715. {
  716. result.AddRange(LoadResponseFile(arg.Substring(1)));
  717. }
  718. else
  719. {
  720. result.Add(arg);
  721. }
  722. }
  723. arglist = result;
  724. }
  725. void AddDefaultResponseFile(ref ArrayList arglist)
  726. {
  727. ArrayList result = new ArrayList();
  728. foreach (string arg in arglist)
  729. {
  730. if (arg == "-noconfig")
  731. {
  732. _noConfig = true;
  733. }
  734. else
  735. {
  736. result.Add(arg);
  737. }
  738. }
  739. if (!_noConfig)
  740. {
  741. string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "booc.rsp");
  742. if (File.Exists(file))
  743. {
  744. result.InsertRange(0, LoadResponseFile(file));
  745. }
  746. }
  747. arglist = result;
  748. }
  749. void OnBeforeStep(object sender, CompilerStepEventArgs args)
  750. {
  751. args.Context.TraceEnter("Entering {0}", args.Step);
  752. }
  753. void OnAfterStep(object sender, CompilerStepEventArgs args)
  754. {
  755. args.Context.TraceLeave("Leaving {0}", args.Step);
  756. }
  757. void InvalidOption(string arg)
  758. {
  759. Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.InvalidOption", arg));
  760. }
  761. bool IsFlag(string arg)
  762. {
  763. return arg[0] == '-';
  764. }
  765. void AddFilesForPath(string path, CompilerParameters _options)
  766. {
  767. foreach (string fname in Directory.GetFiles(path, "*.boo"))
  768. {
  769. if (!fname.EndsWith(".boo")) continue;
  770. _options.Input.Add(new FileInput(Path.GetFullPath(fname)));
  771. }
  772. foreach (string dirName in Directory.GetDirectories(path))
  773. {
  774. AddFilesForPath(dirName, _options);
  775. }
  776. }
  777. void MonitorAppDomain()
  778. {
  779. if (_options.TraceInfo)
  780. {
  781. AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
  782. foreach(Assembly a in AppDomain.CurrentDomain.GetAssemblies())
  783. {
  784. Trace.WriteLine("ASSEMBLY AT STARTUP: "+GetAssemblyLocation(a));
  785. }
  786. }
  787. }
  788. static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
  789. {
  790. Trace.WriteLine("ASSEMBLY LOADED: " + GetAssemblyLocation(args.LoadedAssembly));
  791. }
  792. static string GetAssemblyLocation(Assembly a)
  793. {
  794. string loc;
  795. try
  796. {
  797. loc = a.Location;
  798. }
  799. catch (Exception)
  800. {
  801. loc = "<dynamic>"+a.FullName;
  802. }
  803. return loc;
  804. }
  805. static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
  806. {
  807. string simpleName = args.Name.Split(',')[0];
  808. string fileName = Path.Combine(Environment.CurrentDirectory,
  809. simpleName + ".dll");
  810. if (File.Exists(fileName))
  811. {
  812. return Assembly.LoadFile(fileName);
  813. }
  814. return null;
  815. }
  816. }
  817. }