Compiler.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.CodeDom.Compiler;
  29. using System.Collections.Generic;
  30. using System.Globalization;
  31. using System.IO;
  32. using Microsoft.CSharp;
  33. using Microsoft.JScript;
  34. using Microsoft.VisualBasic;
  35. using OpenSim.Region.Environment.Interfaces;
  36. using OpenSim.Region.ScriptEngine.Interfaces;
  37. namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
  38. {
  39. public class Compiler
  40. {
  41. // private static readonly log4net.ILog m_log
  42. // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  43. // * Uses "LSL2Converter" to convert LSL to C# if necessary.
  44. // * Compiles C#-code into an assembly
  45. // * Returns assembly name ready for AppDomain load.
  46. //
  47. // Assembly is compiled using LSL_BaseClass as base. Look at debug C# code file created when LSL script is compiled for full details.
  48. //
  49. internal enum enumCompileType
  50. {
  51. lsl = 0,
  52. cs = 1,
  53. vb = 2,
  54. js = 3,
  55. yp = 4
  56. }
  57. /// <summary>
  58. /// This contains number of lines WE use for header when compiling script. User will get error in line x-LinesToRemoveOnError when error occurs.
  59. /// </summary>
  60. public int LinesToRemoveOnError = 3;
  61. private enumCompileType DefaultCompileLanguage;
  62. private bool WriteScriptSourceToDebugFile;
  63. private bool CompileWithDebugInformation;
  64. private Dictionary<string, bool> AllowedCompilers = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
  65. private Dictionary<string, enumCompileType> LanguageMapping = new Dictionary<string, enumCompileType>(StringComparer.CurrentCultureIgnoreCase);
  66. private string FilePrefix;
  67. private string ScriptEnginesPath = "ScriptEngines";
  68. private static LSL2CSConverter LSL_Converter = new LSL2CSConverter();
  69. //private static CSCodeGenerator LSL_Converter;
  70. private static CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
  71. private static VBCodeProvider VBcodeProvider = new VBCodeProvider();
  72. private static JScriptCodeProvider JScodeProvider = new JScriptCodeProvider();
  73. private static CSharpCodeProvider YPcodeProvider = new CSharpCodeProvider(); // YP is translated into CSharp
  74. private static YP2CSConverter YP_Converter = new YP2CSConverter();
  75. // private static int instanceID = new Random().Next(0, int.MaxValue); // Unique number to use on our compiled files
  76. private static UInt64 scriptCompileCounter = 0; // And a counter
  77. public IScriptEngine m_scriptEngine;
  78. public Compiler(IScriptEngine scriptEngine)
  79. {
  80. m_scriptEngine = scriptEngine;
  81. ReadConfig();
  82. }
  83. public bool in_startup = true;
  84. public void ReadConfig()
  85. {
  86. // Get some config
  87. WriteScriptSourceToDebugFile = m_scriptEngine.Config.GetBoolean("WriteScriptSourceToDebugFile", true);
  88. CompileWithDebugInformation = m_scriptEngine.Config.GetBoolean("CompileWithDebugInformation", true);
  89. // Get file prefix from scriptengine name and make it file system safe:
  90. FilePrefix = "CommonCompiler";
  91. foreach (char c in Path.GetInvalidFileNameChars())
  92. {
  93. FilePrefix = FilePrefix.Replace(c, '_');
  94. }
  95. // First time we start? Delete old files
  96. if (in_startup)
  97. {
  98. in_startup = false;
  99. DeleteOldFiles();
  100. }
  101. // Map name and enum type of our supported languages
  102. LanguageMapping.Add(enumCompileType.cs.ToString(), enumCompileType.cs);
  103. LanguageMapping.Add(enumCompileType.vb.ToString(), enumCompileType.vb);
  104. LanguageMapping.Add(enumCompileType.lsl.ToString(), enumCompileType.lsl);
  105. LanguageMapping.Add(enumCompileType.js.ToString(), enumCompileType.js);
  106. LanguageMapping.Add(enumCompileType.yp.ToString(), enumCompileType.yp);
  107. // Allowed compilers
  108. string allowComp = m_scriptEngine.Config.GetString("AllowedCompilers", "lsl,cs,vb,js,yp");
  109. AllowedCompilers.Clear();
  110. #if DEBUG
  111. m_scriptEngine.Log.Debug("[Compiler]: Allowed languages: " + allowComp);
  112. #endif
  113. foreach (string strl in allowComp.Split(','))
  114. {
  115. string strlan = strl.Trim(" \t".ToCharArray()).ToLower();
  116. if (!LanguageMapping.ContainsKey(strlan))
  117. {
  118. m_scriptEngine.Log.Error("[Compiler]: Config error. Compiler is unable to recognize language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
  119. }
  120. else
  121. {
  122. #if DEBUG
  123. //m_scriptEngine.Log.Debug("[Compiler]: Config OK. Compiler recognized language type \"" + strlan + "\" specified in \"AllowedCompilers\".");
  124. #endif
  125. }
  126. AllowedCompilers.Add(strlan, true);
  127. }
  128. if (AllowedCompilers.Count == 0)
  129. m_scriptEngine.Log.Error("[Compiler]: Config error. Compiler could not recognize any language in \"AllowedCompilers\". Scripts will not be executed!");
  130. // Default language
  131. string defaultCompileLanguage = m_scriptEngine.Config.GetString("DefaultCompileLanguage", "lsl").ToLower();
  132. // Is this language recognized at all?
  133. if (!LanguageMapping.ContainsKey(defaultCompileLanguage))
  134. {
  135. m_scriptEngine.Log.Error("[Compiler]: " +
  136. "Config error. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is not recognized as a valid language. Changing default to: \"lsl\".");
  137. defaultCompileLanguage = "lsl";
  138. }
  139. // Is this language in allow-list?
  140. if (!AllowedCompilers.ContainsKey(defaultCompileLanguage))
  141. {
  142. m_scriptEngine.Log.Error("[Compiler]: " +
  143. "Config error. Default language \"" + defaultCompileLanguage + "\"specified in \"DefaultCompileLanguage\" is not in list of \"AllowedCompilers\". Scripts may not be executed!");
  144. }
  145. else
  146. {
  147. #if DEBUG
  148. // m_scriptEngine.Log.Debug("[Compiler]: " +
  149. // "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language.");
  150. #endif
  151. // LANGUAGE IS IN ALLOW-LIST
  152. DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage];
  153. }
  154. // We now have an allow-list, a mapping list, and a default language
  155. }
  156. /// <summary>
  157. /// Delete old script files
  158. /// </summary>
  159. private void DeleteOldFiles()
  160. {
  161. // CREATE FOLDER IF IT DOESNT EXIST
  162. if (!Directory.Exists(ScriptEnginesPath))
  163. {
  164. try
  165. {
  166. Directory.CreateDirectory(ScriptEnginesPath);
  167. }
  168. catch (Exception ex)
  169. {
  170. m_scriptEngine.Log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + ScriptEnginesPath + "\": " + ex.ToString());
  171. }
  172. }
  173. if (!Directory.Exists(Path.Combine(ScriptEnginesPath,
  174. m_scriptEngine.World.RegionInfo.RegionID.ToString())))
  175. {
  176. try
  177. {
  178. Directory.CreateDirectory(Path.Combine(ScriptEnginesPath,
  179. m_scriptEngine.World.RegionInfo.RegionID.ToString()));
  180. }
  181. catch (Exception ex)
  182. {
  183. m_scriptEngine.Log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath,
  184. m_scriptEngine.World.RegionInfo.RegionID.ToString())+ "\": " + ex.ToString());
  185. }
  186. }
  187. foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath,
  188. m_scriptEngine.World.RegionInfo.RegionID.ToString())))
  189. {
  190. //m_scriptEngine.Log.Error("[Compiler]: FILE FOUND: " + file);
  191. if (file.ToLower().StartsWith(FilePrefix + "_compiled_") ||
  192. file.ToLower().StartsWith(FilePrefix + "_source_"))
  193. {
  194. try
  195. {
  196. File.Delete(file);
  197. }
  198. catch (Exception ex)
  199. {
  200. m_scriptEngine.Log.Error("[Compiler]: Exception trying delete old script file \"" + file + "\": " + ex.ToString());
  201. }
  202. }
  203. }
  204. }
  205. ////private ICodeCompiler icc = codeProvider.CreateCompiler();
  206. //public string CompileFromFile(string LSOFileName)
  207. //{
  208. // switch (Path.GetExtension(LSOFileName).ToLower())
  209. // {
  210. // case ".txt":
  211. // case ".lsl":
  212. // Common.ScriptEngineBase.Shared.SendToDebug("Source code is LSL, converting to CS");
  213. // return CompileFromLSLText(File.ReadAllText(LSOFileName));
  214. // case ".cs":
  215. // Common.ScriptEngineBase.Shared.SendToDebug("Source code is CS");
  216. // return CompileFromCSText(File.ReadAllText(LSOFileName));
  217. // default:
  218. // throw new Exception("Unknown script type.");
  219. // }
  220. //}
  221. /// <summary>
  222. /// Converts script from LSL to CS and calls CompileFromCSText
  223. /// </summary>
  224. /// <param name="Script">LSL script</param>
  225. /// <returns>Filename to .dll assembly</returns>
  226. public string PerformScriptCompile(string Script, string asset)
  227. {
  228. string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
  229. m_scriptEngine.World.RegionInfo.RegionID.ToString(),
  230. FilePrefix + "_compiled_" + asset + ".dll"));
  231. // string OutFile = Path.Combine(ScriptEnginesPath,
  232. // FilePrefix + "_compiled_" + asset + ".dll");
  233. if (File.Exists(OutFile))
  234. {
  235. m_scriptEngine.Log.DebugFormat("[Compiler] Returning existing assembly for {0}", asset);
  236. return OutFile;
  237. }
  238. if (!Directory.Exists(ScriptEnginesPath))
  239. {
  240. try
  241. {
  242. Directory.CreateDirectory(ScriptEnginesPath);
  243. }
  244. catch (Exception)
  245. {
  246. }
  247. }
  248. if (!Directory.Exists(Path.Combine(ScriptEnginesPath,
  249. m_scriptEngine.World.RegionInfo.RegionID.ToString())))
  250. {
  251. try
  252. {
  253. Directory.CreateDirectory(ScriptEnginesPath);
  254. }
  255. catch (Exception)
  256. {
  257. }
  258. }
  259. enumCompileType l = DefaultCompileLanguage;
  260. if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture))
  261. l = enumCompileType.cs;
  262. if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture))
  263. {
  264. l = enumCompileType.vb;
  265. // We need to remove //vb, it won't compile with that
  266. Script = Script.Substring(4, Script.Length - 4);
  267. }
  268. if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture))
  269. l = enumCompileType.lsl;
  270. if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture))
  271. l = enumCompileType.js;
  272. if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
  273. l = enumCompileType.yp;
  274. if (!AllowedCompilers.ContainsKey(l.ToString()))
  275. {
  276. // Not allowed to compile to this language!
  277. string errtext = String.Empty;
  278. errtext += "The compiler for language \"" + l.ToString() + "\" is not in list of allowed compilers. Script will not be executed!";
  279. throw new Exception(errtext);
  280. }
  281. string compileScript = Script;
  282. if (l == enumCompileType.lsl)
  283. {
  284. // Its LSL, convert it to C#
  285. compileScript = LSL_Converter.Convert(Script);
  286. //LSL_Converter = new CSCodeGenerator(Script);
  287. //compileScript = LSL_Converter.Generate();
  288. l = enumCompileType.cs;
  289. }
  290. if (l == enumCompileType.yp)
  291. {
  292. // Its YP, convert it to C#
  293. compileScript = YP_Converter.Convert(Script);
  294. // We have our own processor now
  295. //l = enumCompileType.cs;
  296. }
  297. // Insert additional assemblies here
  298. //ADAM: Disabled for the moment until it's working right.
  299. bool enableCommanderLSL = false;
  300. if (enableCommanderLSL == true && ((l == enumCompileType.cs) || (l == enumCompileType.yp)))
  301. {
  302. foreach (KeyValuePair<string,
  303. ICommander> com
  304. in m_scriptEngine.World.GetCommanders())
  305. {
  306. compileScript = com.Value.GenerateRuntimeAPI() + compileScript;
  307. }
  308. }
  309. // End of insert
  310. switch (l)
  311. {
  312. case enumCompileType.cs:
  313. compileScript = CreateCSCompilerScript(compileScript);
  314. break;
  315. case enumCompileType.vb:
  316. compileScript = CreateVBCompilerScript(compileScript);
  317. break;
  318. case enumCompileType.js:
  319. compileScript = CreateJSCompilerScript(compileScript);
  320. break;
  321. case enumCompileType.yp:
  322. compileScript = CreateYPCompilerScript(compileScript);
  323. break;
  324. }
  325. // m_log.Debug("[ScriptEngine.DotNetEngine]: Preparing to compile the following LSL to C# translated code");
  326. // m_log.Debug("");
  327. // m_log.Debug(compileScript);
  328. return CompileFromDotNetText(compileScript, l, asset);
  329. }
  330. private static string CreateJSCompilerScript(string compileScript)
  331. {
  332. compileScript = String.Empty +
  333. "import OpenSim.Region.ScriptEngine.Shared; import System.Collections.Generic;\r\n" +
  334. "package SecondLife {\r\n" +
  335. "class Script extends OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
  336. compileScript +
  337. "} }\r\n";
  338. return compileScript;
  339. }
  340. private static string CreateCSCompilerScript(string compileScript)
  341. {
  342. compileScript = String.Empty +
  343. "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
  344. String.Empty + "namespace SecondLife { " +
  345. String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
  346. @"public Script() { } " +
  347. compileScript +
  348. "} }\r\n";
  349. return compileScript;
  350. }
  351. private static string CreateYPCompilerScript(string compileScript)
  352. {
  353. compileScript = String.Empty +
  354. "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " +
  355. "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" +
  356. String.Empty + "namespace SecondLife { " +
  357. String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" +
  358. //@"public Script() { } " +
  359. @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " +
  360. @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " +
  361. compileScript +
  362. "} }\r\n";
  363. return compileScript;
  364. }
  365. private static string CreateVBCompilerScript(string compileScript)
  366. {
  367. compileScript = String.Empty +
  368. "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " +
  369. String.Empty + "NameSpace SecondLife:" +
  370. String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " +
  371. "\r\nPublic Sub New()\r\nEnd Sub: " +
  372. compileScript +
  373. ":End Class :End Namespace\r\n";
  374. return compileScript;
  375. }
  376. /// <summary>
  377. /// Compile .NET script to .Net assembly (.dll)
  378. /// </summary>
  379. /// <param name="Script">CS script</param>
  380. /// <returns>Filename to .dll assembly</returns>
  381. internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset)
  382. {
  383. string ext = "." + lang.ToString();
  384. // Output assembly name
  385. scriptCompileCounter++;
  386. string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
  387. m_scriptEngine.World.RegionInfo.RegionID.ToString(),
  388. FilePrefix + "_compiled_" + asset + ".dll"));
  389. #if DEBUG
  390. // m_scriptEngine.Log.Debug("[Compiler]: Starting compile of \"" + OutFile + "\".");
  391. #endif
  392. try
  393. {
  394. File.Delete(OutFile);
  395. }
  396. catch (Exception e) // NOTLEGIT - Should be just catching FileIOException
  397. {
  398. //m_scriptEngine.Log.Error("[Compiler]: Unable to delete old existring script-file before writing new. Compile aborted: " + e.ToString());
  399. throw new Exception("Unable to delete old existring script-file before writing new. Compile aborted: " + e.ToString());
  400. }
  401. //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
  402. // DEBUG - write source to disk
  403. if (WriteScriptSourceToDebugFile)
  404. {
  405. string srcFileName = FilePrefix + "_source_" + Path.GetFileNameWithoutExtension(OutFile) + ext;
  406. try
  407. {
  408. File.WriteAllText(Path.Combine(Path.Combine(
  409. ScriptEnginesPath,
  410. m_scriptEngine.World.RegionInfo.RegionID.ToString()),
  411. srcFileName), Script);
  412. }
  413. catch (Exception ex) // NOTLEGIT - Should be just catching FileIOException
  414. {
  415. m_scriptEngine.Log.Error("[Compiler]: Exception while trying to write script source to file \"" + srcFileName + "\": " + ex.ToString());
  416. }
  417. }
  418. // Do actual compile
  419. CompilerParameters parameters = new CompilerParameters();
  420. parameters.IncludeDebugInformation = true;
  421. // Add all available assemblies
  422. // foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
  423. // {
  424. // Console.WriteLine("Adding assembly: " + asm.Location);
  425. // parameters.ReferencedAssemblies.Add(asm.Location);
  426. // }
  427. string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
  428. // string rootPathSE = Path.GetDirectoryName(GetType().Assembly.Location);
  429. //Console.WriteLine("Assembly location: " + rootPath);
  430. parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.dll"));
  431. parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
  432. if (lang == enumCompileType.yp)
  433. {
  434. parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Shared.YieldProlog.dll"));
  435. }
  436. parameters.GenerateExecutable = false;
  437. parameters.OutputAssembly = OutFile;
  438. parameters.IncludeDebugInformation = CompileWithDebugInformation;
  439. //parameters.WarningLevel = 1; // Should be 4?
  440. parameters.TreatWarningsAsErrors = false;
  441. //Console.WriteLine(Script);
  442. CompilerResults results;
  443. switch (lang)
  444. {
  445. case enumCompileType.vb:
  446. results = VBcodeProvider.CompileAssemblyFromSource(parameters, Script);
  447. break;
  448. case enumCompileType.cs:
  449. results = CScodeProvider.CompileAssemblyFromSource(parameters, Script);
  450. break;
  451. case enumCompileType.js:
  452. results = JScodeProvider.CompileAssemblyFromSource(parameters, Script);
  453. break;
  454. case enumCompileType.yp:
  455. results = YPcodeProvider.CompileAssemblyFromSource(parameters, Script);
  456. break;
  457. default:
  458. throw new Exception("Compiler is not able to recongnize language type \"" + lang.ToString() + "\"");
  459. }
  460. // Check result
  461. // Go through errors
  462. //
  463. // WARNINGS AND ERRORS
  464. //
  465. if (results.Errors.Count > 0)
  466. {
  467. string errtext = String.Empty;
  468. foreach (CompilerError CompErr in results.Errors)
  469. {
  470. errtext += "Line number " + (CompErr.Line - LinesToRemoveOnError) +
  471. ", Error Number: " + CompErr.ErrorNumber +
  472. ", '" + CompErr.ErrorText + "'\r\n";
  473. }
  474. if (!File.Exists(OutFile))
  475. {
  476. throw new Exception(errtext);
  477. }
  478. }
  479. //
  480. // NO ERRORS, BUT NO COMPILED FILE
  481. //
  482. if (!File.Exists(OutFile))
  483. {
  484. string errtext = String.Empty;
  485. errtext += "No compile error. But not able to locate compiled file.";
  486. throw new Exception(errtext);
  487. }
  488. m_scriptEngine.Log.DebugFormat("[Compiler] Compiled new assembly for {0}", asset);
  489. return OutFile;
  490. }
  491. }
  492. }