Skip to content

Extend PropertyInitialValueSetEventArgs and PropertyReassignmentEventArgs #839

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

Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 3 additions & 9 deletions src/ResourcesGenerator/ResourceCreator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;

using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -51,6 +52,8 @@ public class ResourceCreator
"TaskFoundFromFactory",
"TaskFound",
"PropertyReassignment",
"PropertyAssignment",
"UninitializedPropertyRead",
"ProjectImported",
"ProjectImportSkippedMissingFile",
"ProjectImportSkippedInvalidFile",
Expand All @@ -66,16 +69,7 @@ public class ResourceCreator
"SearchPathsForMSBuildExtensionsPath",
"OverridingTarget",
"TryingExtensionsPath",
"ProjectImported",
"DuplicateImport",
"ProjectImportSkippedEmptyFile",
"ProjectImportSkippedFalseCondition",
"ProjectImportSkippedNoMatches",
"ProjectImportSkippedMissingFile",
"ProjectImportSkippedInvalidFile",
"PropertyReassignment",
"EvaluationStarted",
"EvaluationFinished",
"CouldNotResolveSdk",
"ProjectImportSkippedExpressionEvaluatedToEmpty",
"SkipTargetBecauseOutputsUpToDate",
Expand Down
4 changes: 3 additions & 1 deletion src/StructuredLogger/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ public sealed class BinaryLogger : ILogger
// BuildCheckTracingEvent, BuildCheckAcquisitionEvent, BuildSubmissionStartedEvent
// version 24:
// - new record kind: BuildCanceledEvent
// version 25:
// - add extra information to PropertyInitialValueSetEventArgs and PropertyReassignmentEventArgs and change parsing logic of Message property in them.

// 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 = 24;
internal const int FileFormatVersion = 25;
// 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
46 changes: 41 additions & 5 deletions src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,25 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs()
string message = fields.Message;
if (_fileFormatVersion >= 13)
{
message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location);
if (_fileFormatVersion >= 25)
{
var extendedEvent = new ExtendedPropertyReassignmentEventArgs(
propertyName,
previousValue,
newValue,
fields.File,
fields.LineNumber,
fields.ColumnNumber,
GetPropertyReassignmentMessage(propertyName, newValue, previousValue, $"{fields.File} ({fields.LineNumber},{fields.ColumnNumber})"));

SetCommonFields(extendedEvent, fields);

return extendedEvent;
}
else
{
message = GetPropertyReassignmentMessage(propertyName, newValue, previousValue, location);
}
}

var e = new PropertyReassignmentEventArgs(
Expand All @@ -1373,18 +1391,23 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs()
fields.SenderName,
fields.Importance);
SetCommonFields(e, fields);

return e;
}

