Skip to content

Commit 3c1406e

Browse files
committed
build: annotate platform-specific code
Annotate any OS or platform specific code with the new (Un)SupportedOSPlatform(Guard) attributes and update various platform util methods to use the OperatingSystem.Is<platform> methods. This will help ensure we're not missing any OS checks in the future. For test projects we ignore these warnings since we're using skipping Xunit tests that are not applicable for the current platform already, making these warnings just noise.
1 parent 26735d1 commit 3c1406e

17 files changed

+57
-3
lines changed

Directory.Build.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@
3333
</ItemGroup>
3434
</Target>
3535

36+
<PropertyGroup>
37+
<!-- Ignore platform API compatibilty checks in test projects -->
38+
<NoWarn Condition="'$(IsTestProject)'=='true'">$(NoWarn);CA1416</NoWarn>
39+
</PropertyGroup>
40+
3641
</Project>

src/shared/Core/Constants.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public static class Constants
1616

1717
public const string GcmDataDirectoryName = ".gcm";
1818

19+
public const string WindowsPlatformName = "windows";
20+
public const string LinuxPlatformName = "linux";
21+
public const string MacOSPlatformName = "osx";
22+
1923
public static readonly Guid DevBoxPartnerId = new("e3171dd9-9a5f-e5be-b36c-cc7c4f3f3bcf");
2024

2125
/// <summary>

src/shared/Core/Interop/Linux/LinuxFileSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.Versioning;
34
using GitCredentialManager.Interop.Posix;
45

56
namespace GitCredentialManager.Interop.Linux
67
{
8+
[SupportedOSPlatform(Constants.LinuxPlatformName)]
79
public class LinuxFileSystem : PosixFileSystem
810
{
911
public override bool IsSamePath(string a, string b)

src/shared/Core/Interop/Linux/LinuxSessionManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System.Runtime.Versioning;
12
using GitCredentialManager.Interop.Posix;
23

34
namespace GitCredentialManager.Interop.Linux;
45

6+
[SupportedOSPlatform(Constants.LinuxPlatformName)]
57
public class LinuxSessionManager : PosixSessionManager
68
{
79
private bool? _isWebBrowserAvailable;

src/shared/Core/Interop/Linux/LinuxTerminal.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Versioning;
23
using GitCredentialManager.Interop.Linux.Native;
34
using GitCredentialManager.Interop.Posix;
45
using GitCredentialManager.Interop.Posix.Native;
56

67
namespace GitCredentialManager.Interop.Linux
78
{
9+
[SupportedOSPlatform(Constants.LinuxPlatformName)]
810
public class LinuxTerminal : PosixTerminal
911
{
1012
public LinuxTerminal(ITrace trace, ITrace2 trace2)

src/shared/Core/Interop/MacOS/MacOSEnvironment.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Runtime.Versioning;
56
using System.Threading;
67
using GitCredentialManager.Interop.Posix;
78

89
namespace GitCredentialManager.Interop.MacOS
910
{
11+
[SupportedOSPlatform(Constants.MacOSPlatformName)]
1012
public class MacOSEnvironment : PosixEnvironment
1113
{
1214
private ICollection<string> _pathsToIgnore;

src/shared/Core/Interop/MacOS/MacOSFileSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.Versioning;
34
using GitCredentialManager.Interop.Posix;
45

56
namespace GitCredentialManager.Interop.MacOS
67
{
8+
[SupportedOSPlatform(Constants.MacOSPlatformName)]
79
public class MacOSFileSystem : PosixFileSystem
810
{
911
public override bool IsSamePath(string a, string b)

src/shared/Core/Interop/MacOS/MacOSSessionManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using System.Runtime.Versioning;
12
using GitCredentialManager.Interop.MacOS.Native;
23
using GitCredentialManager.Interop.Posix;
34

45
namespace GitCredentialManager.Interop.MacOS
56
{
7+
[SupportedOSPlatform(Constants.MacOSPlatformName)]
68
public class MacOSSessionManager : PosixSessionManager
79
{
810
public MacOSSessionManager(IEnvironment env, IFileSystem fs) : base(env, fs)

src/shared/Core/Interop/MacOS/MacOSTerminal.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Versioning;
23
using GitCredentialManager.Interop.MacOS.Native;
34
using GitCredentialManager.Interop.Posix;
45
using GitCredentialManager.Interop.Posix.Native;
56

67
namespace GitCredentialManager.Interop.MacOS
78
{
9+
[SupportedOSPlatform(Constants.MacOSPlatformName)]
810
public class MacOSTerminal : PosixTerminal
911
{
1012
public MacOSTerminal(ITrace trace, ITrace2 trace2)

src/shared/Core/Interop/Posix/PosixEnvironment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.Versioning;
45

56
namespace GitCredentialManager.Interop.Posix
67
{
8+
[SupportedOSPlatform(Constants.LinuxPlatformName)]
9+
[SupportedOSPlatform(Constants.MacOSPlatformName)]
710
public class PosixEnvironment : EnvironmentBase
811
{
912
public PosixEnvironment(IFileSystem fileSystem)

0 commit comments

Comments
 (0)