Skip to content

Commit cefa86d

Browse files
committed
Moved DotNetSdkValidator.GetSdkVersionFromMoniker to RuntimeMonikerExtensions.GetRuntimeVersion.
Check all configs of each partition instead of only representative.
1 parent 5feb748 commit cefa86d

File tree

3 files changed

+54
-74
lines changed

3 files changed

+54
-74
lines changed

src/BenchmarkDotNet/Extensions/RuntimeMonikerExtensions.cs

+46
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,51 @@ internal static Runtime GetRuntime(this RuntimeMoniker runtimeMoniker)
7575
throw new ArgumentOutOfRangeException(nameof(runtimeMoniker), runtimeMoniker, "Runtime Moniker not supported");
7676
}
7777
}
78+
79+
internal static Version GetRuntimeVersion(this RuntimeMoniker runtimeMoniker) => runtimeMoniker switch
80+
{
81+
RuntimeMoniker.Net461 => new Version(4, 6, 1),
82+
RuntimeMoniker.Net462 => new Version(4, 6, 2),
83+
RuntimeMoniker.Net47 => new Version(4, 7),
84+
RuntimeMoniker.Net471 => new Version(4, 7, 1),
85+
RuntimeMoniker.Net472 => new Version(4, 7, 2),
86+
RuntimeMoniker.Net48 => new Version(4, 8),
87+
RuntimeMoniker.Net481 => new Version(4, 8, 1),
88+
RuntimeMoniker.NetCoreApp20 => new Version(2, 0),
89+
RuntimeMoniker.NetCoreApp21 => new Version(2, 1),
90+
RuntimeMoniker.NetCoreApp22 => new Version(2, 2),
91+
RuntimeMoniker.NetCoreApp30 => new Version(3, 0),
92+
RuntimeMoniker.NetCoreApp31 => new Version(3, 1),
93+
RuntimeMoniker.Net50 => new Version(5, 0),
94+
RuntimeMoniker.Net60 => new Version(6, 0),
95+
RuntimeMoniker.Net70 => new Version(7, 0),
96+
RuntimeMoniker.Net80 => new Version(8, 0),
97+
RuntimeMoniker.Net90 => new Version(9, 0),
98+
RuntimeMoniker.Net10_0 => new Version(10, 0),
99+
RuntimeMoniker.NativeAot60 => new Version(6, 0),
100+
RuntimeMoniker.NativeAot70 => new Version(7, 0),
101+
RuntimeMoniker.NativeAot80 => new Version(8, 0),
102+
RuntimeMoniker.NativeAot90 => new Version(9, 0),
103+
RuntimeMoniker.NativeAot10_0 => new Version(10, 0),
104+
RuntimeMoniker.Mono60 => new Version(6, 0),
105+
RuntimeMoniker.Mono70 => new Version(7, 0),
106+
RuntimeMoniker.Mono80 => new Version(8, 0),
107+
RuntimeMoniker.Mono90 => new Version(9, 0),
108+
RuntimeMoniker.Mono10_0 => new Version(10, 0),
109+
RuntimeMoniker.Wasm => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(5, 0),
110+
RuntimeMoniker.WasmNet50 => new Version(5, 0),
111+
RuntimeMoniker.WasmNet60 => new Version(6, 0),
112+
RuntimeMoniker.WasmNet70 => new Version(7, 0),
113+
RuntimeMoniker.WasmNet80 => new Version(8, 0),
114+
RuntimeMoniker.WasmNet90 => new Version(9, 0),
115+
RuntimeMoniker.WasmNet10_0 => new Version(10, 0),
116+
RuntimeMoniker.MonoAOTLLVM => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(6, 0),
117+
RuntimeMoniker.MonoAOTLLVMNet60 => new Version(6, 0),
118+
RuntimeMoniker.MonoAOTLLVMNet70 => new Version(7, 0),
119+
RuntimeMoniker.MonoAOTLLVMNet80 => new Version(8, 0),
120+
RuntimeMoniker.MonoAOTLLVMNet90 => new Version(9, 0),
121+
RuntimeMoniker.MonoAOTLLVMNet10_0 => new Version(10, 0),
122+
_ => throw new NotImplementedException($"SDK version check not implemented for {runtimeMoniker}")
123+
};
78124
}
79125
}

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
8585
var buildPartitions = BenchmarkPartitioner.CreateForBuild(supportedBenchmarks, resolver);
8686

