Skip to content

Commit

Permalink
Merge pull request #793 from JanKrivanek/proto/Env-vars-args-update
Browse files Browse the repository at this point in the history
Update Log format to recognize changes in EnvVarArgs
  • Loading branch information
KirillOsenkov authored Jul 26, 2024
2 parents ad09966 + e1513eb commit d7462fa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/StructuredLogger/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public sealed class BinaryLogger : ILogger
// - TaskStartedEventArgs: Added TaskAssemblyLocation property
// version 21:
// - TaskParameterEventArgs: Added ParameterName and PropertyName properties
// version 22:
// - extend EnvironmentVariableRead with location where environment variable was used.

// 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 = 21;
internal const int FileFormatVersion = 22;
// 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
22 changes: 16 additions & 6 deletions src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.Build.Framework.Profiler;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using StructuredLogger.BinaryLogger;

namespace Microsoft.Build.Logging.StructuredLogger
{
Expand Down Expand Up @@ -1223,13 +1224,22 @@ private BuildEventArgs ReadEnvironmentVariableReadEventArgs()
var fields = ReadBuildEventArgsFields(readImportance: true);

var environmentVariableName = ReadDeduplicatedString();
int line = 0;
int column = 0;
string? fileName = null;
if (_fileFormatVersion >= 22)
{
line = ReadInt32();
column = ReadInt32();
fileName = ReadDeduplicatedString();
}

var e = new EnvironmentVariableReadEventArgs(
environmentVariableName,
fields.Message,
fields.HelpKeyword,
fields.SenderName,
fields.Importance);
var e = new EnvironmentVariableReadEventArgs2(
environmentVariableName ?? string.Empty,
fields.Message,
fileName ?? string.Empty,
line,
column);
SetCommonFields(e, fields);

return e;
Expand Down
5 changes: 4 additions & 1 deletion src/StructuredLogger/BinaryLogger/BuildEventArgsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@ private BinaryLogRecordKind Write(PropertyInitialValueSetEventArgs e)

private BinaryLogRecordKind Write(EnvironmentVariableReadEventArgs e)
{
WriteMessageFields(e, writeImportance: true);
WriteMessageFields(e, writeImportance: false);
WriteDeduplicatedString(e.EnvironmentVariableName);
Write(e.LineNumber);
Write(e.ColumnNumber);
WriteDeduplicatedString(e.File);

return BinaryLogRecordKind.EnvironmentVariableRead;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.Build.Framework;

namespace StructuredLogger.BinaryLogger
{
public class EnvironmentVariableReadEventArgs2 : EnvironmentVariableReadEventArgs
{
/// <summary>
/// Initializes an instance of the EnvironmentVariableReadEventArgs class.
/// </summary>
/// <param name="environmentVarName">The name of the environment variable that was read.</param>
/// <param name="environmentVarValue">The value of the environment variable that was read.</param>
/// <param name="file">file associated with the event</param>
/// <param name="line">line number (0 if not applicable)</param>
/// <param name="column">column number (0 if not applicable)</param>
public EnvironmentVariableReadEventArgs2(
string environmentVarName,
string environmentVarValue,
string file,
int line,
int column)
: base(environmentVarName, environmentVarValue)
{
LineNumber = line;
ColumnNumber = column;
File = file;
}

// the properties in the base class have an internal setter
public new int LineNumber { get; set; }
public new int ColumnNumber { get; set; }
public new string File { get; set; }
}
}

0 comments on commit d7462fa

Please sign in to comment.