Skip to content

Commit 861cd2f

Browse files
committed
Force older DotNetCli partitions to build sequentially.
Revert sdk validator.
1 parent d4990ee commit 861cd2f

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using BenchmarkDotNet.Mathematics;
2222
using BenchmarkDotNet.Reports;
2323
using BenchmarkDotNet.Toolchains;
24+
using BenchmarkDotNet.Toolchains.DotNetCli;
2425
using BenchmarkDotNet.Toolchains.Parameters;
2526
using BenchmarkDotNet.Toolchains.Results;
2627
using BenchmarkDotNet.Validators;
@@ -81,17 +82,21 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
8182
compositeLogger.WriteLineHeader($"// ***** Found {totalBenchmarkCount} benchmark(s) in total *****");
8283
var globalChronometer = Chronometer.Start();
8384

85+
var buildPartitions = BenchmarkPartitioner.CreateForBuild(supportedBenchmarks, resolver);
8486

85-
var parallelBuildBenchmarks = supportedBenchmarks.Where(x => !x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)).ToArray();
86-
var parallelBuildPartitions = BenchmarkPartitioner.CreateForBuild(parallelBuildBenchmarks, resolver);
87+
static bool ShouldBuildSequential(BuildPartition partition)
88+
=> partition.RepresentativeBenchmarkCase.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)
89+
// .Net SDK 8+ supports ArtifactsPath for proper parallel builds.
90+
// Older SDKs may produce builds with incorrect bindings if more than 1 partition is built in parallel.
91+
|| (partition.RepresentativeBenchmarkCase.GetToolchain().Generator is DotNetCliGenerator && partition.RepresentativeBenchmarkCase.GetRuntime().RuntimeMoniker < RuntimeMoniker.Net80);
8792

88-
var sequentialBuildBenchmarks = supportedBenchmarks.Where(x => x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)).ToArray();
89-
var sequentialBuildPartitions = BenchmarkPartitioner.CreateForBuild(sequentialBuildBenchmarks, resolver);
93+
var parallelBuildPartitions = buildPartitions.Where(x => !ShouldBuildSequential(x)).ToArray();
94+
var sequentialBuildPartitions = buildPartitions.Where(ShouldBuildSequential).ToArray();
9095

9196
eventProcessor.OnStartBuildStage([.. parallelBuildPartitions, .. sequentialBuildPartitions]);
9297

9398
var buildResults = new Dictionary<BuildPartition, BuildResult>();
94-
if (parallelBuildBenchmarks.Length > 0)
99+
if (parallelBuildPartitions.Length > 0)
95100
{
96101
var results = BuildInParallel(compositeLogger, rootArtifactsFolderPath, parallelBuildPartitions, in globalChronometer, eventProcessor);
97102
foreach (var kvp in results)
@@ -100,7 +105,7 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
100105
}
101106
}
102107

103-
if (sequentialBuildBenchmarks.Length > 0)
108+
if (sequentialBuildPartitions.Length > 0)
104109
{
105110
var results = BuildSequential(compositeLogger, rootArtifactsFolderPath, sequentialBuildPartitions, in globalChronometer, eventProcessor);
106111
foreach (var kvp in results)

src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
5252
benchmarkCase);
5353
yield break;
5454
}
55+
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
56+
{
57+
yield return invalidCliError;
58+
}
5559

56-
foreach (var validationError in DotNetSdkValidator.ValidateFrameworkSdks(CustomDotNetCliPath, benchmarkCase))
60+
foreach (var validationError in DotNetSdkValidator.ValidateFrameworkSdks(benchmarkCase))
5761
{
5862
yield return validationError;
5963
}

src/BenchmarkDotNet/Validators/DotNetSdkValidator.cs renamed to src/BenchmarkDotNet/Validators/DotNetSdkVersionValidator.cs

+8-23
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,30 @@ public static IEnumerable<ValidationError> ValidateCoreSdks(string? customDotNet
2020
if (IsCliPathInvalid(customDotNetCliPath, benchmark, out ValidationError? cliPathError))
2121
{
2222
yield return cliPathError;
23-
yield break;
2423
}
25-
if (!TryGetSdkVersion(benchmark, out Version requiredSdkVersion))
24+
else if (TryGetSdkVersion(benchmark, out Version requiredSdkVersion))
2625
{
27-
yield break;
28-
}
29-
30-
var installedSdks = GetInstalledDotNetSdks(customDotNetCliPath);
31-
if (!installedSdks.Any(sdk => sdk >= requiredSdkVersion))
32-
{
33-
yield return new ValidationError(true, $"The required .NET Core SDK version {requiredSdkVersion} or higher for runtime moniker {benchmark.Job.Environment.Runtime.RuntimeMoniker} is not installed.", benchmark);
34-
}
35-
else if (requiredSdkVersion.Major < 8)
36-
{
37-
yield return new ValidationError(false, ".Net SDK versions older than 8.0 may produce builds with incorrect bindings.", benchmark);
26+
var installedSdks = GetInstalledDotNetSdks(customDotNetCliPath);
27+
if (!installedSdks.Any(sdk => sdk >= requiredSdkVersion))
28+
{
29+
yield return new ValidationError(true, $"The required .NET Core SDK version {requiredSdkVersion} or higher for runtime moniker {benchmark.Job.Environment.Runtime.RuntimeMoniker} is not installed.", benchmark);
30+
}
3831
}
3932
}
4033

41-
public static IEnumerable<ValidationError> ValidateFrameworkSdks(string? customDotNetCliPath, BenchmarkCase benchmark)
34+
public static IEnumerable<ValidationError> ValidateFrameworkSdks(BenchmarkCase benchmark)
4235
{
43-
if (IsCliPathInvalid(customDotNetCliPath, benchmark, out ValidationError? cliPathError))
44-
{
45-
yield return cliPathError;
46-
yield break;
47-
}
4836
if (!TryGetSdkVersion(benchmark, out Version requiredSdkVersion))
4937
{
5038
yield break;
5139
}
5240

5341
var installedVersionString = cachedFrameworkSdks.Value.FirstOrDefault();
42+
5443
if (installedVersionString == null || Version.TryParse(installedVersionString, out var installedVersion) && installedVersion < requiredSdkVersion)
5544
{
5645
yield return new ValidationError(true, $"The required .NET Framework SDK version {requiredSdkVersion} or higher is not installed.", benchmark);
5746
}
58-
else if (requiredSdkVersion.Major < 8)
59-
{
60-
yield return new ValidationError(false, ".Net SDK versions older than 8.0 may produce builds with incorrect bindings.", benchmark);
61-
}
6247
}
6348

6449
public static bool IsCliPathInvalid(string customDotNetCliPath, BenchmarkCase benchmarkCase, out ValidationError? validationError)

0 commit comments

Comments
 (0)