Remove references to PlatformAbstractions. (#7408)

* 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
This commit is contained in:
Eric Erhardt 2020-05-06 09:59:23 -05:00 committed by GitHub
parent ef2ea7d6ae
commit efe7c8e566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 33 additions and 302 deletions

View file

@ -1,206 +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.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.PlatformAbstractions;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
namespace Microsoft.DotNet.Cli.Build.Framework
{
public static class CurrentPlatform
{
public static BuildPlatform Current
{
get
{
return DetermineCurrentPlatform();
}
}
public static bool IsWindows
{
get
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}
}
public static bool IsOSX
{
get
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
}
public static bool IsFreeBSD
{
get
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"));
}
}
public static bool IsUbuntu
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsCentOS
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsRHEL
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "rhel", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsFedora
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "fedora", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsOpenSuse
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "opensuse", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsUnix
{
get
{
return IsLinux || IsOSX || IsFreeBSD;
}
}
public static bool IsDebian
{
get
{
var osname = RuntimeEnvironment.OperatingSystem;
return string.Equals(osname, "debian", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsLinux
{
get
{
return IsUbuntu || IsCentOS || IsRHEL || IsDebian || IsFedora || IsOpenSuse;
}
}
public static bool IsPlatform(BuildPlatform platform, string version = null)
{
return IsPlatform(platform) && (version == null || IsVersion(version));
}
public static bool IsAnyPlatform(params BuildPlatform[] platforms)
{
return platforms.Any(p => IsPlatform(p));
}
public static bool IsPlatform(BuildPlatform platform)
{
switch (platform)
{
case BuildPlatform.Windows:
return IsWindows;
case BuildPlatform.Ubuntu:
return IsUbuntu;
case BuildPlatform.OSX:
return IsOSX;
case BuildPlatform.FreeBSD:
return IsFreeBSD;
case BuildPlatform.CentOS:
return IsCentOS;
case BuildPlatform.RHEL:
return IsRHEL;
case BuildPlatform.Debian:
return IsDebian;
case BuildPlatform.Fedora:
return IsFedora;
case BuildPlatform.OpenSuse:
return IsOpenSuse;
case BuildPlatform.Unix:
return IsUnix;
case BuildPlatform.Linux:
return IsLinux;
default:
throw new Exception("Unrecognized Platform.");
}
}
public static bool IsVersion(string version)
{
return RuntimeEnvironment.OperatingSystemVersion.Equals(version, StringComparison.OrdinalIgnoreCase);
}
private static BuildPlatform DetermineCurrentPlatform()
{
if (IsWindows)
{
return BuildPlatform.Windows;
}
else if (IsOSX)
{
return BuildPlatform.OSX;
}
else if (IsUbuntu)
{
return BuildPlatform.Ubuntu;
}
else if (IsCentOS)
{
return BuildPlatform.CentOS;
}
else if (IsRHEL)
{
return BuildPlatform.RHEL;
}
else if (IsDebian)
{
return BuildPlatform.Debian;
}
else if (IsFedora)
{
return BuildPlatform.Fedora;
}
else if (IsOpenSuse)
{
return BuildPlatform.OpenSuse;
}
else if (IsFreeBSD)
{
return BuildPlatform.FreeBSD;
}
else
{
return default(BuildPlatform);
}
}
}
}

View file

@ -1,47 +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 Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build
{
public class GetCurrentRuntimeInformation : Task
{
[Output]
public string Rid { get; set; }
[Output]
public string OSName { get; set; }
[Output]
public string OSPlatform { get; set; }
public override bool Execute()
{
Rid = RuntimeEnvironment.GetRuntimeIdentifier();
OSName = GetOSShortName();
OSPlatform = RuntimeEnvironment.OperatingSystemPlatform.ToString().ToLower();
return true;
}
private static string GetOSShortName()
{
string osname = "";
switch (CurrentPlatform.Current)
{
case BuildPlatform.Windows:
osname = "win";
break;
default:
osname = CurrentPlatform.Current.ToString().ToLower();
break;
}
return osname;
}
}
}

View file

@ -10,7 +10,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="15.7.179" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.7.179" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="NuGet.Versioning" Version="4.3.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.4.2" />

View file

@ -20,7 +20,6 @@
</Target>
<UsingTask TaskName="CalculateTemplateVersions" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="GetCurrentRuntimeInformation" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="DownloadFile" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="ExtractArchiveToDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />

View file

@ -1,31 +1,31 @@
<Project>
<Target Name="SetupFileExtensions" DependsOnTargets="GetCurrentRuntimeInformation">
<PropertyGroup>
<ArchiveExtension Condition=" '$(HostOSName)' == 'win' ">.zip</ArchiveExtension>
<ArchiveExtension Condition=" '$(HostOSName)' != 'win' ">.tar.gz</ArchiveExtension>
<ArchiveExtension>.tar.gz</ArchiveExtension>
<ArchiveExtension Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) ">.zip</ArchiveExtension>
<InstallerExtension Condition=" '$(HostOSName)' == 'win' ">.msi</InstallerExtension>
<InstallerExtension Condition=" '$(HostOSName)' == 'osx' ">.pkg</InstallerExtension>
<InstallerExtension Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) ">.msi</InstallerExtension>
<InstallerExtension Condition=" $([MSBuild]::IsOSPlatform('OSX')) ">.pkg</InstallerExtension>
<InstallerExtension Condition=" '$(IsDebianBaseDistro)' == 'true' ">.deb</InstallerExtension>
<InstallerExtension Condition=" '$(IsRPMBasedDistro)' == true ">.rpm</InstallerExtension>
<BundleExtension Condition=" '$(HostOSName)' == 'win' ">.exe</BundleExtension>
<BundleExtension Condition=" '$(HostOSName)' == 'osx' ">$(InstallerExtension)</BundleExtension>
<BundleExtension Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) ">.exe</BundleExtension>
<BundleExtension Condition=" $([MSBuild]::IsOSPlatform('OSX')) ">$(InstallerExtension)</BundleExtension>
<BundleExtension Condition=" '$(IsDebianBaseDistro)' == 'true' ">$(InstallerExtension)</BundleExtension>
<BundleExtension Condition=" '$(IsRPMBasedDistro)' == true ">$(InstallerExtension)</BundleExtension>
<DynamicLibPrefix>lib</DynamicLibPrefix>
<DynamicLibPrefix Condition=" '$(HostOSName)' == 'win' "></DynamicLibPrefix>
<DynamicLibPrefix Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) "></DynamicLibPrefix>
<DynamicLibExtension>.so</DynamicLibExtension>
<DynamicLibExtension Condition=" '$(HostOSName)' == 'win' ">.dll</DynamicLibExtension>
<DynamicLibExtension Condition=" '$(HostOSName)' == 'osx' ">.dylib</DynamicLibExtension>
<DynamicLibExtension Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) ">.dll</DynamicLibExtension>
<DynamicLibExtension Condition=" $([MSBuild]::IsOSPlatform('OSX')) ">.dylib</DynamicLibExtension>
<ExeExtension>.exe</ExeExtension>
<ExeExtension Condition=" '$(OS)' != 'Windows_NT' "></ExeExtension>
<ExeExtension Condition=" !$([MSBuild]::IsOSPlatform('WINDOWS')) "></ExeExtension>
<PlatformScriptExtension Condition=" '$(OS)' == 'Windows_NT' ">.ps1</PlatformScriptExtension>
<PlatformScriptExtension Condition=" '$(OS)' != 'Windows_NT' ">.sh</PlatformScriptExtension>
<PlatformScriptExtension>.sh</PlatformScriptExtension>
<PlatformScriptExtension Condition=" $([MSBuild]::IsOSPlatform('WINDOWS')) ">.ps1</PlatformScriptExtension>
</PropertyGroup>
</Target>

