Skip to content

Commit

Permalink
[msbuild] Simplified entitlements for the simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Jun 7, 2024
1 parent e8ded9a commit bb08532
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1572,4 +1572,12 @@
<value>The app bundle '{0}' contains a subdirectory named 'Resources'. This is not allowed on this platform. Typically resource files should be in the root directory of the app bundle (or a custom subdirectory, but named anything other than 'Resources').</value>
<comment>0: a path</comment>
</data>

<data name="W7124" xml:space="preserve">
<value>A provisioning profile has been specified, but this value is ignored for the simulator.</value>
</data>

<data name="W7125" xml:space="preserve">
<value>A file with codesigning entitlements has been specified, but this value is ignored for the simulator.</value>
</data>
</root>
31 changes: 31 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ public override bool Execute ()
return false;
}

if (SdkIsSimulator)
return ExecuteSimulator ();

if (!string.IsNullOrEmpty (ProvisioningProfile)) {
if ((profile = GetMobileProvision (platform, ProvisioningProfile)) is null) {
Log.LogError (MSBStrings.E0049, ProvisioningProfile);
Expand Down Expand Up @@ -534,6 +537,34 @@ public override bool Execute ()
return !Log.HasLoggedErrors;
}

bool ExecuteSimulator ()
{
if (!string.IsNullOrEmpty (ProvisioningProfile))
Log.LogWarning (null, null, null, ProvisioningProfile, 0, 0, 0, 0, MSBStrings.W7124 /* A provisioning profile has been specified, but this value is ignored for the simulator. */);

if (!string.IsNullOrEmpty (Entitlements))
Log.LogWarning (null, null, null, Entitlements, 0, 0, 0, 0, MSBStrings.W7125 /* A file with codesigning entitlements has been specified, but this value is ignored for the simulator. */);

// No matter what, I've only been able to make Xcode apply a single entitlement to simulator builds: com.apple.security.get-task-allow
var compiled = new PDictionary ();
compiled.Add ("com.apple.security.get-task-allow", new PBoolean (true));

// Still apply custom entitlements, just to offer a way out if we're wrong about com.apple.security.get-task-allow being the only entitlement.
AddCustomEntitlements (compiled, null);

try {
Directory.CreateDirectory (Path.GetDirectoryName (CompiledEntitlements!.ItemSpec));
WriteXcent (compiled, CompiledEntitlements.ItemSpec);
} catch (Exception ex) {
Log.LogError (MSBStrings.E0114, CompiledEntitlements, ex.Message);
return false;
}

EntitlementsInExecutable = CompiledEntitlements;

return !Log.HasLoggedErrors;
}

bool SaveArchivedExpandedEntitlements (PDictionary archived)
{
if (Platform == Utils.ApplePlatform.MacCatalyst) {
Expand Down

1 comment on commit bb08532

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.