Skip to content

Commit

Permalink
Rename IsOSXLike to IsApplePlatform in libraries (#96098)
Browse files Browse the repository at this point in the history
Consolidates the name we use across runtime and libraries.
  • Loading branch information
akoeplinger authored Dec 17, 2023
1 parent 85f87ff commit 17594ec
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task<Connection> EstablishConnectionAsync()
socket.NoDelay = true;
}
// OSX can throw if socket is in weird state during close or cancellation
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.InvalidArgument && PlatformDetection.IsOSXLike) { }
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.InvalidArgument && PlatformDetection.IsApplePlatform) { }

stream = new NetworkStream(socket, ownsSocket: false);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ public static partial class PlatformDetection
public static bool IsNotMonoLinuxArm64 => !IsMonoLinuxArm64;

// OSX family
public static bool IsOSXLike => IsOSX || IsiOS || IstvOS || IsMacCatalyst;
public static bool IsApplePlatform => IsOSX || IsiOS || IstvOS || IsMacCatalyst;
public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
public static bool IsNotOSX => !IsOSX;
public static bool IsMacOsMojaveOrHigher => IsOSX && Environment.OSVersion.Version >= new Version(10, 14);
public static bool IsMacOsCatalinaOrHigher => IsOSX && Environment.OSVersion.Version >= new Version(10, 15);
public static bool IsMacOsAppleSilicon => IsOSX && IsArm64Process;
public static bool IsNotMacOsAppleSilicon => !IsMacOsAppleSilicon;
public static bool IsAppSandbox => Environment.GetEnvironmentVariable("APP_SANDBOX_CONTAINER_ID") != null;
Expand All @@ -50,12 +48,12 @@ public static partial class PlatformDetection
public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily;
public static bool IsNotDebian10 => !IsDebian10;

public static Version OpenSslVersion => !IsOSXLike && !IsWindows && !IsAndroid ?
public static Version OpenSslVersion => !IsApplePlatform && !IsWindows && !IsAndroid ?
GetOpenSslVersion() :
throw new PlatformNotSupportedException();

private static readonly Version s_openssl3Version = new Version(3, 0, 0);
public static bool IsOpenSsl3 => !IsOSXLike && !IsWindows && !IsAndroid && !IsBrowser ?
public static bool IsOpenSsl3 => !IsApplePlatform && !IsWindows && !IsAndroid && !IsBrowser ?
GetOpenSslVersion() >= s_openssl3Version :
false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static partial class PlatformDetection
public static bool IsAppleMobile => IsMacCatalyst || IsiOS || IstvOS;
public static bool IsNotAppleMobile => !IsAppleMobile;
public static bool IsNotNetFramework => !IsNetFramework;
public static bool IsBsdLike => IsOSXLike || IsFreeBSD || IsNetBSD;
public static bool IsBsdLike => IsApplePlatform || IsFreeBSD || IsNetBSD;

public static bool IsArmProcess => RuntimeInformation.ProcessArchitecture == Architecture.Arm;
public static bool IsNotArmProcess => !IsArmProcess;
Expand Down Expand Up @@ -526,7 +526,7 @@ private static bool AndroidGetSslProtocolSupport(SslProtocols protocol)
private static bool GetTls10Support()
{
// on macOS and Android TLS 1.0 is supported.
if (IsOSXLike || IsAndroid)
if (IsApplePlatform || IsAndroid)
{
return true;
}
Expand Down Expand Up @@ -554,7 +554,7 @@ private static bool GetTls11Support()
return GetProtocolSupportFromWindowsRegistry(SslProtocols.Tls11, defaultProtocolSupport: true) && !IsWindows10Version20348OrGreater;
}
// on macOS and Android TLS 1.1 is supported.
else if (IsOSXLike || IsAndroid)
else if (IsApplePlatform || IsAndroid)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool IsLibLdapInstalled
#if NETCOREAPP
if (!_isLibLdapInstalled.HasValue)
{
if (PlatformDetection.IsOSXLike)
if (PlatformDetection.IsApplePlatform)
{
_isLibLdapInstalled = NativeLibrary.TryLoad("libldap.dylib", out _);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void FileSystemWatcher_Filter()
watcher.Filter = "abc.dll";
Assert.Equal("abc.dll", watcher.Filter);

if (!PlatformDetection.IsOSXLike)
if (!PlatformDetection.IsApplePlatform)
{
watcher.Filter = "ABC.DLL";
Assert.Equal("ABC.DLL", watcher.Filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void PingResultValidator(PingReply pingReply, IPAddress[] localIp

private static byte[] GetPingPayload(AddressFamily addressFamily)
// On Unix, Non-root processes cannot send arbitrary data in the ping packet payload
=> Capability.CanUseRawSockets(addressFamily) || PlatformDetection.IsOSXLike
=> Capability.CanUseRawSockets(addressFamily) || PlatformDetection.IsApplePlatform
? TestSettings.PayloadAsBytes
: Array.Empty<byte>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public async Task Connect_DatagramSockets_DontThrowConnectedException_OnSecondAt
await ConnectAsync(s, new IPEndPoint(listenAt, ((IPEndPoint)listener.LocalEndPoint).Port));
Assert.True(s.Connected);
// According to the OSX man page, it's enough connecting to an invalid address to dissolve the connection. (0 port connection returns error on OSX)
await ConnectAsync(s, new IPEndPoint(secondConnection, PlatformDetection.IsOSXLike ? 1 : 0));
await ConnectAsync(s, new IPEndPoint(secondConnection, PlatformDetection.IsApplePlatform ? 1 : 0));
Assert.True(s.Connected);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void IOControl_SIOCATMARK_Unix_Success()

// OOB data read, read pointer at mark.
Assert.Equal(4, client.IOControl(IOControlCode.OobDataRead, null, siocatmarkResult));
Assert.Equal(PlatformDetection.IsOSXLike ? 0 : 1, BitConverter.ToInt32(siocatmarkResult, 0));
Assert.Equal(PlatformDetection.IsApplePlatform ? 0 : 1, BitConverter.ToInt32(siocatmarkResult, 0));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task NotBound_Throws_InvalidOperationException()
[InlineData(true)]
public async Task ReceiveSent_TCP_Success(bool ipv6)
{
if (ipv6 && PlatformDetection.IsOSXLike)
if (ipv6 && PlatformDetection.IsApplePlatform)
{
// [ActiveIssue("https://github.com/dotnet/runtime/issues/47335")]
// accept() will create a (seemingly) DualMode socket on Mac,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task NotBound_Throws_InvalidOperationException()
[InlineData(true)]
public async Task ReceiveSent_TCP_Success(bool ipv6)
{
if (ipv6 && PlatformDetection.IsOSXLike)
if (ipv6 && PlatformDetection.IsApplePlatform)
{
// [ActiveIssue("https://github.com/dotnet/runtime/issues/47335")]
// accept() will create a (seemingly) DualMode socket on Mac,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public async Task SliceBuffers_Success()
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73536", TestPlatforms.iOS | TestPlatforms.tvOS)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/80169", typeof(PlatformDetection), nameof(PlatformDetection.IsOSXLike))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/80169", typeof(PlatformDetection), nameof(PlatformDetection.IsApplePlatform))]
public async Task SendFileGetsCanceledByDispose(bool owning)
{
// Aborting sync operations for non-owning handles is not supported on Unix.
Expand Down Expand Up @@ -300,7 +300,7 @@ await RetryHelper.ExecuteAsync(async () =>
// On OSX, we're unable to unblock the on-going socket operations and
// perform an abortive close.
if (!(UsesSync && PlatformDetection.IsOSXLike))
if (!(UsesSync && PlatformDetection.IsApplePlatform))
{
SocketError? peerSocketError = null;
var receiveBuffer = new byte[4096];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ await socketOperation
// On OSX, we're unable to unblock the on-going socket operations and
// perform an abortive close.
if (!(UsesSync && PlatformDetection.IsOSXLike))
if (!(UsesSync && PlatformDetection.IsApplePlatform))
{
SocketError? peerSocketError = null;
var receiveBuffer = new ArraySegment<byte>(new byte[4096]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<PropertyGroup>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<Nullable>enable</Nullable>
<IsOSXLike Condition="'$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</IsOSXLike>
<IsiOSLike Condition="'$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</IsiOSLike>
<IsApplePlatform Condition="'$(TargetsOSX)' == 'true' or '$(IsiOSLike)' == 'true'">true</IsApplePlatform>
<IsMobileLike Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true' or '$(IsiOSLike)' == 'true' or '$(TargetsAndroid)' == 'true'">true</IsMobileLike>
<SupportsArmIntrinsics Condition="'$(Platform)' == 'arm64'">true</SupportsArmIntrinsics>
<SupportsWasmIntrinsics Condition="'$(Platform)' == 'wasm'">true</SupportsWasmIntrinsics>
Expand Down Expand Up @@ -62,7 +62,7 @@
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.NoArmIntrinsics.xml" Condition="'$(SupportsArmIntrinsics)' != 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.NoX86Intrinsics.xml" Condition="'$(SupportsX86Intrinsics)' != 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.NoWasmIntrinsics.xml" Condition="'$(SupportsWasmIntrinsics)' != 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.OSX.xml" Condition="'$(IsOSXLike)' == 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.OSX.xml" Condition="'$(IsApplePlatform)' == 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.Windows.xml" Condition="'$(TargetsWindows)' == 'true'" />
<ILLinkSubstitutionsXmls Include="$(ILLinkSharedDirectory)ILLink.Substitutions.Browser.xml" Condition="'$(TargetsBrowser)' == 'true'" />
<ILLinkLinkAttributesXmls Include="$(ILLinkSharedDirectory)ILLink.LinkAttributes.Shared.xml" />
Expand Down Expand Up @@ -2459,7 +2459,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Android.cs" Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.NoRegistry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.UnixOrBrowser.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.OSX.cs" Condition="'$(IsOSXLike)' == 'true' AND '$(TargetsMacCatalyst)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.OSX.cs" Condition="'$(IsApplePlatform)' == 'true' AND '$(TargetsMacCatalyst)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.MacCatalyst.cs" Condition="'$(TargetsMacCatalyst)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.GetFolderPathCore.Unix.cs" Condition="'$(IsiOSLike)' != 'true' and '$(TargetsAndroid)' != 'true' and '$(TargetsLinuxBionic)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Variables.Unix.cs" Condition="'$(FeatureCoreCLR)' != 'true'" />
Expand Down Expand Up @@ -2501,7 +2501,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.Android.cs" Condition="'$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.NonAndroid.cs" Condition="'$(TargetsAndroid)' != 'true' and '$(TargetsLinuxBionic)' != 'true'" />
</ItemGroup>
<ItemGroup Condition="('$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(IsOSXLike)' != 'true'">
<ItemGroup Condition="('$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(IsApplePlatform)' != 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStatus.SetTimes.OtherUnix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
Expand All @@ -2525,7 +2525,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Linux.cs" Condition="'$(TargetsLinux)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSX.cs" Condition="'$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.iOS.cs" Condition="'$(IsiOSLike)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.Unix.cs" Condition="'$(IsOSXLike)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.OSVersion.Unix.cs" Condition="'$(IsApplePlatform)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.SunOS.cs" Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.FullGlobalizationData.Unix.cs" Condition="'$(UseMinimalGlobalizationData)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" />
Expand All @@ -2546,7 +2546,7 @@
<ItemGroup Condition="'$(UseMinimalGlobalizationData)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.MinimalGlobalizationData.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsOSXLike)' == 'true'">
<ItemGroup Condition="'$(IsApplePlatform)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\Interop.libobjc.cs">
<Link>Common\Interop\OSX\Interop.libobjc.cs</Link>
</Compile>
Expand All @@ -2559,7 +2559,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStatus.SetTimes.OSX.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileSystem.TryCloneFile.OSX.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsiOSLike)' == 'true' or '$(IsOSXLike)' == 'true'">
<ItemGroup Condition="'$(IsApplePlatform)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.SearchPath.cs">
<Link>Common\Interop\OSX\Interop.SearchPath.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static void FlushToDisk(SafeFileHandle handle)

internal static void Lock(SafeFileHandle handle, bool canWrite, long position, long length)
{
if (OperatingSystem.IsOSXLike() || OperatingSystem.IsFreeBSD())
if (OperatingSystem.IsApplePlatform() || OperatingSystem.IsFreeBSD())
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
Expand All @@ -68,7 +68,7 @@ internal static void Lock(SafeFileHandle handle, bool canWrite, long position, l

internal static void Unlock(SafeFileHandle handle, long position, long length)
{
if (OperatingSystem.IsOSXLike() || OperatingSystem.IsFreeBSD())
if (OperatingSystem.IsApplePlatform() || OperatingSystem.IsFreeBSD())
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OSXFileLocking);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static bool IsMacOS() =>
false;
#endif

internal static bool IsOSXLike() =>
internal static bool IsApplePlatform() =>
#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
true;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void CurrentCulture_DefaultWithNoLang(string langEnvVar)
Assert.NotNull(CultureInfo.CurrentCulture);
Assert.NotNull(CultureInfo.CurrentUICulture);
if (PlatformDetection.IsOSXLike)
if (PlatformDetection.IsApplePlatform)
{
Assert.NotEqual("", CultureInfo.CurrentCulture.Name);
Assert.NotEqual("", CultureInfo.CurrentUICulture.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class File_GetSetTimes : StaticGetSetTimes
{
// OSX has the limitation of setting upto 2262-04-11T23:47:16 (long.Max) date.
// 32bit Unix has time_t up to ~ 2038.
protected static bool SupportsLongMaxDateTime => PlatformDetection.IsWindows || (!PlatformDetection.Is32BitProcess && !PlatformDetection.IsOSXLike);
protected static bool SupportsLongMaxDateTime => PlatformDetection.IsWindows || (!PlatformDetection.Is32BitProcess && !PlatformDetection.IsApplePlatform);

protected override bool CanBeReadOnly => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FileInfo GetNonZeroNanoseconds()

if (!HasNonZeroNanoseconds(fileinfo.LastWriteTime))
{
if (PlatformDetection.IsOSXLike)
if (PlatformDetection.IsApplePlatform)
return null;

DateTime dt = fileinfo.LastWriteTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

internal static class IOInputs
{
public static bool SupportsSettingCreationTime => PlatformDetection.IsWindows || PlatformDetection.IsOSXLike;
public static bool SupportsGettingCreationTime => PlatformDetection.IsWindows || PlatformDetection.IsOSXLike;
public static bool SupportsSettingCreationTime => PlatformDetection.IsWindows || PlatformDetection.IsApplePlatform;
public static bool SupportsGettingCreationTime => PlatformDetection.IsWindows || PlatformDetection.IsApplePlatform;

// Max path length (minus trailing \0). Unix values vary system to system; just using really long values here likely to be more than on the average system.
public static readonly int MaxPath = OperatingSystem.IsWindows() ? 259 : 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ public static void Parse_Japanese()
Assert.Equal(expected, DateTime.Parse(expectedString, cultureInfo));
}

private static bool IsNotOSXOrBrowser => !PlatformDetection.IsOSXLike && !PlatformDetection.IsBrowser;
private static bool IsNotOSXOrBrowser => !PlatformDetection.IsApplePlatform && !PlatformDetection.IsBrowser;

[ConditionalTheory(nameof(IsNotOSXOrBrowser))]
[InlineData("ar")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DSA Create(int keySize)
}

public bool SupportsFips186_3 => false;
public bool SupportsKeyGeneration => !PlatformDetection.IsOSXLike;
public bool SupportsKeyGeneration => !PlatformDetection.IsApplePlatform;
}

public partial class DSAFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public bool SupportsFips186_3
{
get
{
return !(PlatformDetection.IsWindows7 || PlatformDetection.IsOSXLike);
return !(PlatformDetection.IsWindows7 || PlatformDetection.IsApplePlatform);
}
}

public bool SupportsKeyGeneration => !PlatformDetection.IsOSXLike;
public bool SupportsKeyGeneration => !PlatformDetection.IsApplePlatform;
}

public partial class DSAFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class ECDiffieHellmanProvider : IECDiffieHellmanProvider
{
public bool IsCurveValid(Oid oid)
{
if (PlatformDetection.IsOSXLike)
if (PlatformDetection.IsApplePlatform)
{
return false;
}
Expand All @@ -25,7 +25,7 @@ public bool ExplicitCurvesSupported
{
get
{
if (PlatformDetection.IsOSXLike)
if (PlatformDetection.IsApplePlatform)
{
return false;
}
Expand Down
Loading

0 comments on commit 17594ec

Please sign in to comment.