Skip to content

Commit bc8d560

Browse files
committed
Fix Mac build to use UnixName Custom Build Task
_system_name and _system_type are not available by default in the environment. Use new UnixName Custom Build Task to conditionally build Mac unit tests instead of depending on _system_name. Define new build/platform.targets that can be used to create system-specific definitions for conditional compilation.
1 parent fe95500 commit bc8d560

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

Palaso.Tests/Palaso.Tests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@
198198
<ErrorReport>prompt</ErrorReport>
199199
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
200200
</PropertyGroup>
201-
<PropertyGroup Condition= " '$(_system_name)' != '' ">
202-
<DefineConstants>$(DefineConstants);SYSTEM_$(_system_name)</DefineConstants>
203-
</PropertyGroup>
204201
<ItemGroup>
205202
<Reference Include="System" />
206203
<Reference Include="System.Core" />
@@ -346,6 +343,7 @@
346343
</BootstrapperPackage>
347344
</ItemGroup>
348345
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
346+
<Import Project="..\build\platform.targets" />
349347
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
350348
Other similar extension points exist, see Microsoft.Common.targets.
351349
<Target Name="BeforeBuild">

Palaso.Tests/PlatformUtilities/PlatformTests.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@
44
using NUnit.Framework;
55
using Palaso.PlatformUtilities;
66

7-
// For code shipped with products, please try to use runtime checks to select code to run.
8-
// There are cases that require compile-time conditionals (e.g. when testing the runtime or
9-
// referencing platform specific imported assemblies like MonoMac.dll). In this case, do
10-
// The following:
11-
// 1) include the following PropertyGroup in the .csproj after all of the DefineConstants
12-
// elements. [Note: _system_name and _system_type are defined by xbuild in later
13-
// versions of Mono. We tested with Mono 3.12 that comes with Xamarin Studio for
14-
// Mac. To verify, add /verbosity:diag to xbuild command-line. YMMV.]
15-
//
16-
// <PropertyGroup Condition= " '$(_system_name)' != '' ">
17-
// <DefineConstants>$(DefineConstants);SYSTEM_$(_system_name)</DefineConstants>
18-
// </PropertyGroup>
19-
//
20-
// 2) In code use a conditional based on the desired platform.
21-
//
22-
// #if SYSTEM_OSX
23-
// using MonoMac.Foundation;
24-
// #endif
25-
267
namespace Palaso.Tests.PlatformUtilities
278
{
289
[TestFixture]
@@ -56,7 +37,7 @@ public void IsDotnet_Net()
5637
Assert.That(Platform.IsDotNet, Is.True);
5738
}
5839

59-
#if SYSTEM_OSX
40+
#if SYSTEM_MAC
6041
[Test]
6142
public void IsLinux_Mac()
6243
{
@@ -78,7 +59,7 @@ public void IsLinux_Windows()
7859
Assert.That(Platform.IsLinux, Is.False);
7960
}
8061

81-
#if SYSTEM_OSX
62+
#if SYSTEM_MAC
8263
[Test]
8364
public void IsWindows_Mac()
8465
{
@@ -100,7 +81,7 @@ public void IsWindows_Windows()
10081
Assert.That(Platform.IsWindows, Is.True);
10182
}
10283

103-
#if SYSTEM_OSX
84+
#if SYSTEM_MAC
10485
[Test]
10586
public void IsMac_Mac()
10687
{
@@ -122,7 +103,7 @@ public void IsMac_Windows()
122103
Assert.That(Platform.IsMac, Is.False);
123104
}
124105

125-
#if SYSTEM_OSX
106+
#if SYSTEM_MAC
126107
[Test]
127108
public void IsUnix_Mac()
128109
{

build/Palaso.BuildTasks.dll

4 KB
Binary file not shown.

build/platform.targets

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
Include this file at the end of a csproj file (just before the
4+
include of Microsoft.CSharp.targets) to add system-specific defines
5+
for conditional compilation.
6+
Example: libpalaso/Palaso.Tests/Palaso.Tests.csproj
7+
8+
These constants will be defined:
9+
SYSTEM_UNIX - should be compiled on Linux and Mac
10+
SYSTEM_MAC - should only be compiled on Mac (e.g. Unit Tests specific to Mac)
11+
SYSTEM_LINUX - should only be compiled on Linux
12+
13+
In csproj file:
14+
<Include Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
15+
<Include Project="..\build\platform.targets" />
16+
17+
To use in C# code:
18+
#if SYSTEM_MAC
19+
/* code that should only be compiled on Mac */
20+
#endif
21+
-->
22+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
23+
<UsingTask TaskName="UnixName" AssemblyFile="Palaso.BuildTasks.dll" />
24+
<Target Name="BeforeBuild">
25+
<UnixName>
26+
<Output TaskParameter="Value" PropertyName="UNIX_NAME" />
27+
</UnixName>
28+
<PropertyGroup>
29+
<DefineConstants Condition="'$(OS)' == 'Unix'">$(DefineConstants);SYSTEM_UNIX</DefineConstants>
30+
<DefineConstants Condition="'$(UNIX_NAME)' == 'Darwin'">$(DefineConstants);SYSTEM_MAC</DefineConstants>
31+
<DefineConstants Condition="'$(UNIX_NAME)' == 'Linux'">$(DefineConstants);SYSTEM_LINUX</DefineConstants>
32+
</PropertyGroup>
33+
</Target>
34+
</Project>
35+

0 commit comments

Comments
 (0)