/// <summary>
        /// Handle a response from the server, reporting messages and returning
        /// the appropriate exit code.
        /// </summary>
        private int HandleResponse(BuildResponse response, string pathToTool, string responseFileCommands, string commandLineCommands, ICompilerServerLogger logger)
        {
            if (response.Type != BuildResponse.ResponseType.Completed)
            {
                ValidateBootstrapUtil.AddFailedServerConnection(response.Type, OutputAssembly?.ItemSpec);
            }

            switch (response.Type)
            {
            case BuildResponse.ResponseType.Completed:
                var completedResponse = (CompletedBuildResponse)response;
                LogMessages(completedResponse.Output, StandardOutputImportanceToUse);

                if (LogStandardErrorAsError)
                {
                    LogErrorMultiline(completedResponse.ErrorOutput);
                }
                else
                {
                    LogMessages(completedResponse.ErrorOutput, StandardErrorImportanceToUse);
                }

                return(completedResponse.ReturnCode);

            case BuildResponse.ResponseType.MismatchedVersion:
                logMessage("Roslyn compiler server reports different protocol version than build task.", isError: true);
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.IncorrectHash:
                logMessage("Roslyn compiler server reports different hash version than build task.", isError: true);
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.Rejected:
                var rejectedResponse = (RejectedBuildResponse)response;
                logMessage($"Request rejected: {rejectedResponse.Reason}", isError: false);
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.AnalyzerInconsistency:
                logMessage($"Server rejected request due to analyzer inconsistency", isError: false);
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            default:
                logMessage($"Received an unrecognized response from the server: {response.Type}", isError: true);
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            void logMessage(string message, bool isError)
            {
                logger.LogError(message);
                if (isError)
                {
                    Log.LogError(message);
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, message);
                }
            }
        }
Exemple #2
0
        internal static Assembly ResolveAssembly(string assemblyDisplayName, Assembly requestingAssemblyOpt)
        {
            var name = new AssemblyName(assemblyDisplayName);

            try
            {
                return(TryRedirect(name) ? Assembly.Load(name) : null);
            }
            catch
            {
                ValidateBootstrapUtil.AddFailedLoad(name);
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Handle a response from the server, reporting messages and returning
        /// the appropriate exit code.
        /// </summary>
        private int HandleResponse(Guid requestId, BuildResponse?response, string pathToTool, string responseFileCommands, string commandLineCommands, ICompilerServerLogger logger)
        {
            if (response is null)
            {
                LogCompilationMessage(logger, requestId, CompilationKind.ToolFallback, "could not launch server");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }

            if (response.Type != BuildResponse.ResponseType.Completed)
            {
                ValidateBootstrapUtil.AddFailedServerConnection(response.Type, OutputAssembly?.ItemSpec);
            }

            switch (response.Type)
            {
            case BuildResponse.ResponseType.Completed:
                var completedResponse = (CompletedBuildResponse)response;
                LogCompilerOutput(completedResponse.Output, StandardOutputImportanceToUse);
                LogCompilationMessage(logger, requestId, CompilationKind.Server, "server processed compilation");
                return(completedResponse.ReturnCode);

            case BuildResponse.ResponseType.MismatchedVersion:
                LogCompilationMessage(logger, requestId, CompilationKind.FatalError, "server reports different protocol version than build task");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.IncorrectHash:
                LogCompilationMessage(logger, requestId, CompilationKind.FatalError, "server reports different hash version than build task");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.CannotConnect:
                LogCompilationMessage(logger, requestId, CompilationKind.ToolFallback, $"cannot connect to the server");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.Rejected:
                var rejectedResponse = (RejectedBuildResponse)response;
                LogCompilationMessage(logger, requestId, CompilationKind.ToolFallback, $"server rejected the request '{rejectedResponse.Reason}'");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.AnalyzerInconsistency:
                var analyzerResponse = (AnalyzerInconsistencyBuildResponse)response;
                var combinedMessage  = string.Join(", ", analyzerResponse.ErrorMessages.ToArray());
                LogCompilationMessage(logger, requestId, CompilationKind.ToolFallback, $"server rejected the request due to analyzer / generator issues '{combinedMessage}'");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            default:
                LogCompilationMessage(logger, requestId, CompilationKind.ToolFallback, $"server gave an unrecognized response");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }
        }
Exemple #4
0
        /// <summary>
        /// Handle a response from the server, reporting messages and returning
        /// the appropriate exit code.
        /// </summary>
        private int HandleResponse(BuildResponse response, string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            if (response.Type != BuildResponse.ResponseType.Completed)
            {
                ValidateBootstrapUtil.AddFailedServerConnection();
            }

            switch (response.Type)
            {
            case BuildResponse.ResponseType.Completed:
                var completedResponse = (CompletedBuildResponse)response;
                LogMessages(completedResponse.Output, StandardOutputImportanceToUse);

                if (LogStandardErrorAsError)
                {
                    LogErrorOutput(completedResponse.ErrorOutput);
                }
                else
                {
                    LogMessages(completedResponse.ErrorOutput, StandardErrorImportanceToUse);
                }

                return(completedResponse.ReturnCode);

            case BuildResponse.ResponseType.MismatchedVersion:
                LogErrorOutput("Roslyn compiler server reports different protocol version than build task.");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.IncorrectHash:
                LogErrorOutput("Roslyn compiler server reports different hash version than build task.");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            case BuildResponse.ResponseType.Rejected:
            case BuildResponse.ResponseType.AnalyzerInconsistency:
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));

            default:
                LogErrorOutput($"Received an unrecognized response from the server: {response.Type}");
                return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands));
            }
        }