Created
May 15, 2022 21:13
-
-
Save NickCraver/e1c007da29e681b0f5c1e92d1e323dec to your computer and use it in GitHub Desktop.
MSBuild Dupe WriteChecker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by https://github.com/dotnet/roslyn/blob/main/src/Tools/BuildBoss/StructuredLoggerCheckerUtil.cs#L33 | |
// Licensed to the .NET Foundation under one or more agreements. | |
using System; | |
using Microsoft.Build.Logging.StructuredLogger; | |
// Invokes the analyzer here: | |
// https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/master/src/StructuredLogger/Analyzers/DoubleWritesAnalyzer.cs | |
string _logFilePath = System.IO.Path.GetFullPath(args[0]); | |
Console.WriteLine($"Running MSBuild binlog checks for '{_logFilePath}'"); | |
try | |
{ | |
bool doubleWritesPresent = false; | |
var build = Serialization.Read(_logFilePath); | |
if (!build.Succeeded) | |
{ | |
Console.Error.WriteLine($" Error reading binlog at '{_logFilePath}'"); | |
return 2; | |
} | |
foreach (var doubleWrite in DoubleWritesAnalyzer.GetDoubleWrites(build)) | |
{ | |
doubleWritesPresent = true; | |
Console.Error.WriteLine($" Multiple writes to {doubleWrite.Key}"); | |
foreach (var source in doubleWrite.Value) | |
{ | |
Console.Error.WriteLine($" {source}"); | |
} | |
Console.Error.WriteLine(); | |
} | |
if (!doubleWritesPresent) | |
{ | |
Console.WriteLine(" No duplicate writes found."); | |
return 0; | |
} | |
return 1; | |
} | |
catch (Exception ex) | |
{ | |
Console.Error.WriteLine($" Error processing binary log file: {ex.Message}"); | |
return 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment