Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f9b54a8

Browse files
committed
Merge pull request #2068 from jasonwilliams200OK/master
Adds FreeBSD support to S.RT.I.RI
2 parents 318d768 + 64b7f87 commit f9b54a8

File tree

5 files changed

+63
-31
lines changed

5 files changed

+63
-31
lines changed

src/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.sln

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1212
Debug|Any CPU = Debug|Any CPU
13+
FreeBSD_Debug|Any CPU = FreeBSD_Debug|Any CPU
14+
FreeBSD_Release|Any CPU = FreeBSD_Release|Any CPU
1315
Linux_Debug|Any CPU = Linux_Debug|Any CPU
1416
Linux_Release|Any CPU = Linux_Release|Any CPU
1517
OSX_Debug|Any CPU = OSX_Debug|Any CPU
@@ -19,8 +21,10 @@ Global
1921
Windows_Release|Any CPU = Windows_Release|Any CPU
2022
EndGlobalSection
2123
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22-
{F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
23-
{F9DF2357-81B4-4317-908E-512DA9395583}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
24+
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.ActiveCfg = FreeBSD_Debug|Any CPU
25+
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Debug|Any CPU.Build.0 = FreeBSD_Debug|Any CPU
26+
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.ActiveCfg = FreeBSD_Release|Any CPU
27+
{F9DF2357-81B4-4317-908E-512DA9395583}.FreeBSD_Release|Any CPU.Build.0 = FreeBSD_Release|Any CPU
2428
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU
2529
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU
2630
{F9DF2357-81B4-4317-908E-512DA9395583}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU
@@ -29,14 +33,14 @@ Global
2933
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Debug|Any CPU.Build.0 = OSX_Debug|Any CPU
3034
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU
3135
{F9DF2357-81B4-4317-908E-512DA9395583}.OSX_Release|Any CPU.Build.0 = OSX_Release|Any CPU
32-
{F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
33-
{F9DF2357-81B4-4317-908E-512DA9395583}.Release|Any CPU.Build.0 = Windows_Release|Any CPU
3436
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
3537
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
3638
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
3739
{F9DF2357-81B4-4317-908E-512DA9395583}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU
38-
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39-
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.FreeBSD_Release|Any CPU.Build.0 = Release|Any CPU
4044
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU
4145
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU
4246
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -45,8 +49,6 @@ Global
4549
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Debug|Any CPU.Build.0 = Debug|Any CPU
4650
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.ActiveCfg = Release|Any CPU
4751
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.OSX_Release|Any CPU.Build.0 = Release|Any CPU
48-
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
49-
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Release|Any CPU.Build.0 = Release|Any CPU
5052
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
5153
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
5254
{9B4D1DA9-AA4C-428F-9F66-D45C924025A5}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU

src/System.Runtime.InteropServices.RuntimeInformation/src/OSPlatform.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,37 @@ public struct OSPlatform : IEquatable<OSPlatform>
77
{
88
private readonly string _osPlatform;
99

10-
private const string WindowsName = "WINDOWS";
10+
private const string FreeBSDName = "FREEBSD";
1111
private const string LinuxName = "LINUX";
1212
private const string OSXName = "OSX";
13+
private const string WindowsName = "WINDOWS";
1314

14-
private static readonly OSPlatform s_windows = new OSPlatform(WindowsName);
15+
private static readonly OSPlatform s_freebsd = new OSPlatform(FreeBSDName);
1516
private static readonly OSPlatform s_linux = new OSPlatform(LinuxName);
1617
private static readonly OSPlatform s_osx = new OSPlatform(OSXName);
18+
private static readonly OSPlatform s_windows = new OSPlatform(WindowsName);
1719

18-
public static OSPlatform Windows
20+
public static OSPlatform Linux
1921
{
2022
get
2123
{
22-
return s_windows;
24+
return s_linux;
2325
}
2426
}
2527

26-
public static OSPlatform Linux
28+
public static OSPlatform OSX
2729
{
2830
get
2931
{
30-
return s_linux;
32+
return s_osx;
3133
}
3234
}
3335

34-
public static OSPlatform OSX
36+
public static OSPlatform Windows
3537
{
3638
get
3739
{
38-
return s_osx;
40+
return s_windows;
3941
}
4042
}
4143

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace System.Runtime.InteropServices
5+
{
6+
public static class RuntimeInformation
7+
{
8+
private static OSPlatform s_freeBSD = OSPlatform.Create("FREEBSD");
9+
10+
public static bool IsOSPlatform(OSPlatform osPlatform)
11+
{
12+
return s_freeBSD == osPlatform;
13+
}
14+
}
15+
}

src/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@
1111
<ProjectGuid>{F9DF2357-81B4-4317-908E-512DA9395583}</ProjectGuid>
1212
</PropertyGroup>
1313
<!-- Help VS understand available configurations -->
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Debug|AnyCPU' " />
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'FreeBSD_Release|AnyCPU' " />
1416
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Debug|AnyCPU' " />
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Linux_Release|AnyCPU' " />
1618
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Debug|AnyCPU' " />
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OSX_Release|AnyCPU' " />
1820
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows_Debug|AnyCPU' " />
1921
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows_Release|AnyCPU' " />
20-
<ItemGroup Condition=" '$(TargetsWindows)' == 'true' ">
21-
<Compile Include="RuntimeInformation.Windows.cs" />
22+
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true' ">
23+
<Compile Include="RuntimeInformation.FreeBSD.cs" />
2224
</ItemGroup>
2325
<ItemGroup Condition=" '$(TargetsLinux)' == 'true' ">
2426
<Compile Include="RuntimeInformation.Linux.cs" />
2527
</ItemGroup>
2628
<ItemGroup Condition=" '$(TargetsOSX)' == 'true' ">
2729
<Compile Include="RuntimeInformation.OSX.cs" />
2830
</ItemGroup>
31+
<ItemGroup Condition=" '$(TargetsWindows)' == 'true' ">
32+
<Compile Include="RuntimeInformation.Windows.cs" />
33+
</ItemGroup>
2934
<ItemGroup>
3035
<None Include="project.json" />
3136
</ItemGroup>

src/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22
using Xunit;
33

44
namespace System.Runtime.InteropServices.RuntimeInformationTests
55
{
66
public class CheckPlatformTests
77
{
8-
[Fact, PlatformSpecific(PlatformID.Windows)]
9-
public void CheckWindows()
10-
{
11-
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
12-
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS")));
13-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows")));
14-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT")));
15-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
16-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
17-
}
18-
198
[Fact, PlatformSpecific(PlatformID.Linux)]
209
public void CheckLinux()
2110
{
2211
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
2312
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
13+
14+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
2415
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
2516
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
2617
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
@@ -34,14 +25,29 @@ public void CheckOSX()
3425
{
3526
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
3627
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("OSX")));
28+
29+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
30+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
3731
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
3832
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
3933
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
4034
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
41-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
4235
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
4336
}
4437

38+
[Fact, PlatformSpecific(PlatformID.Windows)]
39+
public void CheckWindows()
40+
{
41+
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
42+
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS")));
43+
44+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
45+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
46+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
47+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows")));
48+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT")));
49+
}
50+
4551
[Fact]
4652
public void CheckOSPlatform()
4753
{
@@ -56,12 +62,14 @@ public void CheckOSPlatform()
5662
Assert.True(winObj == winProp);
5763
Assert.True(winObj != randomObj);
5864
Assert.True(defaultObj == conObj);
65+
5966
Assert.False(winObj == defaultObj);
6067
Assert.False(winObj == randomObj);
6168
Assert.False(winObj != winProp);
6269

6370
Assert.True(winObj.Equals(winProp));
6471
Assert.True(conObj.Equals(defaultObj));
72+
6573
Assert.False(defaultObj.Equals(winProp));
6674
Assert.False(winObj.Equals(null));
6775
Assert.False(winObj.Equals("something"));

0 commit comments

Comments
 (0)