Skip to content

Commit

Permalink
[dotnet] Enable default compile items for binding projects. Fixes #12532
Browse files Browse the repository at this point in the history
. (#12758)

Enable default compile items for binding projects, and just exclude any api definition
and core source from any automatically included files.

Fixes #12532.
  • Loading branch information
rolfbjarne committed Sep 20, 2021
1 parent 6df1ba2 commit 499a69e
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 4 deletions.
10 changes: 7 additions & 3 deletions dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
<EnableDefaultmacOSItems Condition=" '$(_PlatformName)' == 'macOS' And '$(EnableDefaultmacOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaultmacOSItems>
<EnableDefaultMacCatalystItems Condition=" '$(_PlatformName)' == 'MacCatalyst' And '$(EnableDefaultMacCatalystItems)' == '' ">$(EnableDefaultItems)</EnableDefaultMacCatalystItems>

<!-- Don't include default Compile items for binding projects, because that would pick up ApiDefinition.cs and StructsAndEnums.cs -->
<EnableDefaultCompileItems Condition=" '$(IsBindingProject)' == 'true' ">false</EnableDefaultCompileItems>

<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' And '$(_PlatformName)' != 'macOS'">true</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' And '$(_PlatformName)' == 'macOS'">false</UseMonoRuntime>
</PropertyGroup>

<ItemGroup>
<!-- Exclude api definitions from files included by default -->
<Compile Remove="@(ObjcBindingApiDefinition)" />
<!-- Exclude core sources as well, we re-add them later (this way we make sure they only show up once in the Compile item group) -->
<Compile Remove="@(ObjcBindingCoreSource)" />
</ItemGroup>

<!-- Architecture -->
<!-- If the old-style variables are set, use those -->
<PropertyGroup Condition=" '$(TargetArchitectures)' == '' ">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Foundation;

namespace MyApiDefinition {
[BaseType (typeof (NSObject))]
interface MyNativeClass {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
8 changes: 8 additions & 0 deletions tests/dotnet/BindingWithDefaultCompileInclude/MyClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace MyClassLibrary {
public class MyClass {
public MyClass ()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MyClassLibrary {
public struct MyStruct {
public int A;
public int B;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

1 change: 1 addition & 0 deletions tests/dotnet/BindingWithDefaultCompileInclude/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-macos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
13 changes: 13 additions & 0 deletions tests/dotnet/BindingWithDefaultCompileInclude/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<IsBindingProject>true</IsBindingProject>
</PropertyGroup>

<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
</ItemGroup>

<Import Project="../../common/shared-dotnet.csproj" />
</Project>
27 changes: 27 additions & 0 deletions tests/dotnet/BindingWithDefaultCompileInclude/shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
TOP=../../../..
include $(TOP)/Make.config

prepare:
$(Q) $(MAKE) -C $(TOP)/tests/dotnet copy-dotnet-config

reload:
$(Q) $(MAKE) -C $(TOP) -j8 all
$(Q) $(MAKE) -C $(TOP) -j8 install
$(Q) git clean -xfdq

reload-and-build:
$(Q) $(MAKE) reload
$(Q) $(MAKE) build

reload-and-run:
$(Q) $(MAKE) reload
$(Q) $(MAKE) run

build: prepare
$(Q) $(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS)

run: prepare
$(Q) $(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) $(BUILD_ARGUMENTS) -t:Run

diag: prepare
$(Q) $(DOTNET6) build /v:diag msbuild.binlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
28 changes: 28 additions & 0 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,34 @@ public void SimpleAppWithOldReferences (ApplePlatform platform, string runtimeId
}

[Test]
[TestCase (ApplePlatform.iOS)]
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacCatalyst)]
[TestCase (ApplePlatform.MacOSX)]
public void BindingWithDefaultCompileInclude (ApplePlatform platform)
{
var project = "BindingWithDefaultCompileInclude";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);

var rv = DotNet.AssertBuild (project_path, GetDefaultProperties ());

var dllPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", platform.ToFramework (), $"{project}.dll");
Assert.That (dllPath, Does.Exist, "Binding assembly");

// Verify that the MyNativeClass class exists in the assembly, and that it's actually a class.
var ad = AssemblyDefinition.ReadAssembly (dllPath, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var myNativeClass = ad.MainModule.Types.FirstOrDefault (v => v.FullName == "MyApiDefinition.MyNativeClass");
Assert.IsFalse (myNativeClass.IsInterface, "IsInterface");
var myStruct = ad.MainModule.Types.FirstOrDefault (v => v.FullName == "MyClassLibrary.MyStruct");
Assert.IsTrue (myStruct.IsValueType, "MyStruct");

var warnings = BinLog.GetBuildLogWarnings (rv.BinLogPath).Select (v => v.Message);
Assert.That (warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
}

[TestCase (ApplePlatform.iOS, "iossimulator-x64")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class TestBaseClass {
{ "_BundlerVerbosity", "1" },
};

protected Dictionary<string, string> GetDefaultProperties (string? runtimeIdentifiers)
protected Dictionary<string, string> GetDefaultProperties (string? runtimeIdentifiers = null)
{
var rv = new Dictionary<string, string> (verbosity);
if (!string.IsNullOrEmpty (runtimeIdentifiers))
Expand Down

3 comments on commit 499a69e

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (only version changes)

Packages generated

View packages

Test results

1 tests failed, 242 tests passed.

Failed tests

  • link sdk/Mac Catalyst [dotnet]/Debug [dotnet]: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)

Pipeline on Agent XAMBOT-1037.BigSur'
[dotnet] Enable default compile items for binding projects. Fixes #12532. (#12758)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[dotnet] Enable default compile items for binding projects. Fixes #12532. (#12758)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[dotnet] Enable default compile items for binding projects. Fixes #12532. (#12758)

Please sign in to comment.