From c44ed28e73ca2581ad496b6b279df5d61c859029 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:02:19 +0200 Subject: [PATCH] Fix bin log population + emitting extra event on custom check registration (#10558) --- .../BuildCheckManagerProvider.cs | 21 ++++++++------ .../BinaryLogger/BuildEventArgsReader.cs | 29 +++++++------------ .../BinaryLogger/BuildEventArgsWriter.cs | 10 ------- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs index c152982551d..96a57e974ef 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs @@ -191,16 +191,19 @@ internal void RegisterCustomCheck( foreach (var factory in factories) { var instance = factory(); - var checkFactoryContext = new CheckFactoryContext( - factory, - instance.SupportedRules.Select(r => r.Id).ToArray(), - instance.SupportedRules.Any(r => r.DefaultConfiguration.IsEnabled == true)); - - if (checkFactoryContext != null) + if (instance != null && instance.SupportedRules.Any()) { - _checkRegistry.Add(checkFactoryContext); - SetupSingleCheck(checkFactoryContext, projectPath); - checkContext.DispatchAsComment(MessageImportance.Normal, "CustomCheckSuccessfulAcquisition", instance.FriendlyName); + var checkFactoryContext = new CheckFactoryContext( + factory, + instance.SupportedRules.Select(r => r.Id).ToArray(), + instance.SupportedRules.Any(r => r.DefaultConfiguration.IsEnabled == true)); + + if (checkFactoryContext != null) + { + _checkRegistry.Add(checkFactoryContext); + SetupSingleCheck(checkFactoryContext, projectPath); + checkContext.DispatchAsComment(MessageImportance.Normal, "CustomCheckSuccessfulAcquisition", instance.FriendlyName); + } } } } diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs index 9de51e2a05d..dc7b097be1a 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs @@ -321,8 +321,8 @@ void HandleError(FormatErrorMessage msgFactory, bool noThrow, ReaderErrorType re BinaryLogRecordKind.PropertyInitialValueSet => ReadPropertyInitialValueSetEventArgs(), BinaryLogRecordKind.AssemblyLoad => ReadAssemblyLoadEventArgs(), BinaryLogRecordKind.BuildCheckMessage => ReadBuildCheckMessageEventArgs(), - BinaryLogRecordKind.BuildCheckWarning => ReadBuildCheckWarningEventArgs(), - BinaryLogRecordKind.BuildCheckError => ReadBuildCheckErrorEventArgs(), + BinaryLogRecordKind.BuildCheckWarning => ReadBuildWarningEventArgs(), + BinaryLogRecordKind.BuildCheckError => ReadBuildErrorEventArgs(), BinaryLogRecordKind.BuildCheckTracing => ReadBuildCheckTracingEventArgs(), BinaryLogRecordKind.BuildCheckAcquisition => ReadBuildCheckAcquisitionEventArgs(), _ => null @@ -1218,6 +1218,15 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs() return e; } + private BuildEventArgs ReadBuildCheckMessageEventArgs() + { + var fields = ReadBuildEventArgsFields(); + var e = new BuildCheckResultMessage(fields.Message); + SetCommonFields(e, fields); + + return e; + } + private AssemblyLoadBuildEventArgs ReadAssemblyLoadEventArgs() { var fields = ReadBuildEventArgsFields(readImportance: false); @@ -1242,22 +1251,6 @@ private AssemblyLoadBuildEventArgs ReadAssemblyLoadEventArgs() return e; } - private BuildEventArgs ReadBuildCheckEventArgs(Func createEvent) - where T : BuildEventArgs - { - var fields = ReadBuildEventArgsFields(); - var e = createEvent(fields, fields.Message); - SetCommonFields(e, fields); - - return e; - } - - private BuildEventArgs ReadBuildCheckMessageEventArgs() => ReadBuildCheckEventArgs((_, rawMessage) => new BuildCheckResultMessage(rawMessage)); - - private BuildEventArgs ReadBuildCheckWarningEventArgs() => ReadBuildCheckEventArgs((fields, rawMessage) => new BuildCheckResultWarning(rawMessage, fields.Code)); - - private BuildEventArgs ReadBuildCheckErrorEventArgs() => ReadBuildCheckEventArgs((fields, rawMessage) => new BuildCheckResultError(rawMessage, fields.Code)); - private BuildEventArgs ReadBuildCheckTracingEventArgs() { var fields = ReadBuildEventArgsFields(); diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs index b5d7f6fb73c..294d96bae2c 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs @@ -479,11 +479,6 @@ private BinaryLogRecordKind Write(TaskFinishedEventArgs e) private BinaryLogRecordKind Write(BuildErrorEventArgs e) { - if (e is BuildCheckResultError buildCheckError) - { - return Write(buildCheckError); - } - WriteBuildEventArgsFields(e); WriteArguments(e.RawArguments); WriteDeduplicatedString(e.Subcategory); @@ -500,11 +495,6 @@ private BinaryLogRecordKind Write(BuildErrorEventArgs e) private BinaryLogRecordKind Write(BuildWarningEventArgs e) { - if (e is BuildCheckResultWarning buildCheckWarning) - { - return Write(buildCheckWarning); - } - WriteBuildEventArgsFields(e); WriteArguments(e.RawArguments); WriteDeduplicatedString(e.Subcategory);