Skip to content

Commit

Permalink
Tolerate breaking changes in BDN >= 0.13.8-nightly.20230901.67
Browse files Browse the repository at this point in the history
Supports BDN 0.13.7 and nightly builds up to at least BDN 0.13.8-nightly.20230901.67
Closes #263, closes #259.
  • Loading branch information
mawosoft committed Sep 3, 2023
1 parent caa6591 commit d86ac0a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2021-2023 Matthias Wolf, Mawosoft.

namespace Mawosoft.Extensions.BenchmarkDotNet.ApiCompat;

internal static class SummaryWrapper
{
private static readonly ConstructorInfo? s_ctorStable;
private static readonly ConstructorInfo? s_ctorNightly;

[SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline",
Justification = "Multiple interdependent fields.")]
static SummaryWrapper()
{
s_ctorStable = typeof(Summary).GetConstructor(new[]
{
typeof(string),
typeof(ImmutableArray<BenchmarkReport>),
typeof(HostEnvironmentInfo),
typeof(string),
typeof(string),
typeof(TimeSpan),
typeof(CultureInfo),
typeof(ImmutableArray<ValidationError>),
typeof(ImmutableArray<IColumnHidingRule>)
});
if (s_ctorStable is null)
{
s_ctorNightly = typeof(Summary).GetConstructor(new[]
{
typeof(string),
typeof(ImmutableArray<BenchmarkReport>),
typeof(HostEnvironmentInfo),
typeof(string),
typeof(string),
typeof(TimeSpan),
typeof(CultureInfo),
typeof(ImmutableArray<ValidationError>),
typeof(ImmutableArray<IColumnHidingRule>),
typeof(SummaryStyle)
});
}
}

public static Summary Create(
string title,
ImmutableArray<BenchmarkReport> reports,
HostEnvironmentInfo hostEnvironmentInfo,
string resultsDirectoryPath,
string logFilePath,
TimeSpan totalTime,
CultureInfo cultureInfo,
ImmutableArray<ValidationError> validationErrors,
ImmutableArray<IColumnHidingRule> columnHidingRules,
SummaryStyle? summaryStyle = null)
{
if (s_ctorStable != null)
{
return (Summary)s_ctorStable.Invoke(new object?[]
{
title,
reports,
hostEnvironmentInfo,
resultsDirectoryPath,
logFilePath,
totalTime,
cultureInfo,
validationErrors,
columnHidingRules
});
}
else if (s_ctorNightly != null)
{
return (Summary)s_ctorNightly.Invoke(new object?[]
{
title,
reports,
hostEnvironmentInfo,
resultsDirectoryPath,
logFilePath,
totalTime,
cultureInfo,
validationErrors,
columnHidingRules,
summaryStyle
});
}
else
{
throw new MissingMethodException(nameof(Summary), ".ctor");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private class MockMetricDescriptor : IMetricDescriptor
ExecuteResult[] executeResults = new[] { ExecuteResultWrapper.Create(allMeasurements, default, default, default) };
Metric[] metrics = new[] { new Metric(new MockMetricDescriptor(), 1) };
BenchmarkReport benchmarkReport = new(true, benchmarkCase, generateResult, buildResult, executeResults, metrics);
return new Summary(
return SummaryWrapper.Create(
string.Empty, ImmutableArray.Create(benchmarkReport), HostEnvironmentInfo.GetCurrent(),
string.Empty, string.Empty, TimeSpan.Zero, SummaryExtensions.GetCultureInfo(null),
ImmutableArray.Create<ValidationError>(), ImmutableArray.Create<IColumnHidingRule>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PackageReleaseNotes>This release supports BenchmarkDotNet 0.13.7 and BDN nightly builds up to at least 0.13.8-nightly.20230810.60</PackageReleaseNotes>
<PackageReleaseNotes>This release supports BenchmarkDotNet 0.13.7 and BDN nightly builds up to at least 0.13.8-nightly.20230901.67</PackageReleaseNotes>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>0.2.1</PackageValidationBaselineVersion>
</PropertyGroup>
Expand Down
14 changes: 8 additions & 6 deletions src/Mawosoft.Extensions.BenchmarkDotNet/WhatifFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ public void PrintAsSummaries(ILogger logger)
logger.WriteLineInfo(HostEnvironmentInfo.GetInformation());
if (joinedConfig is not null)
{
Summary summary = new(string.Empty, reports.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
joinedConfig.GetColumnHidingRules().ToImmutableArray());
Summary summary = SummaryWrapper.Create(
string.Empty, reports.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
joinedConfig.GetColumnHidingRules().ToImmutableArray());
PrintSummary(summary, logger);
}
else
Expand All @@ -132,9 +133,10 @@ public void PrintAsSummaries(ILogger logger)
foreach (IGrouping<Type, BenchmarkReport> group in
reports.GroupBy(r => r.BenchmarkCase.Descriptor.Type))
{
Summary summary = new(string.Empty, group.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
group.First().BenchmarkCase.Config.GetColumnHidingRules().ToImmutableArray());
Summary summary = SummaryWrapper.Create(
string.Empty, group.ToImmutableArray(), hostEnvironmentInfo,
string.Empty, string.Empty, TimeSpan.Zero, cultureInfo, validationErrors,
group.First().BenchmarkCase.Config.GetColumnHidingRules().ToImmutableArray());
logger.WriteLine();
logger.WriteLineHeader($"// {(useFullName ? group.Key.FullName : group.Key.Name)}");
logger.WriteLine();
Expand Down

0 comments on commit d86ac0a

Please sign in to comment.