public static CompilerContext Compile(string assemblyName, IEnumerable <string> fileNames, IEnumerable <Assembly> references, IEnumerable <string> imports = null, IEnumerable <EnsuredMethodSignature> ensuredMethodSignatures = null) { var cc = new BooScriptCompiler(); var ps = cc.compiler.Parameters; cc.Configure(references, imports, ensuredMethodSignatures); ps.OutputAssembly = assemblyName; //add inputs ps.Input.Clear(); if (fileNames != null) { //multiple npc types may use the same script var distinctFileNames = fileNames.Distinct(); foreach (var fname in distinctFileNames) { ps.Input.Add(new FileInput(fname)); } } return(cc.compiler.Run()); }
/// <summary> /// Attempts to compile all added filenames, return a Dictionary of filenames to compilation status. If compilation has already run, this throws an exception. /// </summary> /// <returns>Dictionary of file paths to Boo.Lang.CompilerContext's.</returns> public Dictionary <string, CompilerContext> Compile() { compileGuard(); var contexts = new Dictionary <string, CompilerContext>(); var compiler = new BooScriptCompiler(); compiler.Configure(references, defaultImports, ensuredMethodSignatures); foreach (var kvp in modules) { if (kvp.Value.IsValid) { continue; } var scriptPath = kvp.Key; var scriptName = Path.GetFileNameWithoutExtension(scriptPath); var assemblyName = $"{AssemblyNamePrefix}{scriptName}.dll"; var buildTime = DateTime.Now; var context = compiler.Compile(assemblyName, new string[] { scriptPath }); contexts.Add(scriptPath, context); if (context.Errors.Count < 1) { var mi = modules[scriptPath]; mi.Assembly = context.GeneratedAssembly; mi.BuildTime = buildTime; } Plugin?.LogPrintBooErrors(context); Plugin?.LogPrintBooWarnings(context); if (context.Errors.Count == 0) { Plugin?.LogPrint($"Compiled {kvp.Key}.", TraceLevel.Info); } else { Plugin?.LogPrint($"Failed to compile {kvp.Key}.", TraceLevel.Info); } } Compiled = true; return(contexts); }
internal CompilerContext Compile() { var filePath = SourceFiles.FirstOrDefault()?.FilePath; if (!File.Exists(filePath)) { return(null); } var assName = Prefix + Path.GetFileNameWithoutExtension(filePath) + ".exe"; var cc = new BooScriptCompiler(); var refs = ScriptHelpers.GetReferences(); var imports = ScriptHelpers.GetDefaultImports(); cc.Configure(refs, imports); //cc.InternalCompiler.Parameters.OutputType = Boo.Lang.Compiler.CompilerOutputType.ConsoleApplication; cc.InternalCompiler.Parameters.OutputType = Boo.Lang.Compiler.CompilerOutputType.Library; var context = cc.Compile(assName, new List <string>() { filePath }); if (context.Errors.Count > 0) { BooScriptingPlugin.Instance.LogPrintBooErrors(context); return(context); //dont bother listing warnings... } if (context.Warnings.Count > 0) { BooScriptingPlugin.Instance.LogPrintBooWarnings(context); } if (!Link(context.GeneratedAssembly)) { BooScriptingPlugin.Instance.LogPrint($"Unable to link boo script '{filePath}'."); return(null); } return(context); }