make JitOptimizationsValidator work for .NET Core (needed properties are available now in 1.1)
This commit is contained in:
Родитель
19caa2cfec
Коммит
13e12c761f
|
@ -6,28 +6,35 @@ namespace BenchmarkDotNet.Extensions
|
|||
{
|
||||
internal static class AssemblyExtensions
|
||||
{
|
||||
internal static bool? IsJITOptimizationDisabled(this Assembly assembly)
|
||||
{
|
||||
#if CORE
|
||||
return null; // https://github.com/dotnet/coreclr/pull/6153
|
||||
#else
|
||||
return assembly?.GetCustomAttributes(false)
|
||||
.OfType<DebuggableAttribute>()
|
||||
.SingleOrDefault()?.IsJITOptimizerDisabled;
|
||||
#endif
|
||||
}
|
||||
internal static bool? IsJitOptimizationDisabled(this Assembly assembly)
|
||||
=> GetDebuggableAttribute(assembly).IsJitOptimizerDisabled();
|
||||
|
||||
internal static bool? IsDebug(this Assembly assembly)
|
||||
{
|
||||
#if CORE
|
||||
return null; // https://github.com/dotnet/coreclr/pull/6153
|
||||
#else
|
||||
return assembly?.GetCustomAttributes(false)
|
||||
.OfType<DebuggableAttribute>()
|
||||
.SingleOrDefault()?.IsJITTrackingEnabled;
|
||||
#endif
|
||||
}
|
||||
=> GetDebuggableAttribute(assembly).IsJitTrackingEnabled();
|
||||
|
||||
internal static bool IsTrue(this bool? valueOrNothing) => valueOrNothing.HasValue && valueOrNothing.Value;
|
||||
|
||||
private static DebuggableAttribute GetDebuggableAttribute(Assembly assembly)
|
||||
{
|
||||
return assembly?.GetCustomAttributes()
|
||||
.OfType<DebuggableAttribute>()
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
static bool? IsJitOptimizerDisabled(this DebuggableAttribute attribute) => Read(attribute, "IsJITOptimizerDisabled");
|
||||
|
||||
static bool? IsJitTrackingEnabled(this DebuggableAttribute attribute) => Read(attribute, "IsJITTrackingEnabled");
|
||||
|
||||
private static bool? Read(DebuggableAttribute debuggableAttribute, string propertyName)
|
||||
{
|
||||
// the properties are implemented (https://github.com/dotnet/coreclr/pull/6153)
|
||||
// but not exposed in corefx Contracs due to .NET Standard versioning problems (https://github.com/dotnet/corefx/issues/13717)
|
||||
// so we need to use reflection to read this simple property...
|
||||
var propertyInfo = typeof(DebuggableAttribute).GetProperty(propertyName);
|
||||
if (debuggableAttribute == null || propertyInfo == null)
|
||||
return null;
|
||||
|
||||
return (bool)propertyInfo.GetValue(debuggableAttribute);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ namespace BenchmarkDotNet.Validators
|
|||
{
|
||||
var referencedAssembly = Assembly.Load(referencedAssemblyName);
|
||||
|
||||
if (referencedAssembly.IsJITOptimizationDisabled().IsTrue())
|
||||
if (referencedAssembly.IsJitOptimizationDisabled().IsTrue())
|
||||
{
|
||||
yield return new ValidationError(
|
||||
TreatsWarningsAsErrors,
|
||||
|
@ -33,7 +33,7 @@ namespace BenchmarkDotNet.Validators
|
|||
}
|
||||
}
|
||||
|
||||
if (group.Key.IsJITOptimizationDisabled().IsTrue())
|
||||
if (group.Key.IsJitOptimizationDisabled().IsTrue())
|
||||
{
|
||||
yield return new ValidationError(
|
||||
TreatsWarningsAsErrors,
|
||||
|
|
Загрузка…
Ссылка в новой задаче