View file

@ -34,10 +34,10 @@
<DotnetToolsetBlobRootUrl Condition="'$(DotnetToolsetBlobRootUrl)' == ''">https://dotnetfeed.blob.core.windows.net/dotnet-core/</DotnetToolsetBlobRootUrl>
<CoreSetupRid Condition="'$(CoreSetupRid)' == ''">$(HostRid)</CoreSetupRid>
<CoreSetupRid Condition=" ('$(HostOSName)' == 'win' or '$(HostOSName)' == 'osx' or '$(HostOSName)' == 'freebsd') and '$(DotNetBuildFromSource)' != 'true' ">$(HostMonikerRid)</CoreSetupRid>
<CoreSetupRid Condition=" ('$(OSName)' == 'win' or '$(OSName)' == 'osx' or '$(OSName)' == 'freebsd') and '$(DotNetBuildFromSource)' != 'true' ">$(OSName)-$(Architecture)</CoreSetupRid>
<!-- only the runtime OSX .pkgs have a `-internal` suffix -->
<InstallerStartSuffix Condition="'$(HostOSName)' == 'osx'">-internal</InstallerStartSuffix>
<InstallerStartSuffix Condition="$([MSBuild]::IsOSPlatform('OSX'))">-internal</InstallerStartSuffix>
<!-- Downloaded Installers + Archives -->
@ -77,7 +77,7 @@
<AspNetCoreSharedFxArchiveRid>$(AspNetCoreSharedFxInstallerRid)</AspNetCoreSharedFxArchiveRid>
<AspNetCoreSharedFxInstallerRid Condition="'$(InstallerExtension)' == '.deb' OR '$(InstallerExtension)' == '.rpm'">x64</AspNetCoreSharedFxInstallerRid>
<DownloadedAspNetCoreSharedFxInstallerFileName Condition=" '$(InstallerExtension)' != '' AND '$(HostOSName)' != 'osx' ">aspnetcore-runtime-$(MicrosoftAspNetCoreAppRuntimePackageVersion)-$(AspNetCoreSharedFxInstallerRid)$(InstallerExtension)</DownloadedAspNetCoreSharedFxInstallerFileName>
<DownloadedAspNetCoreSharedFxInstallerFileName Condition=" '$(InstallerExtension)' != '' AND !$([MSBuild]::IsOSPlatform('OSX')) ">aspnetcore-runtime-$(MicrosoftAspNetCoreAppRuntimePackageVersion)-$(AspNetCoreSharedFxInstallerRid)$(InstallerExtension)</DownloadedAspNetCoreSharedFxInstallerFileName>
<!-- Note: we use the "-internal" archives and installers that contain only the aspnetcore shared framework, and shouldn't overlap with Microsoft.NETCore.App. -->
<DownloadedAspNetCoreSharedFxWixLibFileName Condition=" '$(InstallerExtension)' == '.msi' ">aspnetcore-runtime-internal-$(MicrosoftAspNetCoreAppRuntimePackageVersion)-$(AspNetCoreSharedFxInstallerRid).wixlib</DownloadedAspNetCoreSharedFxWixLibFileName>
<DownloadedAspNetTargetingPackInstallerFileName Condition=" '$(InstallerExtension)' != '' ">aspnetcore-targeting-pack-$(MicrosoftAspNetCoreAppRefPackageVersion)$(InstallerExtension)</DownloadedAspNetTargetingPackInstallerFileName>
@ -98,7 +98,7 @@
<CombinedSharedHostAndFrameworkArchive>$(CoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive$(ArchiveExtension)</CombinedSharedHostAndFrameworkArchive>
</PropertyGroup>
<PropertyGroup Condition="'$(HostOSName)' == 'win' And !$(Architecture.StartsWith('arm'))">
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('WINDOWS')) And !$(Architecture.StartsWith('arm'))">
<AlternateAppHostRid>win-$(AlternateArchitecture)</AlternateAppHostRid>
<ArmAppHostRid>win-arm</ArmAppHostRid>
<Arm64AppHostRid>win-arm64</Arm64AppHostRid>

