2016-02-18 11:39:36 -08:00
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Microsoft.Extensions.PlatformAbstractions;
|
|
|
|
|
2016-02-19 17:00:41 -08:00
|
|
|
namespace Microsoft.DotNet.Cli.Build.Framework
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
public static class CurrentPlatform
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
public static BuildPlatform Current
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return DetermineCurrentPlatform();
|
|
|
|
}
|
2016-02-18 11:39:36 -08:00
|
|
|
}
|
|
|
|
|
2016-02-19 17:00:41 -08:00
|
|
|
public static bool IsWindows
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
|
|
}
|
2016-02-18 11:39:36 -08:00
|
|
|
}
|
|
|
|
|
2016-02-19 17:00:41 -08:00
|
|
|
public static bool IsOSX
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
|
|
|
}
|
2016-02-18 11:39:36 -08:00
|
|
|
}
|
|
|
|
|
2016-02-19 17:00:41 -08:00
|
|
|
public static bool IsUbuntu
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
get
|
|
|
|
{
|
|
|
|
var osname = PlatformServices.Default.Runtime.OperatingSystem;
|
|
|
|
return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
2016-02-18 11:39:36 -08:00
|
|
|
}
|
|
|
|
|
2016-02-19 17:00:41 -08:00
|
|
|
public static bool IsCentOS
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var osname = PlatformServices.Default.Runtime.OperatingSystem;
|
|
|
|
return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static BuildPlatform DetermineCurrentPlatform()
|
2016-02-18 11:39:36 -08:00
|
|
|
{
|
2016-02-19 17:00:41 -08:00
|
|
|
if (IsWindows)
|
|
|
|
{
|
|
|
|
return BuildPlatform.Windows;
|
|
|
|
}
|
|
|
|
else if (IsOSX)
|
|
|
|
{
|
|
|
|
return BuildPlatform.OSX;
|
|
|
|
}
|
|
|
|
else if (IsUbuntu)
|
|
|
|
{
|
|
|
|
return BuildPlatform.Ubuntu;
|
|
|
|
}
|
|
|
|
else if (IsCentOS)
|
|
|
|
{
|
|
|
|
return BuildPlatform.CentOS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return default(BuildPlatform);
|
|
|
|
}
|
2016-02-18 11:39:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|