From f9b89dd0d401e4a6380f12e91350b0154a8967cf Mon Sep 17 00:00:00 2001 From: Ben Villalobos Date: Fri, 23 Aug 2019 14:06:56 -0700 Subject: [PATCH] Update to version 8 --- .../BinaryLogger/BinaryLogRecordKind.cs | 6 +- .../BinaryLogger/BinaryLogger.cs | 8 +- .../BinaryLogger/BuildEventArgsReader.cs | 90 +++++++++++++++++++ .../BinaryLogger/BuildEventArgsWriter.cs | 55 ++++++++++++ .../EnvironmentVariableReadEventArgs.cs | 37 ++++++++ .../PropertyInitialValueSetEventArgs.cs | 42 +++++++++ .../PropertyReassignmentEventArgs.cs | 62 +++++++++++++ .../UninitializedPropertyReadEventArgs.cs | 36 ++++++++ 8 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 src/StructuredLogger/BinaryLogger/EnvironmentVariableReadEventArgs.cs create mode 100644 src/StructuredLogger/BinaryLogger/PropertyInitialValueSetEventArgs.cs create mode 100644 src/StructuredLogger/BinaryLogger/PropertyReassignmentEventArgs.cs create mode 100644 src/StructuredLogger/BinaryLogger/UninitializedPropertyReadEventArgs.cs diff --git a/src/StructuredLogger/BinaryLogger/BinaryLogRecordKind.cs b/src/StructuredLogger/BinaryLogger/BinaryLogRecordKind.cs index adb012781..86897d59e 100644 --- a/src/StructuredLogger/BinaryLogger/BinaryLogRecordKind.cs +++ b/src/StructuredLogger/BinaryLogger/BinaryLogRecordKind.cs @@ -20,6 +20,10 @@ public enum BinaryLogRecordKind ProjectEvaluationFinished, ProjectImported, ProjectImportArchive, - TargetSkipped + TargetSkipped, + PropertyReassignment, + UninitializedPropertyRead, + EnvironmentVariableRead, + PropertyInitialValueSet } } diff --git a/src/StructuredLogger/BinaryLogger/BinaryLogger.cs b/src/StructuredLogger/BinaryLogger/BinaryLogger.cs index d8afc233f..42a73fc18 100644 --- a/src/StructuredLogger/BinaryLogger/BinaryLogger.cs +++ b/src/StructuredLogger/BinaryLogger/BinaryLogger.cs @@ -30,7 +30,13 @@ public sealed class BinaryLogger : ILogger // - Ids and parent ids for the evaluation locations // version 7: // - Include ProjectStartedEventArgs.GlobalProperties - internal const int FileFormatVersion = 7; + // version 8 + // - New record kinds: + // - EnvironmentVariableRead + // - PropertyInitialValueSet + // - PropertyReassignment + // - UninitializedPropertyRead + internal const int FileFormatVersion = 8; private Stream stream; private BinaryWriter binaryWriter; diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index 8f2cfbee3..adc8455db 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -111,6 +111,18 @@ public BuildEventArgs Read() case BinaryLogRecordKind.TargetSkipped: result = ReadTargetSkippedEventArgs(); break; + case BinaryLogRecordKind.PropertyReassignment: + result = ReadPropertyReassignmentEventArgs(); + break; + case BinaryLogRecordKind.UninitializedPropertyRead: + result = ReadUninitializedPropertyReadEventArgs(); + break; + case BinaryLogRecordKind.EnvironmentVariableRead: + result = ReadEnvironmentVariableReadEventArgs(); + break; + case BinaryLogRecordKind.PropertyInitialValueSet: + result = ReadPropertyInitialValueSetEventArgs(); + break; default: break; } @@ -189,6 +201,84 @@ private BuildEventArgs ReadTargetSkippedEventArgs() return e; } + private BuildEventArgs ReadPropertyReassignmentEventArgs() + { + var fields = ReadBuildEventArgsFields(); + var importance = (MessageImportance)ReadInt32(); + string propertyName = ReadString(); + string previousValue = ReadString(); + string newValue = ReadString(); + string location = ReadString(); + + var e = new PropertyReassignmentEventArgs( + propertyName, + previousValue, + newValue, + location, + fields.Message, + fields.HelpKeyword, + fields.SenderName, + importance); + SetCommonFields(e, fields); + + return e; + } + private BuildEventArgs ReadUninitializedPropertyReadEventArgs() + { + var fields = ReadBuildEventArgsFields(); + var importance = (MessageImportance)ReadInt32(); + string propertyName = ReadString(); + + var e = new UninitializedPropertyReadEventArgs( + propertyName, + fields.Message, + fields.HelpKeyword, + fields.SenderName, + importance); + SetCommonFields(e, fields); + + return e; + } + + private BuildEventArgs ReadPropertyInitialValueSetEventArgs() + { + var fields = ReadBuildEventArgsFields(); + var importance = (MessageImportance)ReadInt32(); + string propertyName = ReadString(); + string propertyValue = ReadString(); + string propertySource = ReadString(); + + var e = new PropertyInitialValueSetEventArgs( + propertyName, + propertyValue, + propertySource, + fields.Message, + fields.HelpKeyword, + fields.SenderName, + importance); + SetCommonFields(e, fields); + + return e; + } + + private BuildEventArgs ReadEnvironmentVariableReadEventArgs() + { + var fields = ReadBuildEventArgsFields(); + var importance = (MessageImportance)ReadInt32(); + + var environmentVariableName = ReadString(); + + var e = new EnvironmentVariableReadEventArgs( + environmentVariableName, + fields.Message, + fields.HelpKeyword, + fields.SenderName, + importance); + SetCommonFields(e, fields); + + return e; + } + private BuildEventArgs ReadBuildStartedEventArgs() { var fields = ReadBuildEventArgsFields(); diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs index 17e7d603f..b45766713 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs @@ -328,6 +328,29 @@ private void Write(BuildMessageEventArgs e) Write((TargetSkippedEventArgs)e); return; } + if (e is PropertyReassignmentEventArgs) + { + Write((PropertyReassignmentEventArgs)e); + return; + } + + if (e is UninitializedPropertyReadEventArgs) + { + Write((UninitializedPropertyReadEventArgs)e); + return; + } + + if (e is EnvironmentVariableReadEventArgs) + { + Write((EnvironmentVariableReadEventArgs)e); + return; + } + + if (e is PropertyInitialValueSetEventArgs) + { + Write((PropertyInitialValueSetEventArgs)e); + return; + } Write(BinaryLogRecordKind.Message); WriteMessageFields(e); @@ -352,6 +375,38 @@ private void Write(TargetSkippedEventArgs e) Write((int)e.BuildReason); } + private void Write(PropertyReassignmentEventArgs e) + { + Write(BinaryLogRecordKind.PropertyReassignment); + WriteMessageFields(e); + Write(e.PropertyName); + Write(e.PreviousValue); + Write(e.NewValue); + Write(e.Location); + } + private void Write(UninitializedPropertyReadEventArgs e) + { + Write(BinaryLogRecordKind.UninitializedPropertyRead); + WriteMessageFields(e); + Write(e.PropertyName); + } + + private void Write(PropertyInitialValueSetEventArgs e) + { + Write(BinaryLogRecordKind.PropertyInitialValueSet); + WriteMessageFields(e); + Write(e.PropertyName); + Write(e.PropertyValue); + Write(e.PropertySource); + } + + private void Write(EnvironmentVariableReadEventArgs e) + { + Write(BinaryLogRecordKind.EnvironmentVariableRead); + WriteMessageFields(e); + Write(e.EnvironmentVariableName); + } + private void Write(CriticalBuildMessageEventArgs e) { Write(BinaryLogRecordKind.CriticalBuildMessage); diff --git a/src/StructuredLogger/BinaryLogger/EnvironmentVariableReadEventArgs.cs b/src/StructuredLogger/BinaryLogger/EnvironmentVariableReadEventArgs.cs new file mode 100644 index 000000000..55b1eb75b --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/EnvironmentVariableReadEventArgs.cs @@ -0,0 +1,37 @@ +using System; + +namespace Microsoft.Build.Framework +{ + public class EnvironmentVariableReadEventArgs : BuildMessageEventArgs + { + /// + /// Initializes a new instance of the EnvironmentVariableReadEventArgs class. + /// +#if FEATURE_BINARY_SERIALIZATION + [Serializable] +#endif + public EnvironmentVariableReadEventArgs() + { + } + + /// + /// Initializes a new instance of the EnvironmentVariableReadEventArgs class. + /// + public EnvironmentVariableReadEventArgs + ( + string environmentVariableName, + string message, + string helpKeyword=null, + string senderName=null, + MessageImportance importance = MessageImportance.Low, + params object[] messageArgs + ) + : base(null, null, null, 0, 0, 0, 0, message, helpKeyword, senderName, importance, DateTime.UtcNow, messageArgs) + { + EnvironmentVariableName = environmentVariableName; + } + + + public string EnvironmentVariableName { get; set; } + } +} diff --git a/src/StructuredLogger/BinaryLogger/PropertyInitialValueSetEventArgs.cs b/src/StructuredLogger/BinaryLogger/PropertyInitialValueSetEventArgs.cs new file mode 100644 index 000000000..69448a797 --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/PropertyInitialValueSetEventArgs.cs @@ -0,0 +1,42 @@ +using System; + +namespace Microsoft.Build.Framework +{ + public class PropertyInitialValueSetEventArgs : BuildMessageEventArgs + { + /// + /// Initializes a new instance of the UninitializedPropertyRead class. + /// +#if FEATURE_BINARY_SERIALIZATION + [Serializable] +#endif + public PropertyInitialValueSetEventArgs() + { + } + + /// + /// Initializes a new instance of the UninitializedPropertyRead class. + /// + public PropertyInitialValueSetEventArgs + ( + string propertyName, + string propertyValue, + string propertySource, + string message, + string helpKeyword = null, + string senderName = null, + MessageImportance importance = MessageImportance.Low + ) : base(message, helpKeyword, senderName, importance) + { + this.PropertyName = propertyName; + this.PropertySource = propertySource; + this.PropertyValue = propertyValue; + } + + public string PropertyName { get; set; } + + public string PropertySource { get; set; } + + public string PropertyValue { get; set; } + } +} diff --git a/src/StructuredLogger/BinaryLogger/PropertyReassignmentEventArgs.cs b/src/StructuredLogger/BinaryLogger/PropertyReassignmentEventArgs.cs new file mode 100644 index 000000000..25b6c12d8 --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/PropertyReassignmentEventArgs.cs @@ -0,0 +1,62 @@ +using System; + +namespace Microsoft.Build.Framework +{ + public class PropertyReassignmentEventArgs : BuildMessageEventArgs + { + /// + /// Initializes a new instance of the PropertyReassignment class. + /// +#if FEATURE_BINARY_SERIALIZATION + [Serializable] +#endif + public PropertyReassignmentEventArgs() + { + } + + /// + /// Creates an instance of the PropertyReassignmentEventArgs class. + /// + /// The name of the property whose value was reassigned. + /// The previous value of the reassigned property. + /// The new value of the reassigned property. + /// The location of the reassignment. + public PropertyReassignmentEventArgs + ( + string propertyName, + string previousValue, + string newValue, + string location, + string message, + string helpKeyword = null, + string senderName = null, + MessageImportance importance = MessageImportance.Low + ) : base(message, helpKeyword, senderName, importance) + { + this.PropertyName = propertyName; + this.PreviousValue = previousValue; + this.NewValue = newValue; + this.Location = location; + } + + /// + /// The name of the property whose value was reassigned. + /// + public string PropertyName { get; set; } + + /// + /// The previous value of the reassigned property. + /// + public string PreviousValue { get; set; } + + /// + /// The new value of the reassigned property. + /// + public string NewValue { get; set; } + + /// + /// The location of the reassignment. + /// + public string Location { get; set; } + } +} diff --git a/src/StructuredLogger/BinaryLogger/UninitializedPropertyReadEventArgs.cs b/src/StructuredLogger/BinaryLogger/UninitializedPropertyReadEventArgs.cs new file mode 100644 index 000000000..3a497171e --- /dev/null +++ b/src/StructuredLogger/BinaryLogger/UninitializedPropertyReadEventArgs.cs @@ -0,0 +1,36 @@ +using Microsoft.Build.Logging.StructuredLogger; +using System; + +namespace Microsoft.Build.Framework +{ + public class UninitializedPropertyReadEventArgs : BuildMessageEventArgs + { + /// + /// Initializes a new instance of the UninitializedPropertyRead class. + /// +#if FEATURE_BINARY_SERIALIZATION + [Serializable] +#endif + public UninitializedPropertyReadEventArgs() + { + } + + /// + /// Initializes a new instance of the UninitializedPropertyRead class. + /// + public UninitializedPropertyReadEventArgs + ( + string propertyName, + string message, + string helpKeyword=null, + string senderName=null, + MessageImportance importance = MessageImportance.Low, + params object[] messageArgs + ) : base(message, helpKeyword, senderName, importance) + { + this.PropertyName = propertyName; + } + + public string PropertyName { get; set; } + } +}