Removing the public types from InternalAbstractions.

This commit is contained in:
Livar Cunha 2016-08-08 15:35:25 -07:00
parent 5c4785e662
commit b7b90175f4
18 changed files with 13 additions and 537 deletions

View file

@ -8,7 +8,7 @@
"type": "platform",
"version": "1.0.0"
},
"Microsoft.Extensions.DependencyModel": "1.0.1-beta-003395"
"Microsoft.Extensions.DependencyModel": "1.0.1-beta-000914"
},
"frameworks": {
"netcoreapp1.0": {

View file

@ -50,24 +50,10 @@
</Target>
<Target Name="BuildDotnetCliBuildFramework"
Inputs="@(DotnetCliBuildFrameworkInputs)"
Outputs="$(CLIBuildDll)"
DependsOnTargets="MSBuildWorkaroundTarget;
RestoreDotnetCliBuildFramework">
<ItemGroup>
<DotnetSdkDirectories Include="$([System.IO.Directory]::GetDirectories(&quot;$(Stage0Directory)/sdk&quot;))" />
<AzureStorageToCopy Include="@(DotnetSdkDirectories)">
<Source>$(DotnetCliBuildDirectory)/bin/Microsoft.WindowsAzure.Storage.dll</Source>
<Destination>%(Identity)/Microsoft.WindowsAzure.Storage.dll</Destination>
</AzureStorageToCopy>
</ItemGroup>
<Exec Command="$(DotnetStage0) publish -o $(DotnetCliBuildDirectory)/bin --framework netcoreapp1.0" WorkingDirectory="$(DotnetCliBuildDirectory)"/>
<!-- This is a work around to issue https://github.com/Microsoft/msbuild/issues/658 -->
<Copy SourceFiles="%(AzureStorageToCopy.Source)"
DestinationFiles="%(AzureStorageToCopy.Destination)" />
</Target>
<Target Name="RestoreDotnetCliBuildFramework"

View file

@ -1,5 +1,5 @@
using System;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build.Framework
{

View file

@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build.Framework
{

View file

@ -2,17 +2,13 @@
"version": "1.0.0-*",
"buildOptions": {
"warningsAsErrors": true,
"allowUnsafe": true,
"compile": [
"../../src/Microsoft.DotNet.InternalAbstractions/RuntimeEnvironment.cs",
"../../src/Microsoft.DotNet.InternalAbstractions/Platform.cs",
"../../src/Microsoft.DotNet.InternalAbstractions/Native/*.cs"
]
"allowUnsafe": true
},
"dependencies": {
"NETStandard.Library": "1.6.0",
"System.Diagnostics.Process": "4.1.0",
"System.Reflection.TypeExtensions": "4.1.0"
"System.Reflection.TypeExtensions": "4.1.0",
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000914"
},
"frameworks": {
"netstandard1.5": {

View file

@ -3,7 +3,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -22,7 +22,8 @@
"WindowsAzure.Storage": "6.2.2-preview",
"NuGet.CommandLine.XPlat": "3.5.0-rc1-1697",
"Microsoft.Build.Framework": "0.1.0-preview-00029-160805",
"Microsoft.Build.Utilities.Core": "0.1.0-preview-00029-160805"
"Microsoft.Build.Utilities.Core": "0.1.0-preview-00029-160805",
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000914"
},
"frameworks": {
"netcoreapp1.0": {

View file

@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,5 +1,5 @@
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.PlatformAbstractions;
using System;
using System.Collections.Generic;
using System.Linq;

View file

@ -11,7 +11,8 @@
"WindowsAzure.Storage": "6.2.2-preview",
"Microsoft.DotNet.Cli.Build.Framework": {
"target": "project"
}
},
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000914"
},
"frameworks": {
"netstandard1.6": {

View file

@ -1,25 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
namespace Microsoft.DotNet.InternalAbstractions
{
public static class ApplicationEnvironment
{
public static string ApplicationBasePath { get; } = GetApplicationBasePath();
private static string GetApplicationBasePath()
{
var basePath =
#if NET451
(string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") ??
AppDomain.CurrentDomain.BaseDirectory;
#else
AppContext.BaseDirectory;
#endif
return Path.GetFullPath(basePath);
}
}
}

View file

@ -1,58 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Microsoft.DotNet.InternalAbstractions
{
public struct HashCodeCombiner
{
private long _combinedHash64;
public int CombinedHash
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return _combinedHash64.GetHashCode(); }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private HashCodeCombiner(long seed)
{
_combinedHash64 = seed;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(int i)
{
_combinedHash64 = ((_combinedHash64 << 5) + _combinedHash64) ^ i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(string s)
{
var hashCode = (s != null) ? s.GetHashCode() : 0;
Add(hashCode);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(object o)
{
var hashCode = (o != null) ? o.GetHashCode() : 0;
Add(hashCode);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add<TValue>(TValue value, IEqualityComparer<TValue> comparer)
{
var hashCode = value != null ? comparer.GetHashCode(value) : 0;
Add(hashCode);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HashCodeCombiner Start()
{
return new HashCodeCombiner(0x1505L);
}
}
}

View file

@ -1,55 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.InternalAbstractions.Native
{
internal static partial class NativeMethods
{
public static class Darwin
{
private const int CTL_KERN = 1;
private const int KERN_OSRELEASE = 2;
public unsafe static string GetKernelRelease()
{
const uint BUFFER_LENGTH = 32;
var name = stackalloc int[2];
name[0] = CTL_KERN;
name[1] = KERN_OSRELEASE;
var buf = stackalloc byte[(int)BUFFER_LENGTH];
var len = stackalloc uint[1];
*len = BUFFER_LENGTH;
try
{
// If the buffer isn't big enough, it seems sysctl still returns 0 and just sets len to the
// necessary buffer size. This appears to be contrary to the man page, but it's easy to detect
// by simply checking len against the buffer length.
if (sysctl(name, 2, buf, len, IntPtr.Zero, 0) == 0 && *len < BUFFER_LENGTH)
{
return Marshal.PtrToStringAnsi((IntPtr)buf, (int)*len);
}
}
catch (Exception ex)
{
throw new PlatformNotSupportedException("Error reading Darwin Kernel Version", ex);
}
throw new PlatformNotSupportedException("Unknown error reading Darwin Kernel Version");
}
[DllImport("libc")]
private unsafe static extern int sysctl(
int* name,
uint namelen,
byte* oldp,
uint* oldlenp,
IntPtr newp,
uint newlen);
}
}
}

View file

@ -1,39 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NET451
using System;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.InternalAbstractions.Native
{
internal static partial class NativeMethods
{
public static class Unix
{
public unsafe static string GetUname()
{
// Utsname shouldn't be larger than 2K
var buf = stackalloc byte[2048];
try
{
if (uname((IntPtr)buf) == 0)
{
return Marshal.PtrToStringAnsi((IntPtr)buf);
}
}
catch (Exception ex)
{
throw new PlatformNotSupportedException("Error reading Unix name", ex);
}
throw new PlatformNotSupportedException("Unknown error reading Unix name");
}
[DllImport("libc")]
private static extern int uname(IntPtr utsname);
}
}
}
#endif

View file

@ -1,43 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.InternalAbstractions.Native
{
internal static partial class NativeMethods
{
public static class Windows
{
[StructLayout(LayoutKind.Sequential)]
internal struct RTL_OSVERSIONINFOEX
{
internal uint dwOSVersionInfoSize;
internal uint dwMajorVersion;
internal uint dwMinorVersion;
internal uint dwBuildNumber;
internal uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string szCSDVersion;
}
// This call avoids the shimming Windows does to report old versions
[DllImport("ntdll")]
private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation);
internal static string RtlGetVersion()
{
RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX();
osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
if (RtlGetVersion(out osvi) == 0)
{
return $"{osvi.dwMajorVersion}.{osvi.dwMinorVersion}.{osvi.dwBuildNumber}";
}
else
{
return null;
}
}
}
}
}

View file

@ -1,171 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.InternalAbstractions.Native
{
internal static class PlatformApis
{
private class DistroInfo
{
public string Id;
public string VersionId;
}
private static readonly Lazy<Platform> _platform = new Lazy<Platform>(DetermineOSPlatform);
private static readonly Lazy<DistroInfo> _distroInfo = new Lazy<DistroInfo>(LoadDistroInfo);
public static string GetOSName()
{
switch (GetOSPlatform())
{
case Platform.Windows:
return "Windows";
case Platform.Linux:
return GetDistroId() ?? "Linux";
case Platform.Darwin:
return "Mac OS X";
default:
return "Unknown";
}
}
public static string GetOSVersion()
{
switch (GetOSPlatform())
{
case Platform.Windows:
return NativeMethods.Windows.RtlGetVersion() ?? string.Empty;
case Platform.Linux:
return GetDistroVersionId() ?? string.Empty;
case Platform.Darwin:
return GetDarwinVersion() ?? string.Empty;
default:
return string.Empty;
}
}
private static string GetDarwinVersion()
{
Version version;
var kernelRelease = NativeMethods.Darwin.GetKernelRelease();
if (!Version.TryParse(kernelRelease, out version) || version.Major < 5)
{
// 10.0 covers all versions prior to Darwin 5
// Similarly, if the version is not a valid version number, but we have still detected that it is Darwin, we just assume
// it is OS X 10.0
return "10.0";
}
else
{
// Mac OS X 10.1 mapped to Darwin 5.x, and the mapping continues that way
// So just subtract 4 from the Darwin version.
// https://en.wikipedia.org/wiki/Darwin_%28operating_system%29
return $"10.{version.Major - 4}";
}
}
public static Platform GetOSPlatform()
{
return _platform.Value;
}
private static string GetDistroId()
{
return _distroInfo.Value?.Id;
}
private static string GetDistroVersionId()
{
return _distroInfo.Value?.VersionId;
}
private static DistroInfo LoadDistroInfo()
{
// Sample os-release file:
// NAME="Ubuntu"
// VERSION = "14.04.3 LTS, Trusty Tahr"
// ID = ubuntu
// ID_LIKE = debian
// PRETTY_NAME = "Ubuntu 14.04.3 LTS"
// VERSION_ID = "14.04"
// HOME_URL = "http://www.ubuntu.com/"
// SUPPORT_URL = "http://help.ubuntu.com/"
// BUG_REPORT_URL = "http://bugs.launchpad.net/ubuntu/"
// We use ID and VERSION_ID
if (File.Exists("/etc/os-release"))
{
var lines = File.ReadAllLines("/etc/os-release");
var result = new DistroInfo();
foreach (var line in lines)
{
if (line.StartsWith("ID=", StringComparison.Ordinal))
{
result.Id = line.Substring(3).Trim('"', '\'');
}
else if (line.StartsWith("VERSION_ID=", StringComparison.Ordinal))
{
result.VersionId = line.Substring(11).Trim('"', '\'');
}
}
return result;
}
return null;
}
// I could probably have just done one method signature and put the #if inside the body but the implementations
// are just completely different so I wanted to make that clear by putting the whole thing inside the #if.
#if NET451
private static Platform DetermineOSPlatform()
{
var platform = (int)Environment.OSVersion.Platform;
var isWindows = (platform != 4) && (platform != 6) && (platform != 128);
if (isWindows)
{
return Platform.Windows;
}
else
{
try
{
var uname = NativeMethods.Unix.GetUname();
if (string.Equals(uname, "Darwin", StringComparison.OrdinalIgnoreCase))
{
return Platform.Darwin;
}
if (string.Equals(uname, "Linux", StringComparison.OrdinalIgnoreCase))
{
return Platform.Linux;
}
}
catch
{
}
return Platform.Unknown;
}
}
#else
private static Platform DetermineOSPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return Platform.Windows;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Platform.Linux;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return Platform.Darwin;
}
return Platform.Unknown;
}
#endif
}
}

View file

@ -1,13 +0,0 @@
// Copyright(c) .NET Foundation and contributors.All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.InternalAbstractions
{
public enum Platform
{
Unknown = 0,
Windows = 1,
Linux = 2,
Darwin = 3
}
}

View file

@ -1,104 +0,0 @@
// Copyright(c) .NET Foundation and contributors.All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.DotNet.InternalAbstractions.Native;
namespace Microsoft.DotNet.InternalAbstractions
{
public static class RuntimeEnvironment
{
private static readonly string OverrideEnvironmentVariableName = "DOTNET_RUNTIME_ID";
public static Platform OperatingSystemPlatform { get; } = PlatformApis.GetOSPlatform();
public static string OperatingSystemVersion { get; } = PlatformApis.GetOSVersion();
public static string OperatingSystem { get; } = PlatformApis.GetOSName();
public static string RuntimeArchitecture { get; } = GetArch();
private static string GetArch()
{
#if NET451
return Environment.Is64BitProcess ? "x64" : "x86";
#else
return IntPtr.Size == 8 ? "x64" : "x86";
#endif
}
public static string GetRuntimeIdentifier()
{
return
Environment.GetEnvironmentVariable(OverrideEnvironmentVariableName) ??
(GetRIDOS() + GetRIDVersion() + GetRIDArch());
}
private static string GetRIDArch()
{
if (!string.IsNullOrEmpty(RuntimeArchitecture))
{
return $"-{RuntimeArchitecture.ToLowerInvariant()}";
}
return string.Empty;
}
private static string GetRIDVersion()
{
// Windows RIDs do not separate OS name and version by "." due to legacy
// Others do, that's why we have the "." prefix on them below
switch (OperatingSystemPlatform)
{
case Platform.Windows:
return GetWindowsProductVersion();
case Platform.Linux:
return $".{OperatingSystemVersion}";
case Platform.Darwin:
return $".{OperatingSystemVersion}";
default:
return string.Empty; // Unknown Platform? Unknown Version!
}
}
private static string GetWindowsProductVersion()
{
var ver = Version.Parse(OperatingSystemVersion);
if (ver.Major == 6)
{
if (ver.Minor == 1)
{
return "7";
}
else if (ver.Minor == 2)
{
return "8";
}
else if (ver.Minor == 3)
{
return "81";
}
}
else if (ver.Major == 10 && ver.Minor == 0)
{
// Not sure if there will be 10.x (where x > 0) or even 11, so let's be defensive.
return "10";
}
return string.Empty; // Unknown version
}
private static string GetRIDOS()
{
switch (OperatingSystemPlatform)
{
case Platform.Windows:
return "win";
case Platform.Linux:
return OperatingSystem.ToLowerInvariant();
case Platform.Darwin:
return "osx";
default:
return "unknown";
}
}
}
}