Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new event type BuildCanceled #824

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/StructuredLogger/BinaryLogger/BinaryLogRecordKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public enum BinaryLogRecordKind
BuildCheckTracing,
BuildCheckAcquisition,
BuildSubmissionStarted,
BuildCanceled,
}
}
4 changes: 3 additions & 1 deletion src/StructuredLogger/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ public sealed class BinaryLogger : ILogger
// version 23:
// - new record kinds: BuildCheckMessageEvent, BuildCheckWarningEvent, BuildCheckErrorEvent,
// BuildCheckTracingEvent, BuildCheckAcquisitionEvent, BuildSubmissionStartedEvent
// version 24:
// - new record kind: BuildCanceledEvent

// This should be never changed.
// The minimum version of the binary log reader that can read log of above version.
internal const int ForwardCompatibilityMinimalVersion = 18;

// The current version of the binary log representation.
// Changes with each update of the binary log format.
internal const int FileFormatVersion = 23;
internal const int FileFormatVersion = 24;
// The minimum version of the binary log reader that can read log of above version.
// This should be changed only when the binary log format is changed in a way that would prevent it from being
// read by older readers. (changing of the individual BuildEventArgs or adding new is fine - as reader can
Expand Down
45 changes: 45 additions & 0 deletions src/StructuredLogger/BinaryLogger/BuildCanceledEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;

namespace StructuredLogger.BinaryLogger
{
/// <summary>
/// This class represents the event arguments for build canceled events.
/// </summary>
internal sealed class BuildCanceledEventArgs : Microsoft.Build.Framework.BuildStatusEventArgs
{

/// <summary>
/// Constructor which allows the timestamp to be set.
/// </summary>
/// <param name="message">text message</param>
/// <param name="eventTimestamp">Timestamp when the event was created</param>
public BuildCanceledEventArgs(
string message,
DateTime eventTimestamp)
: this(message, eventTimestamp, null)
{
}

/// <summary>
/// Constructor which allows the timestamp to be set.
/// </summary>
/// <param name="message">text message</param>
/// <param name="eventTimestamp">Timestamp when the event was created</param>
/// <param name="messageArgs">message arguments</param>
public BuildCanceledEventArgs(
string message,
DateTime eventTimestamp,
params object[]? messageArgs)
: base(message, null, "MSBuild", eventTimestamp, messageArgs)
{
if (string.IsNullOrWhiteSpace(message))
{
throw new ArgumentException("Message cannot be null or consist only white-space characters.");
}
}
}
}
12 changes: 11 additions & 1 deletion src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ void HandleError(FormatErrorMessage msgFactory, bool noThrow, ReaderErrorType re
BinaryLogRecordKind.BuildCheckTracing => ReadBuildCheckTracingEventArgs(),
BinaryLogRecordKind.BuildCheckAcquisition => ReadBuildCheckAcquisitionEventArgs(),
BinaryLogRecordKind.BuildSubmissionStarted => ReadBuildSubmissionStartedEventArgs(),
BinaryLogRecordKind.BuildCanceled => ReadBuildCanceledEventArgs(),
_ => null,

};
Expand Down Expand Up @@ -711,6 +712,15 @@ private BuildEventArgs ReadBuildFinishedEventArgs()
SetCommonFields(e, fields);
return e;
}
private BuildEventArgs ReadBuildCanceledEventArgs()
{
var fields = ReadBuildEventArgsFields();
var e = new BuildCanceledEventArgs(
fields.Message,
fields.Timestamp);
SetCommonFields(e, fields);
return e;
}

