From 78b3f51220606d80aa7fd692ab06b34d472f5951 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 31 Mar 2020 16:05:38 -0500 Subject: [PATCH] Remove references to PlatformAbstractions. This will allow us to remove the PlatformAbstractions library from dotnet/runtime. Contributes to https://github.com/dotnet/runtime/issues/3470 --- eng/Version.Details.xml | 6 +- eng/Versions.props | 4 +- .../Microsoft.DotNet.Cli.Utils/Constants.cs | 6 +- .../DangerousFileDetector.cs | 4 +- .../Microsoft.DotNet.Cli.Utils/DotnetFiles.cs | 1 - .../EnvironmentProvider.cs | 6 +- .../FileNameSuffixes.cs | 31 +- .../FrameworkDependencyFile.cs | 12 +- .../Microsoft.DotNet.Cli.Utils.csproj | 1 - .../Microsoft.DotNet.Cli.Utils/PathUtility.cs | 8 +- .../ProcessReaper.cs | 13 +- .../RuntimeEnvironment.cs | 372 ++++++++++++++++++ .../RuntimeEnvironmentRidExtensions.cs | 33 -- .../AppBaseCommandResolver.cs | 4 +- .../AppBaseDllCommandResolver.cs | 4 +- .../DefaultCommandResolverPolicy.cs | 4 +- .../DotnetToolsCommandResolver.cs | 6 +- .../LocalToolsCommandResolver.cs | 7 +- .../PathCommandResolverPolicy.cs | 4 +- .../ScriptCommandResolverPolicy.cs | 4 +- .../MulticoreJitProfilePathCalculator.cs | 3 +- src/Cli/dotnet/Program.cs | 10 +- src/Cli/dotnet/ShellShim/AppHostShimMaker.cs | 4 +- .../dotnet/ShellShim/ShellShimRepository.cs | 2 - .../DockerContainerDetectorForTelemetry.cs | 50 +-- .../Telemetry/ExternalTelemetryProperties.cs | 14 +- src/Cli/dotnet/Telemetry/Telemetry.cs | 3 - .../Telemetry/TelemetryCommonProperties.cs | 12 +- .../dotnet-tool/install/ProjectRestorer.cs | 2 - src/Cli/dotnet/dotnet.csproj | 1 - .../targets/GetRuntimeInformation.targets | 3 - src/Layout/toolset-tasks/CurrentPlatform.cs | 50 +-- .../GetCurrentRuntimeInformation.cs | 6 +- src/Layout/toolset-tasks/toolset-tasks.csproj | 8 +- .../FrameworkReferenceResolver.cs | 5 +- .../Microsoft.NET.Build.Tasks.csproj | 2 - .../ArgumentForwarding.Tests.csproj | 4 - .../EndToEnd.Tests/EndToEnd.Tests.csproj | 4 - .../GivenAProjectPathCommandResolver.cs | 2 - .../GivenAnAppBaseCommandResolver.cs | 2 - .../Microsoft.NET.Build.Tests/AppHostTests.cs | 9 +- ...GivenThatWeWantToBuildAComServerLibrary.cs | 5 +- ...WantToBuildASolutionWithProjRefDiffCase.cs | 8 +- ...atWeWantToBuildAnAppWithLibrariesAndRid.cs | 6 +- .../GivenThatWeWantToCopyLocalDependencies.cs | 1 - ...enThatWeWantToFilterSatelliteAssemblies.cs | 9 +- .../GivenThatWeWantToUseVB.cs | 1 - ...venWeWantToRequireWindowsForDesktopApps.cs | 7 +- ...enThatWeWantToPackACrossTargetedLibrary.cs | 3 - .../GivenThatWeWantToPackASimpleLibrary.cs | 3 - .../FilesCopiedToPublishDirTests.cs | 9 +- ...nThatWeWantToExcludeAPackageFromPublish.cs | 9 +- ...enThatWeWantToFilterSatelliteAssemblies.cs | 7 +- ...atWeWantToPublishAFrameworkDependentApp.cs | 7 +- ...enThatWeWantToPublishAHelloWorldProject.cs | 4 - ...WeWantToPublishAProjectWithDependencies.cs | 2 +- ...venThatWeWantToPublishASelfContainedApp.cs | 6 +- .../GivenThatWeWantToPublishASingleFileApp.cs | 6 +- .../GivenThatWeWantToPublishAWebApp.cs | 1 - ...WeWantToPublishAnAppWithLibrariesAndRid.cs | 9 +- ...atWeWantToPublishAnUnpublishableProject.cs | 7 +- .../GivenThatWeWantToPublishReadyToRun.cs | 2 +- .../GivenThatWeWantToRunILLink.cs | 4 +- ...atWeWantToStoreAProjectWithDependencies.cs | 2 +- .../PublishItemsOutputGroupTests.cs | 9 +- .../PublishWebApp.cs | 14 +- .../PublishWpfApp.cs | 19 +- .../AssertionHelper.cs | 4 +- .../CoreMSBuildAndWindowsOnlyFactAttribute.cs | 5 +- ...oreMSBuildAndWindowsOnlyTheoryAttribute.cs | 5 +- .../CoreMSBuildOnlyFactAttribute.cs | 2 - .../CoreMSBuildOnlyTheoryAttribute.cs | 1 - .../Attributes/PlatformSpecificFact.cs | 13 +- .../Attributes/PlatformSpecificTheory.cs | 6 +- .../Attributes/UnixOnlyFactAttribute.cs | 4 +- .../Attributes/UnixOnlyTheoryAttribute.cs | 10 +- .../Attributes/WindowsOnlyFactAttribute.cs | 4 +- .../Attributes/WindowsOnlyTheoryAttribute.cs | 4 +- .../Commands/ComposeStoreCommand.cs | 4 - .../Commands/PublishCommand.cs | 5 - .../Commands/SdkCommandSpec.cs | 9 +- .../EnvironmentInfo.cs | 9 +- .../LinuxOnlyFactAttribute.cs | 4 +- .../MacOsOnlyFactAttribute.cs | 4 +- .../Microsoft.NET.TestFramework.csproj | 1 + .../GivenThatWeWantToPackAToolProject.cs | 4 +- .../GivenDotnetPublishPublishesProjects.cs | 10 +- .../GivenDotnetRunRunsCsProj.cs | 3 +- .../GivenDotnetStoresAndPublishesProjects.cs | 5 +- .../GivenThatIWantToManageMulticoreJIT.cs | 5 +- .../TelemetryCommonPropertiesTests.cs | 4 +- src/Tests/dotnet.Tests/dotnet.Tests.csproj | 1 - toolset/eng/Versions.props | 2 - .../binding-redirects.Tests.csproj | 4 - 94 files changed, 595 insertions(+), 423 deletions(-) create mode 100644 src/Cli/Microsoft.DotNet.Cli.Utils/RuntimeEnvironment.cs delete mode 100644 src/Cli/Microsoft.DotNet.Cli.Utils/RuntimeEnvironmentRidExtensions.cs diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 9c2c9ca9df02..e7ad995c1cdd 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -13,9 +13,9 @@ https://github.com/dotnet/runtime 6e83eafe49ce3c55e9f68ae669f24957e5b482f8 - - https://github.com/dotnet/runtime - 6e83eafe49ce3c55e9f68ae669f24957e5b482f8 + + https://github.com/dotnet/arcade + bce0a98620c1c5a110b2bba9912f3d5929069c6b https://github.com/dotnet/runtime diff --git a/eng/Versions.props b/eng/Versions.props index 57c0babd8715..2e5ec8d5693a 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -18,7 +18,6 @@ 2.1.0-preview2-26306-03 2.0.0 2.0.1-servicing-26011-01 - 2.0.0 11.0.1 $(NewtonsoftJsonPackageVersion) 4.0.0 @@ -30,11 +29,9 @@ 5.0.0-preview.4.20213.12 5.0.0-preview.4.20213.12 $(MicrosoftNETCoreAppRuntimewinx64PackageVersion) - 5.0.0-preview.4.20213.12 5.0.0-preview.4.20202.18 5.0.0-preview.4.20213.12 5.0.0-preview.4.20213.12 - $(MicrosoftDotNetPlatformAbstractionsPackageVersion) $(MicrosoftExtensionsDependencyModelPackageVersion) @@ -133,6 +130,7 @@ 4.19.2 4.19.0 + 5.0.0-beta.20201.2 .exe diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs index 20a8cba23ef4..71edc1dc274d 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/Constants.cs @@ -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"; diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs index 3dbc53af92a7..9c8925a8c06e 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs @@ -4,8 +4,6 @@ using System; using System.IO; using System.Runtime.InteropServices; -using Microsoft.DotNet.PlatformAbstractions; -using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment; namespace Microsoft.DotNet.Cli.Utils { @@ -13,7 +11,7 @@ internal class DangerousFileDetector : IDangerousFileDetector { public bool IsDangerous(string filePath) { - if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return false; } diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs index 9e6a39533904..462107f00648 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/DotnetFiles.cs @@ -5,7 +5,6 @@ using System.IO; using System.Reflection; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.PlatformAbstractions; namespace Microsoft.DotNet.Cli { diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs index f0a9fefbe982..22365f3e99cd 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs @@ -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 { @@ -24,7 +24,7 @@ public IEnumerable ExecutableExtensions if (_executableExtensions == null) { - _executableExtensions = RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows + _executableExtensions = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Environment.GetEnvironmentVariable("PATHEXT") .Split(';') .Select(e => e.ToLower().Trim('"')) @@ -41,7 +41,7 @@ private IEnumerable SearchPaths { if (_searchPaths == null) { - var searchPaths = new List { ApplicationEnvironment.ApplicationBasePath }; + var searchPaths = new List { AppContext.BaseDirectory }; searchPaths.AddRange(Environment .GetEnvironmentVariable("PATH") diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs index 48c149c740db..80ed0672f22c 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/FileNameSuffixes.cs @@ -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 { @@ -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"); } } } diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs b/src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs index b91f35fa0a2d..d8d7e75f3ac1 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/FrameworkDependencyFile.cs @@ -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 @@ -28,11 +27,6 @@ public FrameworkDependencyFile() _dependencyContext = new Lazy(CreateDependencyContext); } - public bool SupportsCurrentRuntime() - { - return IsRuntimeSupported(RuntimeEnvironment.GetRuntimeIdentifier()); - } - public bool IsRuntimeSupported(string runtimeIdentifier) { return DependencyContext.RuntimeGraph.Any(g => g.Runtime == runtimeIdentifier); @@ -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, diff --git a/src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj b/src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj index f48732109c52..556effc7b3ac 100644 --- a/src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj +++ b/src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj @@ -16,7 +16,6 @@ -