Skip to content

Commit

Permalink
[MacCatalyst] Added Default Entitlements for MacCatalyst projects (xa…
Browse files Browse the repository at this point in the history
…marin#18669)

Added default entitlements for MacCatalyst templates.
For Debug, the com.apple.security.get-task-allow entitlement that allows for using developer tools when developing MAUI Blazor apps.
For release, com.apple.security.app-sandbox is required to publish MacCatalyst apps to the Mac App Store.

Also added unit test to check for entitlements when project is created.

Fixes xamarin#18344

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 19b4beb commit 1b016fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
<None Include="@(ObjcBindingCoreSource)" />
</ItemGroup>

<PropertyGroup Condition="'$(_PlatformName)' == 'MacCatalyst'">
<EnableDefaultMacCatalystReleaseEntitlements Condition="'$(EnableDefaultMacCatalystReleaseEntitlements)' == ''">True</EnableDefaultMacCatalystReleaseEntitlements>
<EnableDefaultMacCatalystDebugEntitlements Condition="'$(EnableDefaultMacCatalystDebugEntitlements)' == ''">True</EnableDefaultMacCatalystDebugEntitlements>
</PropertyGroup>

<ItemGroup Condition="'$(EnableDefaultMacCatalystDebugEntitlements)' == 'True' and '$(Configuration)' == 'Debug'">
<CustomEntitlements Include="com.apple.security.get-task-allow" Type="boolean" Value="true" />
</ItemGroup>

<ItemGroup Condition="'$(EnableDefaultMacCatalystReleaseEntitlements)' == 'True' and '$(Configuration)' == 'Release'">
<CustomEntitlements Include="com.apple.security.app-sandbox" Type="boolean" Value="true" />
</ItemGroup>

<!-- Architecture -->
<!-- If the old-style variables are set, use those -->
<PropertyGroup Condition=" '$(TargetArchitectures)' == '' ">
Expand Down
26 changes: 26 additions & 0 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,32 @@ public void AutoAllowJitEntitlements (ApplePlatform platform, string runtimeIden
}
}

[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", "Release")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", "Debug")]
public void CheckForMacCatalystDefaultEntitlements (ApplePlatform platform, string runtimeIdentifiers, string configuration)
{
var project = "Entitlements";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);

var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration);
Clean (project_path);

var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["Configuration"] = configuration;
DotNet.AssertBuild (project_path, properties);

var executable = GetNativeExecutable (platform, appPath);
var foundEntitlements = TryGetEntitlements (executable, out var entitlements);
Assert.IsTrue (foundEntitlements, "Issues found with Entitlements.");
if (configuration == "Release") {
Assert.IsTrue (entitlements!.Get<PBoolean> ("com.apple.security.app-sandbox")?.Value, "com.apple.security.app-sandbox enlistment was not found in Release configuration.");
Assert.IsNull (entitlements.Get<PBoolean> ("com.apple.security.get-task-allow")?.Value, "com.apple.security.get-task-allow enlistment was found in Release configuration.");
} else if (configuration == "Debug") {
Assert.IsTrue (entitlements!.Get<PBoolean> ("com.apple.security.get-task-allow")?.Value, "com.apple.security.get-task-allow enlistment was not found in Debug configuration.");
}
}

// [TestCase (ApplePlatform.MacCatalyst, null, "Release")]
[TestCase (ApplePlatform.MacOSX, null, "Release")]
public void NoWarnCodesign (ApplePlatform platform, string runtimeIdentifiers, string configuration)
Expand Down

0 comments on commit 1b016fa

Please sign in to comment.