private BuildEventArgs ReadProjectEvaluationStartedEventArgs()
{
Expand Down Expand Up @@ -1287,7 +1297,7 @@ private BuildEventArgs ReadBuildCheckAcquisitionEventArgs()
private BuildEventArgs ReadBuildSubmissionStartedEventArgs()
{
var fields = ReadBuildEventArgsFields(readImportance: false);
var e = new BuildSubmissionStartedEvent();
var e = new BuildSubmissionStartedEventArgs();

var globalProperties = ReadStringDictionary();
var entries = ReadStringList();
Expand Down
12 changes: 10 additions & 2 deletions src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Base types and inheritance ("EventArgs" suffix omitted):
ProjectFinished
BuildStarted
BuildFinished
BuildCanceled
ProjectEvaluationStarted
ProjectEvaluationFinished
BuildError
Expand Down Expand Up @@ -211,7 +212,8 @@ private BinaryLogRecordKind WriteCore(BuildEventArgs e)
case ProjectFinishedEventArgs projectFinished: return Write(projectFinished);
case BuildStartedEventArgs buildStarted: return Write(buildStarted);
case BuildFinishedEventArgs buildFinished: return Write(buildFinished);
case BuildSubmissionStartedEvent buildSubmissionStarted: return Write(buildSubmissionStarted);
case BuildCanceledEventArgs buildCanceled: return Write(buildCanceled);
case BuildSubmissionStartedEventArgs buildSubmissionStarted: return Write(buildSubmissionStarted);
case ProjectEvaluationStartedEventArgs projectEvaluationStarted: return Write(projectEvaluationStarted);
case ProjectEvaluationFinishedEventArgs projectEvaluationFinished: return Write(projectEvaluationFinished);
case BuildCheckTracingEventArgs buildCheckTracing: return Write(buildCheckTracing);
Expand Down Expand Up @@ -311,6 +313,12 @@ private BinaryLogRecordKind Write(BuildFinishedEventArgs e)
return BinaryLogRecordKind.BuildFinished;
}

private BinaryLogRecordKind Write(BuildCanceledEventArgs e)
{
WriteBuildEventArgsFields(e);
return BinaryLogRecordKind.BuildCanceled;
}

private BinaryLogRecordKind Write(ProjectEvaluationStartedEventArgs e)
{
WriteBuildEventArgsFields(e, writeMessage: false);
Expand All @@ -336,7 +344,7 @@ private BinaryLogRecordKind Write(BuildCheckAcquisitionEventArgs e)
return BinaryLogRecordKind.BuildCheckAcquisition;
}

private BinaryLogRecordKind Write(BuildSubmissionStartedEvent e)
private BinaryLogRecordKind Write(BuildSubmissionStartedEventArgs e)
{
WriteBuildEventArgsFields(e, writeMessage: false);
Write(e.GlobalProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace StructuredLogger.BinaryLogger
{
internal class BuildSubmissionStartedEvent()
internal class BuildSubmissionStartedEventArgs()
: BuildStatusEventArgs(message: "", helpKeyword: null, senderName: null, eventTimestamp: DateTime.UtcNow)
{
public IDictionary<string, string?> GlobalProperties { get; set; }
Expand Down
13 changes: 12 additions & 1 deletion src/StructuredLogger/Construction/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Build.Collections;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
using StructuredLogger.BinaryLogger;

namespace Microsoft.Build.Logging.StructuredLogger
{
Expand Down Expand Up @@ -512,7 +513,17 @@ public void StatusEventRaised(object sender, BuildStatusEventArgs e)
{
lock (syncLock)
{
if (e is ProjectEvaluationStartedEventArgs projectEvaluationStarted)
// If the build was canceled we want to show a message in the build log view.
if (e is BuildCanceledEventArgs buildCanceledEventArgs)
JanProvaznik marked this conversation as resolved.
Show resolved Hide resolved
{
messageProcessor.Process(new BuildMessageEventArgs(
Intern(buildCanceledEventArgs.Message),
Intern(buildCanceledEventArgs.HelpKeyword),
Intern(buildCanceledEventArgs.SenderName),
MessageImportance.High,
buildCanceledEventArgs.Timestamp));
}
else if (e is ProjectEvaluationStartedEventArgs projectEvaluationStarted)
{
var evaluationId = projectEvaluationStarted.BuildEventContext.EvaluationId;
var projectFilePath = Intern(projectEvaluationStarted.ProjectFile);
Expand Down