From 8e2cb8f9eeed1c4544e9331d0117d5dae4c755b7 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 24 May 2024 17:55:03 +0200 Subject: [PATCH 1/2] BC forwarding logger --- .../BuildCheckConnectorLogger.cs | 8 +++ .../BuildCheckForwardingLogger.cs | 68 ++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs index 7dad5f0c4da..3ad1ba9cf5e 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs @@ -12,6 +12,14 @@ namespace Microsoft.Build.Experimental.BuildCheck.Infrastructure; +/// +/// Central logger for the build check infrastructure. +/// Receives events from the . +/// Processes the events and forwards them to the and registered analyzers. +/// +/// +/// Ensure that the consuming events are in sync with . +/// internal sealed class BuildCheckConnectorLogger : ILogger { private readonly Dictionary> _eventHandlers; diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs index 6e8f969b544..d5b0f073f62 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs @@ -7,13 +7,75 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Build.BackEnd.Logging; +using Microsoft.Build.Experimental.BuildCheck.Acquisition; +using Microsoft.Build.Framework; +using static Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckManagerProvider; namespace Microsoft.Build.Experimental.BuildCheck.Infrastructure; /// /// Forwarding logger for the build check infrastructure. -/// For now we jus want to forward all events, while disable verbose logging of tasks. +/// For now we just want to forward all events that are needed for BuildCheckConnectorLogger and filter out all other. +/// If the custom analyzer is detected, starts to unconditionally forward all events. /// In the future we may need more specific behavior. /// -internal class BuildCheckForwardingLogger : CentralForwardingLogger -{ } +/// +/// Ensure that events filtering is in sync with +/// +internal class BuildCheckForwardingLogger : IForwardingLogger +{ + public IEventRedirector? BuildEventRedirector { get; set; } + + public int NodeId { get; set; } + + public LoggerVerbosity Verbosity { get => LoggerVerbosity.Quiet; set { return; } } + + public string? Parameters { get; set; } + + /// + /// Set of events to be forwarded to + /// + private HashSet _eventsToForward = new HashSet + { + typeof(ProjectEvaluationFinishedEventArgs), + typeof(ProjectEvaluationStartedEventArgs), + typeof(ProjectStartedEventArgs), + typeof(ProjectFinishedEventArgs), + typeof(BuildCheckTracingEventArgs), + typeof(BuildCheckAcquisitionEventArgs), + typeof(TaskStartedEventArgs), + typeof(TaskFinishedEventArgs), + typeof(TaskParameterEventArgs) + }; + + private bool _customAnalyzerDetected; + + public void Initialize(IEventSource eventSource, int nodeCount) => Initialize(eventSource); + + public void Initialize(IEventSource eventSource) + { + _customAnalyzerDetected = false; + eventSource.AnyEventRaised += EventSource_AnyEventRaised; + } + + public void EventSource_AnyEventRaised(object sender, BuildEventArgs buildEvent) + { + if (_customAnalyzerDetected) + { + BuildEventRedirector?.ForwardEvent(buildEvent); + return; + } + + if (_eventsToForward.Contains(buildEvent.GetType())) + { + if (buildEvent is BuildCheckAcquisitionEventArgs) + { + _customAnalyzerDetected = true; + } + + BuildEventRedirector?.ForwardEvent(buildEvent); + } + } + + public void Shutdown() { } +} From 20f74b5334e6b848d020d5856a5d8e9c39983975 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:04:15 +0200 Subject: [PATCH 2/2] Remove custom analyser detection --- .../Infrastructure/BuildCheckForwardingLogger.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs index d5b0f073f62..81dffca84ff 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs @@ -48,31 +48,17 @@ internal class BuildCheckForwardingLogger : IForwardingLogger typeof(TaskParameterEventArgs) }; - private bool _customAnalyzerDetected; - public void Initialize(IEventSource eventSource, int nodeCount) => Initialize(eventSource); public void Initialize(IEventSource eventSource) { - _customAnalyzerDetected = false; eventSource.AnyEventRaised += EventSource_AnyEventRaised; } public void EventSource_AnyEventRaised(object sender, BuildEventArgs buildEvent) { - if (_customAnalyzerDetected) - { - BuildEventRedirector?.ForwardEvent(buildEvent); - return; - } - if (_eventsToForward.Contains(buildEvent.GetType())) { - if (buildEvent is BuildCheckAcquisitionEventArgs) - { - _customAnalyzerDetected = true; - } - BuildEventRedirector?.ForwardEvent(buildEvent); } }