Skip to content

Commit

Permalink
Remove references to PlatformAbstractions.
Browse files Browse the repository at this point in the history
This will allow us to remove the PlatformAbstractions library from dotnet/runtime.

Contributes to dotnet/runtime#3470
  • Loading branch information
eerhardt committed Mar 31, 2020
1 parent 0d61183 commit ac3677c
Show file tree
Hide file tree
Showing 93 changed files with 593 additions and 423 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>c74407fcaff466a17b6e98f1dcc969248de506fe</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.PlatformAbstractions" Version="5.0.0-preview.3.20180.15">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>c74407fcaff466a17b6e98f1dcc969248de506fe</Sha>
<Dependency Name="Microsoft.DotNet.XUnitExtensions" Version="5.0.0-beta.20171.1">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>7dbc907fa03eacf4c57f827cb4235d77b7ed4fcd</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.HostModel" Version="5.0.0-preview.3.20180.15">
<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.3.20180.15</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftNETCoreAppRuntimewinx64PackageVersion>5.0.0-preview.3.20180.15</MicrosoftNETCoreAppRuntimewinx64PackageVersion>
<MicrosoftNETCoreAppRuntimePackageVersion>$(MicrosoftNETCoreAppRuntimewinx64PackageVersion)</MicrosoftNETCoreAppRuntimePackageVersion>
<MicrosoftDotNetPlatformAbstractionsPackageVersion>5.0.0-preview.3.20180.15</MicrosoftDotNetPlatformAbstractionsPackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>5.0.0-preview.3-runtime.20180.15</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftNETCoreDotNetHostResolverPackageVersion>5.0.0-preview.3.20180.15</MicrosoftNETCoreDotNetHostResolverPackageVersion>
<MicrosoftNETHostModelVersion>5.0.0-preview.3.20180.15</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.20171.1</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
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 @@ -7,6 +7,7 @@
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<IsPackable>true</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,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 ac3677c

Please sign in to comment.