Skip to content

Commit

Permalink
Fix bin log population + emitting extra event on custom check registr…
Browse files Browse the repository at this point in the history
…ation (#10558)
  • Loading branch information
YuliiaKovalova authored Aug 23, 2024
1 parent 9b15d8b commit c44ed28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
21 changes: 12 additions & 9 deletions src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
29 changes: 11 additions & 18 deletions src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -1242,22 +1251,6 @@ private AssemblyLoadBuildEventArgs ReadAssemblyLoadEventArgs()
return e;
}

private BuildEventArgs ReadBuildCheckEventArgs<T>(Func<BuildEventArgsFields, string, T> 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();
Expand Down
10 changes: 0 additions & 10 deletions src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c44ed28

Please sign in to comment.