Skip to content

Commit

Permalink
[msbuild/dotnet] Make codesigning createdump work in universal apps. F…
Browse files Browse the repository at this point in the history
…ixes #14155. (#14196)

We don't sign each rid-specific bundle, but we sign the final merged app bundle instead.
This means that we must store the list of files to codesign from the rid-specific
build and load those lists before running codesign on the merged app bundle.

#14155.
  • Loading branch information
rolfbjarne authored Feb 21, 2022
1 parent f838576 commit 96c32e3
Showing 1 changed file with 85 additions and 11 deletions.
96 changes: 85 additions & 11 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
_CompileNativeExecutable;
_LinkNativeExecutable;
_ComputePublishLocation;
_ComputeCodesignItems;
CopyFilesToPublishDirectory;
_CopyDirectoriesToBundle;
_CopyAppExtensionsToBundle;
Expand Down Expand Up @@ -291,11 +292,15 @@
<_RuntimeIdentifiersAsItems Update="@(_RuntimeIdentifiersAsItems)">
<!-- Platform = "rid-arch".Substring (0, "rid-arch".IndexOf ('-')) -->
<Platform>$([System.String]::new('%(Identity)').Substring(0, $([System.String]::new('%(Identity)').IndexOf ('-'))))</Platform>
<RidSpecificCodesignItemsPath>$(DeviceSpecificIntermediateOutputPath)codesignitems-%(Identity).items</RidSpecificCodesignItemsPath>
</_RuntimeIdentifiersAsItems>

<!-- Verify that we're not mixing simulator + device RIDs in a single build -->
<_RuntimeIdentifierPlatforms Include="@(_RuntimeIdentifiersAsItems -> '%(Platform)')" />
<_RuntimeIdentifierDistinctPlatforms Include="@(_RuntimeIdentifierPlatforms->Distinct())" />

<!-- Create an item group with all the rid-specific CodesignItemsPath -->
<_RidSpecificCodesignItemsPath Include="@(_RuntimeIdentifiersAsItems -> '%(RidSpecificCodesignItemsPath)')" />
</ItemGroup>

<!-- Show an error if we're mixing simulator + device RIDs in a single build -->
Expand All @@ -320,7 +325,11 @@
<MSBuild
Projects="$(MSBuildProjectFile)"
Targets="_BuildRidSpecificAppBundle"
Properties="RuntimeIdentifier=%(_RuntimeIdentifiersAsItems.Identity);$(_RidSpecificProperties)">
Properties="
RuntimeIdentifier=%(_RuntimeIdentifiersAsItems.Identity);
_CodesignItemsPath=%(_RuntimeIdentifiersAsItems.RidSpecificCodesignItemsPath);
$(_RidSpecificProperties);
">
<Output TaskParameter="TargetOutputs" ItemName="_AssemblyPublishDirectories" />
</MSBuild>

Expand Down Expand Up @@ -1237,6 +1246,44 @@
</_ComputeLinkModeDependsOn>
</PropertyGroup>

<PropertyGroup>
<_CodesignAppBundleDependsOn Condition="'$(RuntimeIdentifiers)' != ''">
_CollectRidSpecificCodesignItems;
$(_CodesignAppBundleDependsOn);
</_CodesignAppBundleDependsOn>
</PropertyGroup>

<Target Name="_CollectRidSpecificCodesignItems"
DependsOnTargets="_RunRidSpecificBuild;_DetectSigningIdentity;_PrepareResourceRules;_ComputeVariables"
>

<!-- Read the stored list of files to sign if we're an outer build of a multi-rid build -->
<ReadItemsFromFile
SessionId="$(BuildSessionId)"
File="%(_RidSpecificCodesignItemsPath.Identity)"
Condition="@(_RidSpecificCodesignItemsPath->Count()) &gt; 0"
>
<Output TaskParameter="Items" ItemName="_RidSpecificCodesignItems" />
</ReadItemsFromFile>

<ItemGroup>
<!-- The rid-specific build might not have set these values -->
<_RidSpecificCodesignItems>
<CodesignAllocate Condition="'%(_RidSpecificCodesignItem.CodesignAllocate)' == ''">$(_CodesignAllocate)</CodesignAllocate>
<CodesignDisableTimestamp Condition="'%(_RidSpecificCodesignItem.CodesignDisableTimestamp)' == '' And '$(_BundlerDebug)' == 'true'">true</CodesignDisableTimestamp>
<CodesignExtraArgs Condition="'%(_RidSpecificCodesignItem.CodesignExtraArgs)' == ''">$(CodesignExtraArgs)</CodesignExtraArgs>
<CodesignKeychain Condition="'%(_RidSpecificCodesignItem.CodesignKeychain)' == ''">$(CodesignKeychain)</CodesignKeychain>
<CodesignResourceRules Condition="'%(_RidSpecificCodesignItem.CodesignResourceRules)' == ''">$(_PreparedResourceRules)</CodesignResourceRules>
<CodesignSigningKey Condition="'%(_RidSpecificCodesignItem.CodesignSigningKey)' == ''">$(_CodeSigningKey)</CodesignSigningKey>
<CodesignUseHardenedRuntime Condition="'%(_RidSpecificCodesignItem.CodesignUseHardenedRuntime)' == ''">$(UseHardenedRuntime)</CodesignUseHardenedRuntime>
<CodesignUseSecureTimestamp Condition="'%(_RidSpecificCodesignItem.CodesignUseSecureTimestamp)' == ''">$(UseHardenedRuntime)</CodesignUseSecureTimestamp>
</_RidSpecificCodesignItems>