private BuildEventArgs ReadUninitializedPropertyReadEventArgs()
{
var fields = ReadBuildEventArgsFields(readImportance: true);
string propertyName = ReadDeduplicatedString();
string? message = fields.Message ?? string.Empty;

if (_fileFormatVersion >= 25)
{
message = FormatResourceStringIgnoreCodeAndKeyword(Strings.UninitializedPropertyRead, propertyName);
}

var e = new UninitializedPropertyReadEventArgs(
propertyName,
fields.Message,
message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
Expand All @@ -1401,11 +1424,24 @@ private BuildEventArgs ReadPropertyInitialValueSetEventArgs()
string propertyValue = ReadDeduplicatedString();
string propertySource = ReadDeduplicatedString();

var e = new PropertyInitialValueSetEventArgs(
string message = fields.Message;
if (_fileFormatVersion >= 25)
{
string formattedSource = string.IsNullOrEmpty(fields.File)
? propertySource
: $"{fields.File} ({fields.LineNumber},{fields.ColumnNumber})";

message = FormatResourceStringIgnoreCodeAndKeyword(Strings.PropertyAssignment, propertyName, propertyValue, formattedSource);
}

var e = new ExtendedPropertyInitialValueSetEventArgs(
propertyName,
propertyValue,
propertySource,
fields.Message,
fields.File,
fields.LineNumber,
fields.ColumnNumber,
message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Build.Framework;

namespace StructuredLogger.BinaryLogger
{
internal class ExtendedPropertyInitialValueSetEventArgs : BuildMessageEventArgs
{
/// <summary>
/// Creates an instance of the <see cref="ExtendedPropertyInitialValueSetEventArgs"/> class.
/// </summary>
/// <param name="propertyName">The name of the property.</param>
/// <param name="propertyValue">The value of the property.</param>
/// <param name="propertySource">The source of the property.</param>
/// <param name="file">The file associated with the event.</param>
/// <param name="line">The line number (0 if not applicable).</param>
/// <param name="column">The column number (0 if not applicable).</param>
/// <param name="message">The message of the property.</param>
/// <param name="helpKeyword">The help keyword.</param>
/// <param name="senderName">The sender name of the event.</param>
/// <param name="importance">The importance of the message.</param>
public ExtendedPropertyInitialValueSetEventArgs(
string propertyName,
string propertyValue,
string propertySource,
string file,
int line,
int column,
string message,
string helpKeyword = null,
string senderName = null,
MessageImportance importance = MessageImportance.Low)
: base(subcategory: null, code: null, file: file, lineNumber: line, columnNumber: column, 0, 0, message, helpKeyword, senderName, importance)
{
PropertyName = propertyName;
PropertyValue = propertyValue;
PropertySource = propertySource;
}

/// <summary>
/// The name of the property.
/// </summary>
public string PropertyName { get; set; }

/// <summary>
/// The value of the property.
/// </summary>
public string PropertyValue { get; set; }

/// <summary>
/// The source of the property.
/// </summary>
public string PropertySource { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Build.Framework;

namespace StructuredLogger.BinaryLogger
{
internal class ExtendedPropertyReassignmentEventArgs : BuildMessageEventArgs
{
/// <summary>
/// Creates an instance of the <see cref="PropertyReassignmentEventArgs"/> class.
/// </summary>
/// <param name="propertyName">The name of the property whose value was reassigned.</param>
/// <param name="previousValue">The previous value of the reassigned property.</param>
/// <param name="newValue">The new value of the reassigned property.</param>
/// <param name="file">The file associated with the event.</param>
/// <param name="line">The line number (0 if not applicable).</param>
/// <param name="column">The column number (0 if not applicable).</param>
/// <param name="message">The message of the property.</param>
/// <param name="helpKeyword">The help keyword.</param>
/// <param name="senderName">The sender name of the event.</param>
/// <param name="importance">The importance of the message.</param>
public ExtendedPropertyReassignmentEventArgs(
string propertyName,
string previousValue,
string newValue,
string file,
int line,
int column,
string message,
string helpKeyword = null,
string senderName = null,
MessageImportance importance = MessageImportance.Low)
: base(subcategory: null, code: null, file: file, lineNumber: line, columnNumber: column, 0, 0, message, helpKeyword, senderName, importance)
{
PropertyName = propertyName;
PreviousValue = previousValue;
NewValue = newValue;
}

/// <summary>
/// The name of the property whose value was reassigned.
/// </summary>
public string PropertyName { get; set; }

/// <summary>
/// The previous value of the reassigned property.
/// </summary>
public string PreviousValue { get; set; }

/// <summary>
/// The new value of the reassigned property.
/// </summary>
public string NewValue { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/StructuredLogger/Strings/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ private static void InitializeRegex()
string propertyReassignment = GetPropertyReassignmentText();
PropertyReassignmentRegex = new Regex(propertyReassignment, RegexOptions.Compiled | RegexOptions.Singleline);

PropertyAssignment = GetString("PropertyAssignment");

UninitializedPropertyRead = GetString("UninitializedPropertyRead");

// MSBuild 17.6 shipped with this hardcoded to English (the first part of the regex), but it was switched to a different
// localized message in https://github.com/dotnet/msbuild/pull/8665. Support both here.
string deferredResponseFile = ("^(?:Included response file: {0}|" + GetString("PickedUpSwitchesFromAutoResponse") + ")$")
Expand Down Expand Up @@ -443,7 +447,9 @@ public static Regex CreateRegex(string text, int replacePlaceholders = 0, RegexO
public static string ProjectImportSkippedFalseCondition { get; set; }
public static string CouldNotResolveSdk { get; set; }
public static string ProjectImportSkippedExpressionEvaluatedToEmpty { get; set; }
public static string PropertyAssignment { get; set; }
public static string PropertyReassignment { get; set; }
public static string UninitializedPropertyRead { get; set; }
public static string ProjectImportSkippedNoMatches { get; set; }
public static string ProjectImportSkippedMissingFile { get; set; }
public static string ProjectImportSkippedInvalidFile { get; set; }
Expand Down
Loading