From 410d3b74bbc2730204a0d1172de014ce4093e415 Mon Sep 17 00:00:00 2001 From: Thefrank <1910378+Thefrank@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:33:12 -0600 Subject: [PATCH 1/4] FreeBSD Support --- .../Unit/EnvironmentAliasesTests.cs | 34 +++++++++++++++++++ src/Cake.Common/EnviromentAliases.cs | 26 ++++++++++++++ .../Tools/MSBuild/MSBuildResolver.cs | 11 ++++++ .../Extensions/CakePlatformExtensions.cs | 14 ++++++++ src/Cake.Core/PlatformFamily.cs | 7 +++- src/Cake.Core/Polyfill/EnvironmentHelper.cs | 17 +++++++++- 6 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs b/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs index 2a4fdeec22..39e771ffc8 100644 --- a/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs +++ b/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs @@ -182,6 +182,7 @@ public void Should_Throw_If_Context_Is_Null() [Theory] [InlineData(PlatformFamily.Linux, false)] [InlineData(PlatformFamily.OSX, false)] + [InlineData(PlatformFamily.FreeBSD, false)] [InlineData(PlatformFamily.Windows, true)] public void Should_Return_Correct_Value(PlatformFamily family, bool expected) { @@ -212,6 +213,7 @@ public void Should_Throw_If_Context_Is_Null() [Theory] [InlineData(PlatformFamily.Linux, true)] [InlineData(PlatformFamily.OSX, true)] + [InlineData(PlatformFamily.FreeBSD, true)] [InlineData(PlatformFamily.Windows, false)] public void Should_Return_Correct_Value(PlatformFamily family, bool expected) { @@ -242,6 +244,7 @@ public void Should_Throw_If_Context_Is_Null() [Theory] [InlineData(PlatformFamily.Linux, true)] [InlineData(PlatformFamily.OSX, false)] + [InlineData(PlatformFamily.FreeBSD, false)] [InlineData(PlatformFamily.Windows, false)] public void Should_Return_Correct_Value(PlatformFamily family, bool expected) { @@ -272,6 +275,7 @@ public void Should_Throw_If_Context_Is_Null() [Theory] [InlineData(PlatformFamily.Linux, false)] [InlineData(PlatformFamily.OSX, true)] + [InlineData(PlatformFamily.FreeBSD, false)] [InlineData(PlatformFamily.Windows, false)] public void Should_Return_Correct_Value(PlatformFamily family, bool expected) { @@ -282,6 +286,36 @@ public void Should_Return_Correct_Value(PlatformFamily family, bool expected) // When var result = EnvironmentAliases.IsRunningOnMacOs(context); + // Then + Assert.Equal(expected, result); + } + } + public sealed class TheIsRunningOnFreeBSDMethod + { + [Fact] + public void Should_Throw_If_Context_Is_Null() + { + // Given, When + var result = Record.Exception(() => EnvironmentAliases.IsRunningOnFreeBSD(null)); + + // Then + AssertEx.IsArgumentNullException(result, "context"); + } + + [Theory] + [InlineData(PlatformFamily.Linux, false)] + [InlineData(PlatformFamily.OSX, false)] + [InlineData(PlatformFamily.FreeBSD, true)] + [InlineData(PlatformFamily.Windows, false)] + public void Should_Return_Correct_Value(PlatformFamily family, bool expected) + { + // Given + var context = Substitute.For(); + context.Environment.Returns(new FakeEnvironment(family)); + + // When + var result = EnvironmentAliases.IsRunningOnFreeBSD(context); + // Then Assert.Equal(expected, result); } diff --git a/src/Cake.Common/EnviromentAliases.cs b/src/Cake.Common/EnviromentAliases.cs index a6992c07bc..e48db1f095 100644 --- a/src/Cake.Common/EnviromentAliases.cs +++ b/src/Cake.Common/EnviromentAliases.cs @@ -216,6 +216,32 @@ public static bool IsRunningOnMacOs(this ICakeContext context) return context.Environment.Platform.IsOSX(); } + /// + /// Determines whether the build script running on a FreeBSD based system. + /// + /// + /// + /// if (IsRunningOnFreeBSD()) + /// { + /// Information("FreeBSD!"); + /// } + /// + /// + /// The context. + /// + /// true if the build script running on a FreeBSD based system; otherwise false. + /// + [CakeMethodAlias] + [CakeAliasCategory("Platform")] + public static bool IsRunningOnFreeBSD(this ICakeContext context) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return context.Environment.Platform.FreeBSD(); + } + /// /// Determines whether the build script running on a Linux based system. /// diff --git a/src/Cake.Common/Tools/MSBuild/MSBuildResolver.cs b/src/Cake.Common/Tools/MSBuild/MSBuildResolver.cs index 82c279a1ee..13549731d4 100644 --- a/src/Cake.Common/Tools/MSBuild/MSBuildResolver.cs +++ b/src/Cake.Common/Tools/MSBuild/MSBuildResolver.cs @@ -41,6 +41,17 @@ public static FilePath GetMSBuildPath(IFileSystem fileSystem, ICakeEnvironment e throw new CakeException("Could not resolve MSBuild."); } + else if (environment.Platform.Family == PlatformFamily.FreeBSD) + { + var freebsdMSBuildPath = new FilePath("/usr/local/bin/msbuild"); + + if (fileSystem.Exist(freebsdMSBuildPath)) + { + return freebsdMSBuildPath; + } + + throw new CakeException("Could not resolve MSBuild."); + } var binPath = settings.ToolVersion == MSBuildToolVersion.Default ? GetHighestAvailableMSBuildVersion(fileSystem, environment, buildPlatform, settings.AllowPreviewVersion) diff --git a/src/Cake.Core/Extensions/CakePlatformExtensions.cs b/src/Cake.Core/Extensions/CakePlatformExtensions.cs index ca663f44f7..97dd99ba40 100644 --- a/src/Cake.Core/Extensions/CakePlatformExtensions.cs +++ b/src/Cake.Core/Extensions/CakePlatformExtensions.cs @@ -68,5 +68,19 @@ public static bool IsLinux(this ICakePlatform platform) } return EnvironmentHelper.IsLinux(platform.Family); } + + /// + /// Determines whether the specified platform is a FreeBSD platform. + /// + /// The platform. + /// true if the platform is a FreeBSD platform; otherwise false. + public static bool IsFreeBSD(this ICakePlatform platform) + { + if (platform == null) + { + throw new ArgumentNullException(nameof(platform)); + } + return EnvironmentHelper.IsFreeBSD(platform.Family); + } } } \ No newline at end of file diff --git a/src/Cake.Core/PlatformFamily.cs b/src/Cake.Core/PlatformFamily.cs index b94ff29842..3dd927a2e3 100644 --- a/src/Cake.Core/PlatformFamily.cs +++ b/src/Cake.Core/PlatformFamily.cs @@ -28,6 +28,11 @@ public enum PlatformFamily /// Represents the OSX platform family. /// // ReSharper disable once InconsistentNaming - OSX = 3 + OSX = 3, + + /// + /// Represents the FreeBSD platform family. + /// + FreeBSD = 4 } } \ No newline at end of file diff --git a/src/Cake.Core/Polyfill/EnvironmentHelper.cs b/src/Cake.Core/Polyfill/EnvironmentHelper.cs index 465b05ed01..2ad3ee99b1 100644 --- a/src/Cake.Core/Polyfill/EnvironmentHelper.cs +++ b/src/Cake.Core/Polyfill/EnvironmentHelper.cs @@ -54,6 +54,16 @@ public static PlatformFamily GetPlatformFamily() catch (PlatformNotSupportedException) { } + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + { + return PlatformFamily.FreeBSD; + } + } + catch (PlatformNotSupportedException) + { + } return PlatformFamily.Unknown; } @@ -81,7 +91,8 @@ public static bool IsUnix() public static bool IsUnix(PlatformFamily family) { return family == PlatformFamily.Linux - || family == PlatformFamily.OSX; + || family == PlatformFamily.OSX + || family == PlatformFamily.FreeBSD; } public static bool IsOSX(PlatformFamily family) @@ -93,6 +104,10 @@ public static bool IsLinux(PlatformFamily family) { return family == PlatformFamily.Linux; } + public static bool IsFreeBSD(PlatformFamily family) + { + return family == PlatformFamily.FreeBSD; + } public static Runtime GetRuntime() { From afc803f2f5a0ee23c399900d3eefcbf2f1039c2b Mon Sep 17 00:00:00 2001 From: Thefrank <1910378+Thefrank@users.noreply.github.com> Date: Sun, 12 May 2024 21:06:59 -0600 Subject: [PATCH 2/4] don't break compat --- src/Cake.Common/EnviromentAliases.cs | 2 +- src/Cake.Core/Polyfill/EnvironmentHelper.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Cake.Common/EnviromentAliases.cs b/src/Cake.Common/EnviromentAliases.cs index e48db1f095..154737343d 100644 --- a/src/Cake.Common/EnviromentAliases.cs +++ b/src/Cake.Common/EnviromentAliases.cs @@ -239,7 +239,7 @@ public static bool IsRunningOnFreeBSD(this ICakeContext context) { throw new ArgumentNullException(nameof(context)); } - return context.Environment.Platform.FreeBSD(); + return context.Environment.Platform.IsFreeBSD(); } /// diff --git a/src/Cake.Core/Polyfill/EnvironmentHelper.cs b/src/Cake.Core/Polyfill/EnvironmentHelper.cs index 2ad3ee99b1..8407198bda 100644 --- a/src/Cake.Core/Polyfill/EnvironmentHelper.cs +++ b/src/Cake.Core/Polyfill/EnvironmentHelper.cs @@ -56,7 +56,7 @@ public static PlatformFamily GetPlatformFamily() } try { - if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) { return PlatformFamily.FreeBSD; } @@ -104,6 +104,7 @@ public static bool IsLinux(PlatformFamily family) { return family == PlatformFamily.Linux; } + public static bool IsFreeBSD(PlatformFamily family) { return family == PlatformFamily.FreeBSD; From 29a10a59956d973bcd517e5d21cc8fd3539fee2d Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Mon, 29 Jul 2024 15:17:08 -0300 Subject: [PATCH 3/4] formatting --- src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs | 1 + src/Cake.Core/PlatformFamily.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs b/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs index 39e771ffc8..cf149fa2c5 100644 --- a/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs +++ b/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs @@ -290,6 +290,7 @@ public void Should_Return_Correct_Value(PlatformFamily family, bool expected) Assert.Equal(expected, result); } } + public sealed class TheIsRunningOnFreeBSDMethod { [Fact] diff --git a/src/Cake.Core/PlatformFamily.cs b/src/Cake.Core/PlatformFamily.cs index 3dd927a2e3..6d70f7222e 100644 --- a/src/Cake.Core/PlatformFamily.cs +++ b/src/Cake.Core/PlatformFamily.cs @@ -33,6 +33,6 @@ public enum PlatformFamily /// /// Represents the FreeBSD platform family. /// - FreeBSD = 4 + FreeBSD = 4, } } \ No newline at end of file From 4f3384d4dffad1a54a8f41c1cbdc5d249f508f9a Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Mon, 29 Jul 2024 15:17:59 -0300 Subject: [PATCH 4/4] styling --- src/Cake.Common/EnviromentAliases.cs | 2 +- src/Cake.Core/Extensions/CakePlatformExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cake.Common/EnviromentAliases.cs b/src/Cake.Common/EnviromentAliases.cs index 154737343d..2e8444a43c 100644 --- a/src/Cake.Common/EnviromentAliases.cs +++ b/src/Cake.Common/EnviromentAliases.cs @@ -235,7 +235,7 @@ public static bool IsRunningOnMacOs(this ICakeContext context) [CakeAliasCategory("Platform")] public static bool IsRunningOnFreeBSD(this ICakeContext context) { - if (context == null) + if (context is null) { throw new ArgumentNullException(nameof(context)); } diff --git a/src/Cake.Core/Extensions/CakePlatformExtensions.cs b/src/Cake.Core/Extensions/CakePlatformExtensions.cs index 97dd99ba40..fb6700ffd8 100644 --- a/src/Cake.Core/Extensions/CakePlatformExtensions.cs +++ b/src/Cake.Core/Extensions/CakePlatformExtensions.cs @@ -76,7 +76,7 @@ public static bool IsLinux(this ICakePlatform platform) /// true if the platform is a FreeBSD platform; otherwise false. public static bool IsFreeBSD(this ICakePlatform platform) { - if (platform == null) + if (platform is null) { throw new ArgumentNullException(nameof(platform)); }