Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59647c9

Browse files
authoredMar 4, 2024
.Net SDK Validation (#2523)
* Adding DotNetSDK Validation * Added support for Wasm and NativeAot * Added missing case statements * Code cleanup * Separated providers for .Net and .Net Framework. Added validation to MonoAotLLVMToolChain and CsProjClassicNetToolchain * Put code into static utility class. Updated toolchains * Updated validator and toolchains * Updated toolchains and framework validation
1 parent f4c39ee commit 59647c9

File tree

8 files changed

+294
-46
lines changed

8 files changed

+294
-46
lines changed
 

‎src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IEnumerable<ValidationError> Validate(BenchmarkCase benchmark, IResolver
6666
$"Provided CoreRun path does not exist, benchmark '{benchmark.DisplayInfo}' will not be executed. Please remember that BDN expects path to CoreRun.exe (corerun on Unix), not to Core_Root folder.",
6767
benchmark);
6868
}
69-
else if (Toolchain.IsCliPathInvalid(CustomDotNetCliPath?.FullName, benchmark, out var invalidCliError))
69+
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath?.FullName, benchmark, out var invalidCliError))
7070
{
7171
yield return invalidCliError;
7272
}

‎src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
4949
yield return new ValidationError(true,
5050
$"Classic .NET toolchain is supported only for Windows, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
5151
benchmarkCase);
52+
yield break;
5253
}
53-
else if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
54+
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
5455
{
5556
yield return invalidCliError;
5657
}
58+
59+
foreach (var validationError in DotNetSdkValidator.ValidateFrameworkSdks(benchmarkCase))
60+
{
61+
yield return validationError;
62+
}
5763
}
5864
}
5965
}

‎src/BenchmarkDotNet/Toolchains/CsProj/CsProjCoreToolchain.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
4949
yield return validationError;
5050
}
5151

52-
if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
53-
{
54-
yield return invalidCliError;
55-
}
56-
5752
if (benchmarkCase.Job.HasValue(EnvironmentMode.JitCharacteristic) && benchmarkCase.Job.ResolveValue(EnvironmentMode.JitCharacteristic, resolver) == Jit.LegacyJit)
5853
{
5954
yield return new ValidationError(true,
@@ -80,6 +75,11 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
8075
$"Currently CsProjCoreToolchain does not support LINQPad 6+. Please use {nameof(InProcessEmitToolchain)} instead.",
8176
benchmarkCase);
8277
}
78+
79+
foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
80+
{
81+
yield return validationError;
82+
}
8383
}
8484

8585
public override bool Equals(object obj) => obj is CsProjCoreToolchain typed && Equals(typed);
Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1+
using BenchmarkDotNet.Characteristics;
2+
using BenchmarkDotNet.Running;
13
using BenchmarkDotNet.Toolchains.DotNetCli;
4+
using BenchmarkDotNet.Validators;
5+
using System.Collections.Generic;
26

