コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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();
                Console.WriteLine("{0} exited after {1} ms.", exe, stopwatch.ElapsedMilliseconds);

                IEnumerable <CompilerMessage> messages = null;
                if (parser != null)
                {
                    var errorOutput    = p.GetErrorOutput();
                    var standardOutput = p.GetStandardOutput();
                    messages = parser.Parse(errorOutput, standardOutput, true);
                }

                if (p.ExitCode != 0)
                {
                    if (messages != null)
                    {
                        foreach (var message in messages)
                        {
                            Debug.LogPlayerBuildError(message.message, message.file, message.line, message.column);
                        }
                    }

                    Debug.LogError("Failed running " + exe + " " + args + "\n\n" + p.GetAllOutput());

                    throw new Exception(string.Format("{0} did not run properly!", exe));
                }
                else
                {
                    if (messages != null)
                    {
                        foreach (var message in messages)
                        {
                            Console.WriteLine(message.message + " - " + message.file + " - " + message.line + " - " + message.column);
                        }
                    }
                }
            }
        }
コード例 #3
0
            private static void RunProgram(
                Program p,
                string exe,
                string args,
                string workingDirectory,
                CompilerOutputParserBase parser,
                BuildReport report)
            {
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();
                using (p)
                {
                    p.GetProcessStartInfo().WorkingDirectory = workingDirectory;
                    p.Start();
                    p.WaitForExit();
                    stopwatch.Stop();

                    Console.WriteLine("{0} exited after {1} ms.", (object)exe, (object)stopwatch.ElapsedMilliseconds);
                    IEnumerable <UnityEditor.Scripting.Compilers.CompilerMessage> compilerMessages = null;
                    string[] errorOutput    = p.GetErrorOutput();
                    string[] standardOutput = p.GetStandardOutput();
                    if (parser != null)
                    {
                        compilerMessages = parser.Parse(errorOutput, standardOutput, true, "n/a (burst)");
                    }

                    var errorMessageBuilder = new StringBuilder();
                    if (p.ExitCode != 0)
                    {
                        if (compilerMessages != null)
                        {
                            foreach (UnityEditor.Scripting.Compilers.CompilerMessage compilerMessage in compilerMessages)
                            {
                                Debug.LogPlayerBuildError(compilerMessage.message, compilerMessage.file, compilerMessage.line, compilerMessage.column);
                            }
                        }

                        // We try to output the version in the heading error if we can
                        var matchVersion = MatchVersion.Match(exe);
                        errorMessageBuilder.Append(matchVersion.Success ?
                                                   "Burst compiler (" + matchVersion.Groups[1].Value + ") failed running" :
                                                   "Burst compiler failed running");
                        errorMessageBuilder.AppendLine();
                        errorMessageBuilder.AppendLine();
                        // Don't output the path if we are not burst-debugging or the exe exist
                        if (BurstLoader.IsDebugging || !File.Exists(exe))
                        {
                            errorMessageBuilder.Append(exe).Append(" ").Append(args);
                            errorMessageBuilder.AppendLine();
                            errorMessageBuilder.AppendLine();
                        }

                        errorMessageBuilder.AppendLine("stdout:");
                        foreach (string str in standardOutput)
                        {
                            errorMessageBuilder.AppendLine(str);
                        }
                        errorMessageBuilder.AppendLine("stderr:");
                        foreach (string str in errorOutput)
                        {
                            errorMessageBuilder.AppendLine(str);
                        }

                        throw new BuildFailedException(errorMessageBuilder.ToString());
                    }
                    Console.WriteLine(p.GetAllOutput());
                }
            }
コード例 #4
0
            private static void RunProgram(
                Program p,
                string exe,
                string args,
                string workingDirectory,
                CompilerOutputParserBase parser,
                BuildReport report)
            {
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();
                using (p)
                {
                    p.GetProcessStartInfo().WorkingDirectory = workingDirectory;
                    p.Start();
                    p.WaitForExit();
                    stopwatch.Stop();

                    Console.WriteLine("{0} exited after {1} ms.", (object)exe, (object)stopwatch.ElapsedMilliseconds);
                    IEnumerable <UnityEditor.Scripting.Compilers.CompilerMessage> compilerMessages = null;
                    string[] errorOutput    = p.GetErrorOutput();
                    string[] standardOutput = p.GetStandardOutput();
                    if (parser != null)
                    {
                        compilerMessages = parser.Parse(errorOutput, standardOutput, true, "n/a (burst)");
                    }

                    var errorMessageBuilder = new StringBuilder();
                    if (p.ExitCode != 0)
                    {
                        if (compilerMessages != null)
                        {
                            foreach (UnityEditor.Scripting.Compilers.CompilerMessage compilerMessage in compilerMessages)
                            {
                                Debug.LogPlayerBuildError(compilerMessage.message, compilerMessage.file, compilerMessage.line, compilerMessage.column);
                            }
                        }

                        // We try to output the version in the heading error if we can
                        var matchVersion = MatchVersion.Match(exe);
                        errorMessageBuilder.Append(matchVersion.Success ?
                                                   "Burst compiler (" + matchVersion.Groups[1].Value + ") failed running" :
                                                   "Burst compiler failed running");
                        errorMessageBuilder.AppendLine();
                        errorMessageBuilder.AppendLine();
                        // Don't output the path if we are not burst-debugging or the exe exist
                        if (BurstLoader.IsDebugging || !File.Exists(exe))
                        {
                            errorMessageBuilder.Append(exe).Append(" ").Append(args);
                            errorMessageBuilder.AppendLine();
                            errorMessageBuilder.AppendLine();
                        }

                        errorMessageBuilder.AppendLine("stdout:");
                        foreach (string str in standardOutput)
                        {
                            errorMessageBuilder.AppendLine(str);
                        }
                        errorMessageBuilder.AppendLine("stderr:");
                        foreach (string str in errorOutput)
                        {
                            errorMessageBuilder.AppendLine(str);
                        }

                        // We don't use Debug.LogError as it displays a stacktrace that we really don't want to pollute our message output
                        //report.AddMessage(LogType.Error, errorMessageBuilder.ToString());
                        Debug.LogPlayerBuildError(errorMessageBuilder.ToString(), "unknown", 0, 0);

                        // We report the error to the build player but it seems that it is not correctly reported.
                        // In Editor\Src\BuildPipeline\BuildPlayer.cpp
                        //    if (report.GetSuccess())
                        //    {
                        //        DisplayProgressNotification("Build Successful", "");
                        //    }
                        //
                        //    report.UnregisterForLogMessages();
                        //    report.EndBuildStep(buildStepToken);
                        //    report.UpdateSummary();
                        //
                        // Actually report.GetSuccess() should go after the last UpdateSummary()
                        //
                        // We should probably have a method report.SetBuildStatus(error)
                        report.AddMessage(LogType.Error, errorMessageBuilder.ToString());
                    }
                    Console.WriteLine(p.GetAllOutput());
                }
            }