PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/boo/src/booc/App.cs

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