Skip to content

Commit 2cce425

Browse files
authored
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
1 parent 0c90af7 commit 2cce425

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/BenchmarkDotNet/Configs/DebugConfig.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,7 @@ public abstract class DebugConfig : IConfig
7070
public ConfigUnionRule UnionRule => ConfigUnionRule.Union;
7171
public TimeSpan BuildTimeout => DefaultConfig.Instance.BuildTimeout;
7272

73-
public string ArtifactsPath
74-
{
75-
get
76-
{
77-
var root = RuntimeInformation.IsAndroid () ?
78-
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) :
79-
Directory.GetCurrentDirectory();
80-
return Path.Combine(root, "BenchmarkDotNet.Artifacts");
81-
}
82-
}
73+
public string ArtifactsPath => null; // DefaultConfig.ArtifactsPath will be used if the user does not specify it in explicit way
8374

8475
public CultureInfo CultureInfo => null;
8576
public IEnumerable<BenchmarkLogicalGroupRule> GetLogicalGroupRules() => Array.Empty<BenchmarkLogicalGroupRule>();

src/BenchmarkDotNet/Loggers/ConsoleLogger.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using BenchmarkDotNet.Helpers;
5+
using BenchmarkDotNet.Portability;
56
using JetBrains.Annotations;
67

78
namespace BenchmarkDotNet.Loggers
@@ -13,6 +14,8 @@ public sealed class ConsoleLogger : ILogger
1314
public static readonly ILogger Default = new ConsoleLogger();
1415
public static readonly ILogger Ascii = new ConsoleLogger(false);
1516
public static readonly ILogger Unicode = new ConsoleLogger(true);
17+
private static readonly bool ConsoleSupportsColors
18+
= !(RuntimeInformation.IsAndroid() || RuntimeInformation.IsIOS() || RuntimeInformation.IsWasm || RuntimeInformation.IsTvOS());
1619

1720
private readonly bool unicodeSupport;
1821
private readonly Dictionary<LogKind, ConsoleColor> colorScheme;
@@ -41,6 +44,12 @@ private void Write(LogKind logKind, Action<string> write, string text)
4144
if (!unicodeSupport)
4245
text = text.ToAscii();
4346

47+
if (!ConsoleSupportsColors)
48+
{
49+
write(text);
50+
return;
51+
}
52+
4453
var colorBefore = Console.ForegroundColor;
4554

4655
try

src/BenchmarkDotNet/Portability/RuntimeInformation.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ internal static bool IsIOS() =>
143143
Type.GetType("Foundation.NSObject, Xamarin.iOS") != null;
144144
#endif
145145

146+
#if NET6_0_OR_GREATER
147+
[System.Runtime.Versioning.SupportedOSPlatformGuard("tvos")]
148+
#endif
149+
internal static bool IsTvOS() =>
150+
#if NET6_0_OR_GREATER
151+
OperatingSystem.IsTvOS();
152+
#else
153+
IsOSPlatform(OSPlatform.Create("TVOS"));
154+
#endif
155+
146156
public static string GetOsVersion()
147157
{
148158
if (IsMacOS())

0 commit comments

Comments
 (0)