8787
static bool ShouldBuildSequential(BuildPartition partition)
88-
=> partition.RepresentativeBenchmarkCase.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)
88+
=> partition.Benchmarks.Any(x => x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild))
8989
// .Net SDK 8+ supports ArtifactsPath for proper parallel builds.
9090
// Older SDKs may produce builds with incorrect bindings if more than 1 partition is built in parallel.
9191
|| (partition.RepresentativeBenchmarkCase.GetToolchain().Generator is DotNetCliGenerator
92-
&& DotNetSdkValidator.GetSdkVersionFromMoniker(partition.RepresentativeBenchmarkCase.GetRuntime().RuntimeMoniker).Major < 8);
92+
&& partition.RepresentativeBenchmarkCase.GetRuntime().RuntimeMoniker.GetRuntimeVersion().Major < 8);
9393

9494
var parallelBuildPartitions = buildPartitions.Where(x => !ShouldBuildSequential(x)).ToArray();
9595
var sequentialBuildPartitions = buildPartitions.Where(ShouldBuildSequential).ToArray();

src/BenchmarkDotNet/Validators/DotNetSdkValidator.cs

+6-72
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BenchmarkDotNet.Environments;
2+
using BenchmarkDotNet.Extensions;
23
using BenchmarkDotNet.Jobs;
34
using BenchmarkDotNet.Running;
45
using System;
@@ -20,26 +21,19 @@ public static IEnumerable<ValidationError> ValidateCoreSdks(string? customDotNet
2021
if (IsCliPathInvalid(customDotNetCliPath, benchmark, out ValidationError? cliPathError))
2122
{
2223
yield return cliPathError;
24+
yield break;
2325
}
24-
else if (TryGetSdkVersion(benchmark, out Version requiredSdkVersion))
26+
var requiredSdkVersion = benchmark.GetRuntime().RuntimeMoniker.GetRuntimeVersion();
27+
if (!GetInstalledDotNetSdks(customDotNetCliPath).Any(sdk => sdk >= requiredSdkVersion))
2528
{
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-
}
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);
3130
}
3231
}
3332

