From e6a4ed9e2e0e936ccf15d02b640f9240638c83d6 Mon Sep 17 00:00:00 2001 From: Sl4vP0weR <42337892+Sl4vP0weR@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:41:41 +0800 Subject: [PATCH] Add exit code to the compatibility tool. --- .../ValidateAssemblies.cs | 4 +++- .../Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs | 4 +++- .../ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs index b147db6370a1..30d47f85e86e 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.ApiCompat { internal static class ValidateAssemblies { - public static void Run(Func logFactory, + public static int Run(Func logFactory, bool generateSuppressionFile, bool preserveUnnecessarySuppressions, bool permitUnnecessarySuppressions, @@ -100,6 +100,8 @@ public static void Run(Func logFactory, { SuppressionFileHelper.ValidateUnnecessarySuppressions(serviceProvider.SuppressionEngine, serviceProvider.SuppressibleLog); } + + return serviceProvider.SuppressibleLog.HasLoggedErrorSuppressions ? 1 : 0; } private static string[]? GetAssemblyReferences(string[][]? assemblyReferences, int counter) diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs index 94e222fbdbc5..1b82442c985d 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidatePackage.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.ApiCompat { internal static class ValidatePackage { - public static void Run(Func logFactory, + public static int Run(Func logFactory, bool generateSuppressionFile, bool preserveUnnecessarySuppressions, bool permitUnnecessarySuppressions, @@ -96,6 +96,8 @@ public static void Run(Func logFactory, { SuppressionFileHelper.ValidateUnnecessarySuppressions(serviceProvider.SuppressionEngine, serviceProvider.SuppressibleLog); } + + return serviceProvider.SuppressibleLog.HasLoggedErrorSuppressions ? 1 : 0; } } } diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs index 4b3119049b83..cb248930e153 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Program.cs @@ -197,7 +197,7 @@ static int Main(string[] args) (string, string)[]? rightAssembliesTransformationPattern = parseResult.GetValue(rightAssembliesTransformationPatternOption); SuppressibleConsoleLog logFactory(ISuppressionEngine suppressionEngine) => new(suppressionEngine, verbosity); - ValidateAssemblies.Run(logFactory, + int exitCode = ValidateAssemblies.Run(logFactory, generateSuppressionFile, preserveUnnecessarySuppressions, permitUnnecessarySuppressions, @@ -218,6 +218,8 @@ static int Main(string[] args) rightAssembliesTransformationPattern); roslynResolver.Unregister(); + + return exitCode; }); // Package command @@ -319,7 +321,7 @@ static int Main(string[] args) string[]? baselinePackageFrameworksToIgnore = parseResult.GetValue(baselinePackageFrameworksToIgnoreOption); SuppressibleConsoleLog logFactory(ISuppressionEngine suppressionEngine) => new(suppressionEngine, verbosity); - ValidatePackage.Run(logFactory, + int exitCode = ValidatePackage.Run(logFactory, generateSuppressionFile, preserveUnnecessarySuppressions, permitUnnecessarySuppressions, @@ -342,6 +344,8 @@ static int Main(string[] args) baselinePackageFrameworksToIgnore); roslynResolver.Unregister(); + + return exitCode; }); rootCommand.Subcommands.Add(packageCommand);