View file

@ -1,23 +1,20 @@
<Project>
<Target Name="GetCurrentRuntimeInformation">
<GetCurrentRuntimeInformation>
<Output TaskParameter="Rid" PropertyName="HostRid" />
<Output TaskParameter="OSName" PropertyName="HostOSName" />
<Output TaskParameter="OSPlatform" PropertyName="HostOSPlatform" />
</GetCurrentRuntimeInformation>
<PropertyGroup>
<IsLinux Condition = " '$(HostOSName)' != 'win' AND '$(HostOSName)' != 'osx' AND '$(HostOSName)' != 'freebsd' ">True</IsLinux>
<OSName Condition=" '$(OSName)' == '' AND '$(IsLinux)' != 'True' ">$(HostOSName)</OSName>
<OSPlatform Condition=" '$(OSPlatform)' == '' AND '$(IsLinux)' != 'True' ">$(HostOSPlatform)</OSPlatform>
<HostRid Condition="'$(HostRid)' == '' and '$(MSBuildRuntimeType)' == 'core'">$([System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier)</HostRid>
<HostRid Condition="'$(HostRid)' == '' and '$(MSBuildRuntimeType)' != 'core'">win-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant)</HostRid>
<IsLinux Condition = " $([MSBuild]::IsOSPlatform('LINUX')) ">True</IsLinux>
<OSName Condition=" '$(OSName)' == '' AND $([MSBuild]::IsOSPlatform('WINDOWS')) ">win</OSName>
<OSName Condition=" '$(OSName)' == '' AND $([MSBuild]::IsOSPlatform('OSX')) ">osx</OSName>
<OSName Condition=" '$(OSName)' == '' AND $([MSBuild]::IsOSPlatform('FREEBSD')) ">freebsd</OSName>
<OSName Condition=" '$(OSName)' == '' AND '$(IsLinux)' == 'True' ">linux</OSName>
<OSPlatform Condition=" '$(OSPlatform)' == '' AND '$(IsLinux)' == 'True' ">linux</OSPlatform>
<Rid Condition=" '$(Rid)' == '' ">$(OSName)-$(Architecture)</Rid>
</PropertyGroup>
<PropertyGroup>
<IsDebianBaseDistro Condition=" '$(HostOSName)' == 'ubuntu' OR '$(HostOSName)' == 'debian' ">true</IsDebianBaseDistro>
<IsDebianBaseDistro Condition=" $(HostRid.StartsWith('ubuntu')) OR $(HostRid.StartsWith('debian')) ">true</IsDebianBaseDistro>
<IsRPMBasedDistro Condition=" $(HostRid.StartsWith('rhel')) AND '$(HostRid)' != 'rhel.6-x64' ">true</IsRPMBasedDistro>
<PublishNativeInstallers Condition=" '$(IslinuxPortable)' != 'true' AND '$(HostRid)' != 'rhel.6-x64' AND '$(HostRid)' != 'linux-musl-x64'">true</PublishNativeInstallers>
<PublishArchives Condition=" '$(IslinuxPortable)' == 'true' OR ('$(IsDebianBaseDistro)' != 'true' AND '$(IsRPMBasedDistro)' != 'true') ">true</PublishArchives>
@ -29,13 +26,6 @@
'$(Rid)' == 'linux-musl-x64' ">$(Rid)</ProductMonikerRid>
<ProductMonikerRid Condition=" '$(ProductMonikerRid)' == '' ">$(OSName)-$(Architecture)</ProductMonikerRid>
<HostMonikerRid Condition=" '$(HostRid)' == 'ubuntu.16.04-x64' OR
'$(HostRid)' == 'rhel.6-x64' OR
'$(HostRid)' == 'linux-musl-x64' ">$(HostRid)</HostMonikerRid>
<HostMonikerRid Condition=" '$(HostMonikerRid)' == '' ">$(HostOSName)-$(Architecture)</HostMonikerRid>
<HostMonikerRidForFileName>$(HostMonikerRid)</HostMonikerRidForFileName>
<HostMonikerRidForFileName Condition=" '$(IsDebianBaseDistro)' == 'true' OR '$(IsRPMBasedDistro)' == 'true' ">$(Architecture)</HostMonikerRidForFileName>
<ArtifactNameSdk>dotnet-sdk-internal</ArtifactNameSdk>
<ArtifactNameCombinedHostHostFxrFrameworkSdk>dotnet-sdk</ArtifactNameCombinedHostHostFxrFrameworkSdk>
@ -45,8 +35,7 @@
<!-- Warning: changing the value "ProductBandCombinedHostHostFxrFrameworkSdkName" can only occur on a product-band boundary [CliProductBandVersion],
Changing "ProductBandCombinedHostHostFxrFrameworkSdkName" mid-product-band will break the upgradablilty of the SDK bundle installer. -->
<ProductBandCombinedHostHostFxrFrameworkSdkName>Dotnet SDK Bundle Installer $(CliProductBandVersion) $(ProductMonikerRid)</ProductBandCombinedHostHostFxrFrameworkSdkName>
<DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdkWithoutHostMonikerRid>$(ArtifactNameCombinedHostHostFxrFrameworkSdk)-$(Version)-</DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdkWithoutHostMonikerRid>
<DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk>$(DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdkWithoutHostMonikerRid)$(HostMonikerRidForFileName)</DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk>
<DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk>$(ArtifactNameCombinedHostHostFxrFrameworkSdk)-$(Version)-$(Architecture)</DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk>
</PropertyGroup>
</Target>
</Project>

