From 2cce425a69f23b2c9a0de93ceb80c0cc915e5ec6 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 15 Dec 2022 16:13:56 +0100 Subject: [PATCH] improve Android support (#2231) * DebugConfig does not need to duplicate DefaultConfig.ArtifactsPath logic * don't use Console colors on platforms that don't support it: Android, iOS, tvOS and WASM --- src/BenchmarkDotNet/Configs/DebugConfig.cs | 11 +---------- src/BenchmarkDotNet/Loggers/ConsoleLogger.cs | 9 +++++++++ src/BenchmarkDotNet/Portability/RuntimeInformation.cs | 10 ++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/BenchmarkDotNet/Configs/DebugConfig.cs b/src/BenchmarkDotNet/Configs/DebugConfig.cs index 7c832b9cd3..764d798933 100644 --- a/src/BenchmarkDotNet/Configs/DebugConfig.cs +++ b/src/BenchmarkDotNet/Configs/DebugConfig.cs @@ -70,16 +70,7 @@ public abstract class DebugConfig : IConfig public ConfigUnionRule UnionRule => ConfigUnionRule.Union; public TimeSpan BuildTimeout => DefaultConfig.Instance.BuildTimeout; - public string ArtifactsPath - { - get - { - var root = RuntimeInformation.IsAndroid () ? - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) : - Directory.GetCurrentDirectory(); - return Path.Combine(root, "BenchmarkDotNet.Artifacts"); - } - } + public string ArtifactsPath => null; // DefaultConfig.ArtifactsPath will be used if the user does not specify it in explicit way public CultureInfo CultureInfo => null; public IEnumerable GetLogicalGroupRules() => Array.Empty(); diff --git a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs index 6f3cd34ae3..a54bf88edc 100644 --- a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs +++ b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using BenchmarkDotNet.Helpers; +using BenchmarkDotNet.Portability; using JetBrains.Annotations; namespace BenchmarkDotNet.Loggers @@ -13,6 +14,8 @@ public sealed class ConsoleLogger : ILogger public static readonly ILogger Default = new ConsoleLogger(); public static readonly ILogger Ascii = new ConsoleLogger(false); public static readonly ILogger Unicode = new ConsoleLogger(true); + private static readonly bool ConsoleSupportsColors + = !(RuntimeInformation.IsAndroid() || RuntimeInformation.IsIOS() || RuntimeInformation.IsWasm || RuntimeInformation.IsTvOS()); private readonly bool unicodeSupport; private readonly Dictionary colorScheme; @@ -41,6 +44,12 @@ private void Write(LogKind logKind, Action write, string text) if (!unicodeSupport) text = text.ToAscii(); + if (!ConsoleSupportsColors) + { + write(text); + return; + } + var colorBefore = Console.ForegroundColor; try diff --git a/src/BenchmarkDotNet/Portability/RuntimeInformation.cs b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs index de8cdc9c1b..4d5b9c44ce 100644 --- a/src/BenchmarkDotNet/Portability/RuntimeInformation.cs +++ b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs @@ -143,6 +143,16 @@ internal static bool IsIOS() => Type.GetType("Foundation.NSObject, Xamarin.iOS") != null; #endif +#if NET6_0_OR_GREATER + [System.Runtime.Versioning.SupportedOSPlatformGuard("tvos")] +#endif + internal static bool IsTvOS() => +#if NET6_0_OR_GREATER + OperatingSystem.IsTvOS(); +#else + IsOSPlatform(OSPlatform.Create("TVOS")); +#endif + public static string GetOsVersion() { if (IsMacOS())