3433
public static IEnumerable<ValidationError> ValidateFrameworkSdks(BenchmarkCase benchmark)
3534
{
36-
if (!TryGetSdkVersion(benchmark, out Version requiredSdkVersion))
37-
{
38-
yield break;
39-
}
40-
35+
var requiredSdkVersion = benchmark.GetRuntime().RuntimeMoniker.GetRuntimeVersion();
4136
var installedVersionString = cachedFrameworkSdks.Value.FirstOrDefault();
42-
4337
if (installedVersionString == null || Version.TryParse(installedVersionString, out var installedVersion) && installedVersion < requiredSdkVersion)
4438
{
4539
yield return new ValidationError(true, $"The required .NET Framework SDK version {requiredSdkVersion} or higher is not installed.", benchmark);
@@ -71,17 +65,6 @@ public static bool IsCliPathInvalid(string customDotNetCliPath, BenchmarkCase be
7165
return false;
7266
}
7367

74-
private static bool TryGetSdkVersion(BenchmarkCase benchmark, out Version sdkVersion)
75-
{
76-
sdkVersion = default;
77-
if (benchmark?.Job?.Environment?.Runtime?.RuntimeMoniker != null)
78-
{
79-
sdkVersion = GetSdkVersionFromMoniker(benchmark.Job.Environment.Runtime.RuntimeMoniker);
80-
return true;
81-
}
82-
return false;
83-
}
84-
8568
private static IEnumerable<Version> GetInstalledDotNetSdks(string? customDotNetCliPath)
8669
{
8770
string dotnetExecutable = string.IsNullOrEmpty(customDotNetCliPath) ? "dotnet" : customDotNetCliPath;
@@ -198,54 +181,5 @@ private static string CheckFor45PlusVersion(int releaseKey)
198181

199182
return "";
200183
}
201-
202-
internal static Version GetSdkVersionFromMoniker(RuntimeMoniker runtimeMoniker)
203-
{
204-
return runtimeMoniker switch
205-
{
206-
RuntimeMoniker.Net461 => new Version(4, 6, 1),
207-
RuntimeMoniker.Net462 => new Version(4, 6, 2),
208-
RuntimeMoniker.Net47 => new Version(4, 7),
209-
RuntimeMoniker.Net471 => new Version(4, 7, 1),
210-
RuntimeMoniker.Net472 => new Version(4, 7, 2),
211-
RuntimeMoniker.Net48 => new Version(4, 8),
212-
RuntimeMoniker.Net481 => new Version(4, 8, 1),
213-
RuntimeMoniker.NetCoreApp20 => new Version(2, 0),
214-
RuntimeMoniker.NetCoreApp21 => new Version(2, 1),
215-
RuntimeMoniker.NetCoreApp22 => new Version(2, 2),
216-
RuntimeMoniker.NetCoreApp30 => new Version(3, 0),
217-
RuntimeMoniker.NetCoreApp31 => new Version(3, 1),
218-
RuntimeMoniker.Net50 => new Version(5, 0),
219-
RuntimeMoniker.Net60 => new Version(6, 0),
220-
RuntimeMoniker.Net70 => new Version(7, 0),
221-
RuntimeMoniker.Net80 => new Version(8, 0),
222-
RuntimeMoniker.Net90 => new Version(9, 0),
223-
RuntimeMoniker.Net10_0 => new Version(10, 0),
224-
RuntimeMoniker.NativeAot60 => new Version(6, 0),
225-
RuntimeMoniker.NativeAot70 => new Version(7, 0),
226-
RuntimeMoniker.NativeAot80 => new Version(8, 0),
227-
RuntimeMoniker.NativeAot90 => new Version(9, 0),
228-
RuntimeMoniker.NativeAot10_0 => new Version(10, 0),
229-
RuntimeMoniker.Mono60 => new Version(6, 0),
230-
RuntimeMoniker.Mono70 => new Version(7, 0),
231-
RuntimeMoniker.Mono80 => new Version(8, 0),
232-
RuntimeMoniker.Mono90 => new Version(9, 0),
233-
RuntimeMoniker.Mono10_0 => new Version(10, 0),
234-
RuntimeMoniker.Wasm => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(5, 0),
235-
RuntimeMoniker.WasmNet50 => new Version(5, 0),
236-
RuntimeMoniker.WasmNet60 => new Version(6, 0),
237-
RuntimeMoniker.WasmNet70 => new Version(7, 0),
238-
RuntimeMoniker.WasmNet80 => new Version(8, 0),
239-
RuntimeMoniker.WasmNet90 => new Version(9, 0),
240-
RuntimeMoniker.WasmNet10_0 => new Version(10, 0),
241-
RuntimeMoniker.MonoAOTLLVM => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(6, 0),
242-
RuntimeMoniker.MonoAOTLLVMNet60 => new Version(6, 0),
243-
RuntimeMoniker.MonoAOTLLVMNet70 => new Version(7, 0),
244-
RuntimeMoniker.MonoAOTLLVMNet80 => new Version(8, 0),
245-
RuntimeMoniker.MonoAOTLLVMNet90 => new Version(9, 0),
246-
RuntimeMoniker.MonoAOTLLVMNet10_0 => new Version(10, 0),
247-
_ => throw new NotImplementedException($"SDK version check not implemented for {runtimeMoniker}")
248-
};
249-
}
250184
}
251185
}

0 commit comments

Comments
 (0)