View file

@ -12,7 +12,7 @@
OR $(Rid.StartsWith('ubuntu.18.04')))">true</SkipBuildingInstallers>
<SkipBuildingInstallers Condition=" '$(SkipBuildingInstallers)' == '' ">false</SkipBuildingInstallers>
<UsePortableLinuxSharedFramework Condition=" '$(UsePortableLinuxSharedFramework)' == '' AND '$(OSPlatform)' == 'linux' AND '$(Rid)' != 'rhel.6-x64' AND '$(Rid)' != 'linux-musl-x64' ">true</UsePortableLinuxSharedFramework>
<UsePortableLinuxSharedFramework Condition=" '$(UsePortableLinuxSharedFramework)' == '' AND '$(IsLinux)' == 'True' AND '$(Rid)' != 'rhel.6-x64' AND '$(Rid)' != 'linux-musl-x64' ">true</UsePortableLinuxSharedFramework>
<!--<IncludeSharedFrameworksForBackwardsCompatibilityTests Condition=" $(IncludeSharedFrameworksForBackwardsCompatibilityTests) == ''
AND '$(Rid)' != 'linux-x64'
AND '$(Rid)' != 'rhel.6-x64'

View file

@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
// 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.Linq;
using System.Xml.Linq;
using FluentAssertions;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.ProjectModel;
using NuGet.Versioning;

View file

@ -1,9 +1,9 @@
using System;
// 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.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;

View file

@ -5,9 +5,7 @@ using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using FluentAssertions;
using Microsoft.DotNet.PlatformAbstractions;
namespace Microsoft.DotNet.Tools.Test.Utilities
{