<!-- These items are relative to the root of the app bundle, we need to make them relative to the PublishDir property -->
<_CodesignItems Include="@(_RidSpecificCodesignItems -> '$(_RelativePublishDir)%(Identity)')" />
</ItemGroup>
</Target>

<Target Name="_ComputePublishLocation"
DependsOnTargets="_GenerateBundleName;_ParseBundlerArguments;_ComputeMonoLibraries;_DetectSigningIdentity;_PrepareResourceRules"
Condition="'$(_CanOutputAppBundle)' == 'true'"
Expand Down Expand Up @@ -1340,16 +1387,6 @@
/>
<ResolvedFileToPublish Remove="@(_CreateDumpExecutable)" />
<ResolvedFileToPublish Include="@(_CreateDumpExecutable)" />
<!-- The 'createdump' executable must be signed. -->
<!-- Ref: https://github.com/xamarin/xamarin-macios/issues/13417 -->
<_CodesignItems Include="@(_CreateDumpExecutable)" Condition="'$(_RequireCodeSigning)' == 'true'">
<CodesignAllocate>$(_CodesignAllocate)</CodesignAllocate>
<CodesignDisableTimestamp Condition="'$(_BundlerDebug)' == 'true'">true</CodesignDisableTimestamp>
<CodesignExtraArgs>$(CodesignExtraArgs)</CodesignExtraArgs>
<CodesignKeychain>$(CodesignKeychain)</CodesignKeychain>
<CodesignResourceRules>$(_PreparedResourceRules)</CodesignResourceRules>
<CodesignSigningKey>$(_CodeSigningKey)</CodesignSigningKey>
</_CodesignItems>

<!-- Remove any dylibs Mono told us not to link with -->
<ResolvedFileToPublish
Expand Down Expand Up @@ -1452,6 +1489,43 @@
</ResolveNativeReferences>
</Target>

<Target Name="_ComputeCodesignItems"
Outputs="$(_CodesignItemsPath)"
>
<ItemGroup Condition="'$(_RequireCodeSigning)' == 'true'">
<!-- The 'createdump' executable must be signed. -->
<!-- Ref: https://github.com/xamarin/xamarin-macios/issues/13417 -->
<_CreateDumpExecutableToSign Include="@(_CreateDumpExecutable -> '$(_DylibPublishDir)%(RelativePath)')" KeepMetadata="false">
<CodesignAllocate>$(_CodesignAllocate)</CodesignAllocate>
<CodesignDisableTimestamp Condition="'$(_BundlerDebug)' == 'true'">true</CodesignDisableTimestamp>
<CodesignEntitlements>$(IntermediateOutputPath)Entitlements.xcent</CodesignEntitlements>
<CodesignExtraArgs>$(CodesignExtraArgs)</CodesignExtraArgs>
<CodesignKeychain>$(CodesignKeychain)</CodesignKeychain>
<CodesignResourceRules>$(_PreparedResourceRules)</CodesignResourceRules>
<CodesignSigningKey>$(_CodeSigningKey)</CodesignSigningKey>
<CodesignUseHardenedRuntime>$(UseHardenedRuntime)</CodesignUseHardenedRuntime>
<CodesignUseSecureTimestamp>$(UseHardenedRuntime)</CodesignUseSecureTimestamp>
</_CreateDumpExecutableToSign>

<_CodesignItems Include="@(_CreateDumpExecutableToSign -> '$(_RelativePublishDir)%(Identity)')" />
</ItemGroup>

<!-- Write a list of files to sign if we're not an outer build of a multi-rid build -->
<WriteItemsToFile
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And '$(_CodesignItemsPath)' != ''"
Items="@(_CreateDumpExecutableToSign)"
ItemName="_CodesignItems"
File="$(_CodesignItemsPath)"
Overwrite="true"
IncludeMetadata="true"
/>
<ItemGroup>
<FileWrites Include="$(_CodesignItemsPath)" />
</ItemGroup>

</Target>

<Target Name="_DecompressAppleBindingResourcePackages"
Inputs="@(_CompressedAppleBindingResourcePackage)"
DependsOnTargets="_ComputePublishLocation;_ComputeVariables"
Expand Down

4 comments on commit 96c32e3

@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
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API Current PR diff

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff
  • ⚠️ Generator diff comments have not been provided.

Packages generated

View packages

Test results

3 tests failed, 232 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2708 Passed: 2513 Inconclusive: 11 Failed: 3 Ignored: 192)
  • link all/Mac Catalyst [dotnet]/Debug [dotnet]: TimedOut (Execution timed out after 1200 seconds.
    No test log file was produced)
  • [NUnit] Mono Mac OS X BCL tests group 2/Mac Full/Debug: Failed (Test run failed.
    Tests run: 11943 Passed: 10499 Inconclusive: 0 Failed: 3 Ignored: 354)

Pipeline on Agent XAMBOT-1028.BigSur'
[msbuild/dotnet] Make codesigning createdump work in universal apps. Fixes #14155. (#14196)

@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 failed catastrophically on VSTS: device tests iOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-iOS64\TestSummary.md not found.

Pipeline on Agent
[msbuild/dotnet] Make codesigning createdump work in universal apps. Fixes #14155. (#14196)

@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 failed catastrophically on VSTS: device tests tvOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-tvos\TestSummary.md not found.

Pipeline on Agent
[msbuild/dotnet] Make codesigning createdump work in universal apps. Fixes #14155. (#14196)

@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 failed on macOS Mac Catalina (10.15) ❌

Tests failed on Mac Catalina (10.15).

Failed tests are:

  • monotouch-test

Pipeline on Agent
[msbuild/dotnet] Make codesigning createdump work in universal apps. Fixes #14155. (#14196)

Please sign in to comment.