diff --git a/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs b/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs index a675b1e7ce7..86bdc501dce 100644 --- a/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs +++ b/src/XMakeBuildEngine/Evaluation/IntrinsicFunctions.cs @@ -364,6 +364,17 @@ internal static bool DoesTaskHostExist(string runtime, string architecture) return false; } + internal static bool IsOSPlatform(string os) + { + switch (os.ToLower()) + { + case "windows": return NativeMethodsShared.IsWindows; + case "osx": return NativeMethodsShared.IsOSX; + case "unix": return NativeMethodsShared.IsUnix; + default: return false; + } + } + #region Debug only intrinsics /// diff --git a/src/XMakeBuildEngine/UnitTests/Evaluation/Expander_Tests.cs b/src/XMakeBuildEngine/UnitTests/Evaluation/Expander_Tests.cs index 4892248ccf9..04b51ff83cb 100644 --- a/src/XMakeBuildEngine/UnitTests/Evaluation/Expander_Tests.cs +++ b/src/XMakeBuildEngine/UnitTests/Evaluation/Expander_Tests.cs @@ -2826,6 +2826,36 @@ public void PropertyFunctionStaticMethodIntrinsicMaths() Assert.Equal((~-43).ToString(), result); } + private void CheckOSPlatform(Func isOSPlatform, bool isWindows, bool isOSX, bool isUnix) + { + Assert.Equal(isWindows, isOSPlatform("Windows")); + Assert.Equal(isOSX, isOSPlatform("OSX")); + Assert.Equal(isUnix, isOSPlatform("Unix")); + } + + [Fact] + public void PropertyFunctionStaticMethodIntrinsicIsOSPlatform() + { + PropertyDictionary pg = new PropertyDictionary(); + Expander expander = new Expander(pg); + + Func isOSPlatform = os => bool.Parse(expander.ExpandIntoStringLeaveEscaped(@"$([MSBuild]::IsOSPlatform(" + os + "))", + ExpanderOptions.ExpandProperties, MockElementLocation.Instance)); + + if (NativeMethodsShared.IsWindows) + { + CheckOSPlatform(isOSPlatform, isWindows:true, isOSX:false, isUnix:false); + } + else if (NativeMethodsShared.IsOSX) + { + CheckOSPlatform(isOSPlatform, isWindows:false, isOSX:true, isUnix:true); + } + else + { + CheckOSPlatform(isOSPlatform, isWindows:false, isOSX:false, isUnix:true); + } + } + /// /// Expand a property reference that has whitespace around the property name (should result in empty) ///