Skip to content
Draft
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
31 changes: 31 additions & 0 deletions src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,37 @@ public void BinlogFileNameWildcardGeneration()
File.Create(_logFile).Dispose();
}

[Fact]
public void BinaryLogReplayEventSource_ShouldAllowForwardCompatibility()
{
// This test verifies that BinaryLogReplayEventSource can be configured
// to allow forward compatibility with newer binlog versions
// The fact that this compiles and doesn't throw verifies the feature works
var replayEventSource = new BinaryLogReplayEventSource
{
AllowForwardCompatibility = true
};

// If we got here without exception, the property setter works
replayEventSource.ShouldNotBeNull();

// Create the required binlog file for test cleanup
File.Create(_logFile).Dispose();
}

[Fact]
public void BinaryLogger_FileFormatVersion_ShouldBePublic()
{
// This test verifies that the FileFormatVersion constant is publicly accessible
// This is needed for version comparison in command-line tools
int version = BinaryLogger.FileFormatVersion;
version.ShouldBeGreaterThan(0);
version.ShouldBe(25); // Current version as of this test

// Create the required binlog file for test cleanup
File.Create(_logFile).Dispose();
}

public void Dispose()
{
_env.Dispose();
Expand Down
7 changes: 4 additions & 3 deletions src/Build/Logging/BinaryLogger/BinaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ public sealed class BinaryLogger : ILogger
// 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 = 25;
/// <summary>
/// The current version of the binary log file format that this version of MSBuild supports.
/// </summary>
public 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
Expand Down
23 changes: 21 additions & 2 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3889,7 +3889,17 @@ private static void ReplayBinaryLog(
bool isBuildCheckEnabled)
{

var replayEventSource = new BinaryLogReplayEventSource();
var replayEventSource = new BinaryLogReplayEventSource()
{
AllowForwardCompatibility = true
};

// Subscribe to RecoverableReadError to handle forward compatibility issues
replayEventSource.RecoverableReadError += e =>
{
// Output recoverable errors as warnings to the console
Console.WriteLine(e.GetFormattedMessage());
};

var eventSource = isBuildCheckEnabled ?
BuildCheckReplayModeConnector.GetMergedEventSource(BuildManager.DefaultBuildManager, replayEventSource) :
Expand Down Expand Up @@ -3922,7 +3932,16 @@ private static void ReplayBinaryLog(

try
{
replayEventSource.Replay(binaryLogFilePath, s_buildCancellationSource.Token);
// Use the BinaryReader overload to ensure AllowForwardCompatibility is respected
using var binaryReader = BinaryLogReplayEventSource.OpenReader(binaryLogFilePath);
replayEventSource.Replay(binaryReader, s_buildCancellationSource.Token);

// Emit a warning if the log file version is newer than what we support
if (replayEventSource.FileFormatVersion > BinaryLogger.FileFormatVersion)
{
var warningMessage = $"The log file format version is {replayEventSource.FileFormatVersion} with minimum required reader version {replayEventSource.MinimumReaderVersion}, whereas this version of MSBuild only supports versions up to {BinaryLogger.FileFormatVersion}.";
Console.WriteLine(warningMessage);
}
}
catch (Exception ex)
{
Expand Down