Skip to content

Commit

Permalink
Remove references to PlatformAbstractions. (#11076)
Browse files Browse the repository at this point in the history
* Remove references to PlatformAbstractions.

This will allow us to remove the PlatformAbstractions library from dotnet/runtime.

Contributes to dotnet/runtime#3470

* Remove as many references to RuntimeEnvironment as possible.

* Add tests for RuntimeEnvironment. Respond to PR feedback.
  • Loading branch information
eerhardt authored Apr 17, 2020
1 parent af10fe4 commit 873d79d
Show file tree
Hide file tree
Showing 98 changed files with 590 additions and 635 deletions.
6 changes: 3 additions & 3 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>6e83eafe49ce3c55e9f68ae669f24957e5b482f8</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.PlatformAbstractions" Version="5.0.0-preview.4.20213.12">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>6e83eafe49ce3c55e9f68ae669f24957e5b482f8</Sha>
<Dependency Name="Microsoft.DotNet.XUnitExtensions" Version="5.0.0-beta.20201.2">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>bce0a98620c1c5a110b2bba9912f3d5929069c6b</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.HostModel" Version="5.0.0-preview.4.20213.12">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand Down
4 changes: 1 addition & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<MicrosoftExtensionsDependencyModelVersion>2.1.0-preview2-26306-03</MicrosoftExtensionsDependencyModelVersion>
<MicrosoftApplicationInsightsPackageVersion>2.0.0</MicrosoftApplicationInsightsPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.1-servicing-26011-01</NETStandardLibraryNETFrameworkVersion>
<PlatformAbstractionsVersion>2.0.0</PlatformAbstractionsVersion>
<NewtonsoftJsonPackageVersion>11.0.1</NewtonsoftJsonPackageVersion>
<NewtonsoftJsonVersion>$(NewtonsoftJsonPackageVersion)</NewtonsoftJsonVersion>
<SystemDiagnosticsFileVersionInfoVersion>4.0.0</SystemDiagnosticsFileVersionInfoVersion>
Expand All @@ -30,11 +29,9 @@
<MicrosoftNETCoreAppRefPackageVersion>5.0.0-preview.4.20213.12</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-preview.4.20213.12</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
<MicrosoftNETCoreAppRuntimePackageVersion>$(MicrosoftNETCoreAppRuntimewinx64PackageVersion)</MicrosoftNETCoreAppRuntimePackageVersion>
<MicrosoftDotNetPlatformAbstractionsPackageVersion>5.0.0-preview.4.20213.12</MicrosoftDotNetPlatformAbstractionsPackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>5.0.0-preview.4.20202.18</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftNETCoreDotNetHostResolverPackageVersion>5.0.0-preview.4.20213.12</MicrosoftNETCoreDotNetHostResolverPackageVersion>
<MicrosoftNETHostModelVersion>5.0.0-preview.4.20213.12</MicrosoftNETHostModelVersion>
<PlatformAbstractionsVersion>$(MicrosoftDotNetPlatformAbstractionsPackageVersion)</PlatformAbstractionsVersion>
<MicrosoftExtensionsDependencyModelVersion>$(MicrosoftExtensionsDependencyModelPackageVersion)</MicrosoftExtensionsDependencyModelVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -133,6 +130,7 @@
<PropertyGroup>
<FluentAssertionsVersion>4.19.2</FluentAssertionsVersion>
<FluentAssertionsJsonVersion>4.19.0</FluentAssertionsJsonVersion>
<MicrosoftDotNetXUnitExtensionsVersion>5.0.0-beta.20201.2</MicrosoftDotNetXUnitExtensionsVersion>
</PropertyGroup>
<PropertyGroup>
<ExeExtension>.exe</ExeExtension>
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// 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 Microsoft.DotNet.PlatformAbstractions;
using System.Runtime.InteropServices;

namespace Microsoft.DotNet.Cli.Utils
{
public static class Constants
{
private static Platform CurrentPlatform => RuntimeEnvironment.OperatingSystemPlatform;
public const string DefaultConfiguration = "Debug";

public static readonly string ProjectFileName = "project.json";
public static readonly string DotConfigDirectoryName = ".config";
public static readonly string ExeSuffix = CurrentPlatform == Platform.Windows ? ".exe" : string.Empty;
public static readonly string ExeSuffix =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;

public static readonly string BinDirectoryName = "bin";
public static readonly string ObjDirectoryName = "obj";
Expand Down
4 changes: 1 addition & 3 deletions src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.PlatformAbstractions;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.DotNet.Cli.Utils
{
internal class DangerousFileDetector : IDangerousFileDetector
{
public bool IsDangerous(string filePath)
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return false;
}
Expand Down
1 change: 0 additions & 1 deletion src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Reflection;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;

namespace Microsoft.DotNet.Cli
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Microsoft.DotNet.Cli.Utils/DotnetVersionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal class DotnetVersionFile
/// The runtime identifier (rid) that this CLI was built for.
/// </summary>
/// <remarks>
/// This is different than RuntimeEnvironment.GetRuntimeIdentifier() because the
/// This is different than RuntimeInformation.RuntimeIdentifier because the
/// BuildRid is a RID that is guaranteed to exist and works on the current machine. The
/// RuntimeEnvironment.GetRuntimeIdentifier() may be for a new version of the OS that
/// RuntimeInformation.RuntimeIdentifier may be for a new version of the OS that
/// doesn't have full support yet.
/// </remarks>
public string BuildRid { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.PlatformAbstractions;
using System.Runtime.InteropServices;

namespace Microsoft.DotNet.Cli.Utils
{
Expand All @@ -24,7 +24,7 @@ public IEnumerable<string> ExecutableExtensions
if (_executableExtensions == null)
{

_executableExtensions = RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows
_executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Environment.GetEnvironmentVariable("PATHEXT")
.Split(';')
.Select(e => e.ToLower().Trim('"'))
Expand All @@ -41,7 +41,7 @@ private IEnumerable<string> SearchPaths
{
if (_searchPaths == null)
{
var searchPaths = new List<string> { ApplicationEnvironment.ApplicationBasePath };
var searchPaths = new List<string> { AppContext.BaseDirectory };

searchPaths.AddRange(Environment
.GetEnvironmentVariable("PATH")
Expand Down
31 changes: 19 additions & 12 deletions src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Microsoft.DotNet.PlatformAbstractions;
using System.Runtime.InteropServices;

namespace Microsoft.DotNet.Cli.Utils
{
Expand All @@ -16,18 +16,25 @@ public static PlatformFileNameSuffixes CurrentPlatform
{
get
{
switch (RuntimeEnvironment.OperatingSystemPlatform)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
case Platform.Windows:
return Windows;
case Platform.Darwin:
return OSX;
case Platform.Linux:
return Linux;
case Platform.FreeBSD:
return FreeBSD;
default:
throw new InvalidOperationException("Unknown Platform");
return Windows;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return OSX;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return Linux;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")))
{
return FreeBSD;
}
else
{
throw new InvalidOperationException("Unknown Platform");
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.PlatformAbstractions;

using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyModel;

namespace Microsoft.DotNet.Cli.Utils
Expand All @@ -28,11 +27,6 @@ public FrameworkDependencyFile()
_dependencyContext = new Lazy<DependencyContext>(CreateDependencyContext);
}

public bool SupportsCurrentRuntime()
{
return IsRuntimeSupported(RuntimeEnvironment.GetRuntimeIdentifier());
}

public bool IsRuntimeSupported(string runtimeIdentifier)
{
return DependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier);
Expand All @@ -46,18 +40,20 @@ public string GetNetStandardLibraryVersion()
?.Version;
}

#if NETCOREAPP
public bool TryGetMostFitRuntimeIdentifier(
string alternativeCurrentRuntimeIdentifier,
string[] candidateRuntimeIdentifiers,
out string mostFitRuntimeIdentifier)
{
return TryGetMostFitRuntimeIdentifier(
RuntimeEnvironment.GetRuntimeIdentifier(),
RuntimeInformation.RuntimeIdentifier,
alternativeCurrentRuntimeIdentifier,
DependencyContext.RuntimeGraph,
candidateRuntimeIdentifiers,
out mostFitRuntimeIdentifier);
}
#endif

internal static bool TryGetMostFitRuntimeIdentifier(
string currentRuntimeIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(MicrosoftDotNetPlatformAbstractionsPackageVersion)" />
<PackageReference Include="NuGet.Versioning" Version="$(NuGetVersioningPackageVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NuGetPackagingPackageVersion)" />
<!-- nuget moved all type from NuGet.Packaging.Core to NuGet.Packaging and added type forwarding in 5.0.0-rtm.5821.
Expand Down
8 changes: 4 additions & 4 deletions src/Cli/Microsoft.DotNet.Cli.Utils/PathUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;

namespace Microsoft.DotNet.Tools.Common
{
Expand Down Expand Up @@ -152,7 +152,7 @@ public static string GetRelativePath(string path1, string path2, char separator,
}

StringComparison compare;
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
compare = StringComparison.OrdinalIgnoreCase;
// check if paths are on the same volume
Expand Down Expand Up @@ -288,7 +288,7 @@ public static string RemoveExtraPathSeparators(string path)
result = component;

// On Windows, manually append a separator for drive references because Path.Combine won't do so
if (result.EndsWith(":") && RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (result.EndsWith(":") && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
result += Path.DirectorySeparatorChar;
}
Expand All @@ -311,7 +311,7 @@ public static bool HasExtension(this string filePath, string extension)
{
var comparison = StringComparison.Ordinal;

if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
comparison = StringComparison.OrdinalIgnoreCase;
}
Expand Down
13 changes: 6 additions & 7 deletions src/Cli/Microsoft.DotNet.Cli.Utils/ProcessReaper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// 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.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.Win32.SafeHandles;

using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.DotNet.Cli.Utils
{
/// <summary>
Expand Down Expand Up @@ -37,7 +36,7 @@ public ProcessReaper(Process process)
// where the child writes output the test expects before the intermediate dotnet process
// has registered the event handlers to handle the signals the tests will generate.
Console.CancelKeyPress += HandleCancelKeyPress;
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
_shutdownMutex = new Mutex();
AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
Expand All @@ -49,7 +48,7 @@ public ProcessReaper(Process process)
/// </summary>
public void NotifyProcessStarted()
{
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Limit the use of job objects to versions of Windows that support nested jobs (i.e. Windows 8/2012 or later).
// Ideally, we would check for some new API export or OS feature instead of the OS version,
Expand All @@ -66,7 +65,7 @@ public void NotifyProcessStarted()

public void Dispose()
{
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (_job != null)
{
Expand Down
Loading

0 comments on commit 873d79d

Please sign in to comment.