diff --git a/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs b/src/Cake.Common.Tests/Unit/EnvironmentAliasesTests.cs index 2a4fdeec22..cf149fa2c5 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) { @@ -286,5 +290,36 @@ public void Should_Return_Correct_Value(PlatformFamily family, bool expected) 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..2e8444a43c 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 is null) + { + throw new ArgumentNullException(nameof(context)); + } + return context.Environment.Platform.IsFreeBSD(); + } + /// /// 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..fb6700ffd8 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 is 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..6d70f7222e 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..8407198bda 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.Create("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) @@ -94,6 +105,11 @@ public static bool IsLinux(PlatformFamily family) return family == PlatformFamily.Linux; } + public static bool IsFreeBSD(PlatformFamily family) + { + return family == PlatformFamily.FreeBSD; + } + public static Runtime GetRuntime() { if (IsCoreClr())