public static ScriptEngine CreateEngine(IDictionary <string, object> options = null) { var engine = Python.CreateEngine(options); // Redirect IronPython IO var infoStream = new MemoryStream(); var infoWriter = new UnityLogWriter(Debug.Log, infoStream); engine.Runtime.IO.SetOutput(infoStream, infoWriter); var errorStream = new MemoryStream(); var errorWriter = new UnityLogWriter(Debug.LogError, errorStream); engine.Runtime.IO.SetErrorOutput(errorStream, errorWriter); // Load assemblies for the `UnityEngine*` namespaces foreach (var assembly in GetAssembliesInNamespace("UnityEngine")) { engine.Runtime.LoadAssembly(assembly); } // Load assemblies for the `UnityEditor*` namespaces if (Application.isEditor) { foreach (var assembly in GetAssembliesInNamespace("UnityEditor")) { engine.Runtime.LoadAssembly(assembly); } } return(engine); }
private void RunIl2CppWithArguments(List <string> arguments, Action <ProcessStartInfo> setupStartInfo) { var cppOutputDirectoryInBuildCache = GetCppOutputDirectory(m_PlatformProvider.il2cppBuildCacheDirectory); var cppOutputDirectoryInStagingArea = GetCppOutputDirectory(m_TempFolder); var nativeOutputDirectoryInBuildCache = GetNativeOutputRelativeDirectory(m_PlatformProvider.il2cppBuildCacheDirectory); var nativeOutputDirectoryInStagingArea = GetNativeOutputRelativeDirectory(m_StagingAreaData); var il2cppOutputParser = new Il2CppOutputParser(Path.Combine(cppOutputDirectoryInBuildCache, "Il2CppToEditorData.json")); arguments.Add("--convert-in-graph"); var args = arguments.Aggregate(String.Empty, (current, arg) => current + arg + " "); UnityLogWriter.WriteStringToUnityLog($"Invoking il2cpp with arguments: {args}\n"); Runner.RunNetCoreProgram(GetIl2CppExe(), args, m_PlatformProvider.il2cppBuildCacheDirectory, il2cppOutputParser, setupStartInfo); // Copy IL2CPP outputs to StagingArea if (Directory.Exists(nativeOutputDirectoryInBuildCache)) { FileUtil.CopyDirectoryRecursive(nativeOutputDirectoryInBuildCache, nativeOutputDirectoryInStagingArea, true); } // Copy Generated C++ files and Data directory to StagingArea. // This directory will only be present when using "--convert-to-cpp" with IL2CPP. if (Directory.Exists(cppOutputDirectoryInBuildCache)) { FileUtil.CreateOrCleanDirectory(cppOutputDirectoryInStagingArea); FileUtil.CopyDirectoryRecursive(cppOutputDirectoryInBuildCache, cppOutputDirectoryInStagingArea); } }
private static void RunProgram(Program p, string exe, string args, string workingDirectory, CompilerOutputParserBase parser) { var stopwatch = new Stopwatch(); stopwatch.Start(); using (p) { p.GetProcessStartInfo().WorkingDirectory = workingDirectory; p.Start(); p.WaitForExit(); stopwatch.Stop(); UnityLogWriter.WriteStringToUnityLog($"{exe} exited after {stopwatch.ElapsedMilliseconds} ms.\n"); var messages = new List <CompilerMessage>(); if (parser != null) { var errorOutput = p.GetErrorOutput(); var standardOutput = p.GetStandardOutput(); messages.AddRange(parser.Parse(errorOutput, standardOutput, true)); } foreach (var message in NonerrorMessages(messages)) { Debug.LogWarning(message.message); } var errorMessages = ErrorMessages(messages).ToArray(); if (p.ExitCode != 0) { if (errorMessages.Any()) { // Use the last error as the exception message to cause the build to fail. But // log any other errors that might exist. var lastError = messages.Last(); foreach (var message in errorMessages.Take(errorMessages.Length - 1)) { Debug.LogPlayerBuildError(message.message, message.file, message.line, message.column); } throw new Exception(lastError.message); } // No messages were parsed, so just put all of the output in the error. throw new Exception("Failed running " + exe + " " + args + "\n\n" + p.GetAllOutput()); } // The exit code was zero, but there are error messages. Don't fail the build by throwing an exception, // but log the messages to the editor log. foreach (var message in errorMessages) { Console.WriteLine(message.message + " - " + message.file + " - " + message.line + " - " + message.column); } } }
private static bool RunAssemblyLinker(IEnumerable <string> args, out string @out, out string err, string linkerPath, string workingDirectory) { var argString = args.Aggregate((buff, s) => buff + " " + s); var responseFile = Path.Combine(workingDirectory, "response.rsp"); File.WriteAllText(responseFile, argString); UnityLogWriter.WriteStringToUnityLog($"Invoking UnityLinker with response file. response.rsp contents: {argString}\n"); Runner.RunNetCoreProgram(linkerPath, $"@{CommandLineFormatter.PrepareFileName(responseFile)}", workingDirectory, null, null); @out = ""; err = ""; return(true); }
private static void Init() { UnityLogWriter.Init(); }
public UnityDebugAppender() { this._writer = null; }