Skip to content

.Net SDK Validation #2523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/CoreRun/CoreRunToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IEnumerable<ValidationError> Validate(BenchmarkCase benchmark, IResolver
$"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.",
benchmark);
}
else if (Toolchain.IsCliPathInvalid(CustomDotNetCliPath?.FullName, benchmark, out var invalidCliError))
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath?.FullName, benchmark, out var invalidCliError))
{
yield return invalidCliError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
$"Classic .NET toolchain is supported only for Windows, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
benchmarkCase);
}
else if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
{
yield return invalidCliError;
}

foreach (var validationError in DotNetSdkValidator.ValidateFrameworkSdks(benchmarkCase))
{
yield return validationError;
}
}
}
}
7 changes: 6 additions & 1 deletion src/BenchmarkDotNet/Toolchains/CsProj/CsProjCoreToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
yield return validationError;
}

if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
{
yield return invalidCliError;
}
Expand Down Expand Up @@ -80,6 +80,11 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
$"Currently CsProjCoreToolchain does not support LINQPad 6+. Please use {nameof(InProcessEmitToolchain)} instead.",
benchmarkCase);
}

foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
{
yield return validationError;
}
}

public override bool Equals(object obj) => obj is CsProjCoreToolchain typed && Equals(typed);
Expand Down
43 changes: 32 additions & 11 deletions src/BenchmarkDotNet/Toolchains/MonoAotLLVM/MonoAotLLVMToolChain.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Validators;
using System.Collections.Generic;

namespace BenchmarkDotNet.Toolchains.MonoAotLLVM
{
public class MonoAotLLVMToolChain : Toolchain
{
public MonoAotLLVMToolChain(string name, IGenerator generator, IBuilder builder, IExecutor executor)
private readonly string _customDotNetCliPath;

public MonoAotLLVMToolChain(string name, IGenerator generator, IBuilder builder, IExecutor executor, string customDotNetCliPath)
: base(name, generator, builder, executor)
{
_customDotNetCliPath = customDotNetCliPath;
}

public static IToolchain From(NetCoreAppSettings netCoreAppSettings)
=> new MonoAotLLVMToolChain(netCoreAppSettings.Name,
new MonoAotLLVMGenerator(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath,
netCoreAppSettings.PackagesPath,
netCoreAppSettings.CustomRuntimePack,
netCoreAppSettings.AOTCompilerPath,
netCoreAppSettings.AOTCompilerMode),
new DotNetCliBuilder(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath),
new Executor());
=> new MonoAotLLVMToolChain(netCoreAppSettings.Name,
new MonoAotLLVMGenerator(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath,
netCoreAppSettings.PackagesPath,
netCoreAppSettings.CustomRuntimePack,
netCoreAppSettings.AOTCompilerPath,
netCoreAppSettings.AOTCompilerMode),
new DotNetCliBuilder(netCoreAppSettings.TargetFrameworkMoniker,
netCoreAppSettings.CustomDotNetCliPath),
new Executor(),
netCoreAppSettings.CustomDotNetCliPath);

public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase, IResolver resolver)
{
foreach (var validationError in base.Validate(benchmarkCase, resolver))
{
yield return validationError;
}

foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(_customDotNetCliPath, benchmarkCase))
{
yield return validationError;
}
}
}
}
7 changes: 6 additions & 1 deletion src/BenchmarkDotNet/Toolchains/MonoWasm/WasmToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
$"{nameof(WasmToolchain)} is supported only on Unix, benchmark '{benchmarkCase.DisplayInfo}' might not work correctly",
benchmarkCase);
}
else if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
else if (DotNetSdkValidator.IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
{
yield return invalidCliError;
}

foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
{
yield return validationError;
}
}

[PublicAPI]
Expand Down
16 changes: 16 additions & 0 deletions src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Collections.Generic;
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Validators;

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

public static string GetExtraArguments(string runtimeIdentifier) => $"-r {runtimeIdentifier}";

public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase, IResolver resolver)
{
foreach (var error in base.Validate(benchmarkCase, resolver))
{
yield return error;
}

foreach (var validationError in DotNetSdkValidator.ValidateCoreSdks(CustomDotNetCliPath, benchmarkCase))
{
yield return validationError;
}
}
}
}
27 changes: 1 addition & 26 deletions src/BenchmarkDotNet/Toolchains/Toolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,6 @@ public virtual IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase
}
}

internal static bool IsCliPathInvalid(string customDotNetCliPath, BenchmarkCase benchmarkCase, out ValidationError? validationError)
{
validationError = null;

if (string.IsNullOrEmpty(customDotNetCliPath) && !HostEnvironmentInfo.GetCurrent().IsDotNetCliInstalled())
{
validationError = new ValidationError(true,
$"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",
benchmarkCase);

return true;
}

if (!string.IsNullOrEmpty(customDotNetCliPath) && !File.Exists(customDotNetCliPath))
{
validationError = new ValidationError(true,
$"Provided custom dotnet cli path does not exist, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
benchmarkCase);

return true;
}

return false;
}

public override string ToString() => Name;
}
}
}
Loading