Skip to content

Commit

Permalink
improve Android support (#2231)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adamsitnik committed Dec 15, 2022
1 parent 0c90af7 commit 2cce425
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/BenchmarkDotNet/Configs/DebugConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BenchmarkLogicalGroupRule> GetLogicalGroupRules() => Array.Empty<BenchmarkLogicalGroupRule>();
Expand Down
9 changes: 9 additions & 0 deletions src/BenchmarkDotNet/Loggers/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Portability;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Loggers
Expand All @@ -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<LogKind, ConsoleColor> colorScheme;
Expand Down Expand Up @@ -41,6 +44,12 @@ private void Write(LogKind logKind, Action<string> write, string text)
if (!unicodeSupport)
text = text.ToAscii();

if (!ConsoleSupportsColors)
{
write(text);
return;
}

var colorBefore = Console.ForegroundColor;

try
Expand Down
10 changes: 10 additions & 0 deletions src/BenchmarkDotNet/Portability/RuntimeInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ private static bool IsAotMethod()
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())
Expand Down

0 comments on commit 2cce425

Please sign in to comment.