37
namespace BenchmarkDotNet.Toolchains.MonoAotLLVM
48
{
59
public class MonoAotLLVMToolChain : Toolchain
610
{
7-
public MonoAotLLVMToolChain(string name, IGenerator generator, IBuilder builder, IExecutor executor)
11+
private readonly string _customDotNetCliPath;
12+
13+
public MonoAotLLVMToolChain(string name, IGenerator generator, IBuilder builder, IExecutor executor, string customDotNetCliPath)
814
: base(name, generator, builder, executor)
915
{
16+
_customDotNetCliPath = customDotNetCliPath;
1017
}
1118

1219
public static IToolchain From(NetCoreAppSettings netCoreAppSettings)
13-
=> new MonoAotLLVMToolChain(netCoreAppSettings.Name,
14-
new MonoAotLLVMGenerator(netCoreAppSettings.TargetFrameworkMoniker,
15-
netCoreAppSettings.CustomDotNetCliPath,
16-
netCoreAppSettings.PackagesPath,
17-
netCoreAppSettings.CustomRuntimePack,
18-
netCoreAppSettings.AOTCompilerPath,
19-
netCoreAppSettings.AOTCompilerMode),
20-
new DotNetCliBuilder(netCoreAppSettings.TargetFrameworkMoniker,
21-
netCoreAppSettings.CustomDotNetCliPath),
22-
new Executor());
20+
=> new MonoAotLLVMToolChain(netCoreAppSettings.Name,
21+
new MonoAotLLVMGenerator(netCoreAppSettings.TargetFrameworkMoniker,
22+
netCoreAppSettings.CustomDotNetCliPath,
23+
netCoreAppSettings.PackagesPath,
24+
netCoreAppSettings.CustomRuntimePack,
25+
netCoreAppSettings.AOTCompilerPath,
26+
netCoreAppSettings.AOTCompilerMode),
27+
new DotNetCliBuilder(netCoreAppSettings.TargetFrameworkMoniker,
28+
netCoreAppSettings.CustomDotNetCliPath),
29+
new Executor(),
30+
netCoreAppSettings.CustomDotNetCliPath);
31+
32+
public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase, IResolver resolver)
33+
{
34+
foreach (var validationError in base.Validate(benchmarkCase, resolver))
35+
{
36+
yield return validationError;
37+
}
38+
39+
foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(_customDotNetCliPath, benchmarkCase))
40+
{
41+
yield return validationError;
42+
}
43+
}
2344
}
2445
}

‎src/BenchmarkDotNet/Toolchains/MonoWasm/WasmToolchain.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
3232
$"{nameof(WasmToolchain)} is supported only on Unix, benchmark '{benchmarkCase.DisplayInfo}' might not work correctly",
3333
benchmarkCase);
3434
}
35-
else if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
35+
36+
foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
3637
{
37-
yield return invalidCliError;
38+
yield return validationError;
3839
}
3940
}
4041

‎src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchain.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.Collections.Generic;
2+
using BenchmarkDotNet.Characteristics;
3+
using BenchmarkDotNet.Running;
24
using BenchmarkDotNet.Toolchains.DotNetCli;
5+
using BenchmarkDotNet.Validators;
36

47
namespace BenchmarkDotNet.Toolchains.NativeAot
58
{
@@ -60,5 +63,18 @@ internal NativeAotToolchain(string displayName,
6063
public static NativeAotToolchainBuilder CreateBuilder() => NativeAotToolchainBuilder.Create();
6164

6265
public static string GetExtraArguments(string runtimeIdentifier) => $"-r {runtimeIdentifier}";
66+
67+
public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase, IResolver resolver)
68+
{
69+
foreach (var error in base.Validate(benchmarkCase, resolver))
70+
{
71+
yield return error;
72+
}
73+
74+
foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
75+
{
76+
yield return validationError;
77+
}
78+
}
6379
}
6480
}

‎src/BenchmarkDotNet/Toolchains/Toolchain.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,6 @@ public virtual IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase
5757
}
5858
}
5959

60-
internal static bool IsCliPathInvalid(string customDotNetCliPath, BenchmarkCase benchmarkCase, out ValidationError? validationError)
61-
{
62-
validationError = null;
63-
64-
if (string.IsNullOrEmpty(customDotNetCliPath) && !HostEnvironmentInfo.GetCurrent().IsDotNetCliInstalled())
65-
{
66-
validationError = new ValidationError(true,
67-
$"BenchmarkDotNet requires dotnet SDK to be installed or path to local dotnet cli provided in explicit way using `--cli` argument, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
68-
benchmarkCase);
69-
70-
return true;
71-
}
72-
73-
if (!string.IsNullOrEmpty(customDotNetCliPath) && !File.Exists(customDotNetCliPath))
74-
{
75-
validationError = new ValidationError(true,
76-
$"Provided custom dotnet cli path does not exist, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
77-
benchmarkCase);
78-
79-
return true;
80-
}
81-
82-
return false;
83-
}
84-
8560
public override string ToString() => Name;
8661
}
87-
}
62+
}

0 commit comments

Comments
 (0)
Please sign in to comment.