Skip to content

Commit

Permalink
[msbuild] Fix detecting already signed executables.
Browse files Browse the repository at this point in the history
The MSBuild tasks will codesign an executable if the executable's timestamp is
later than `_CodeSignature/CodeResources`'s timestamp (or if
`_CodeSignature/CodeResources` doesn't exist).

Unfortunately, the codesign executable modifies both of those files, and the
executable last. This means that even just after running codesign, the
executable's timestamp might be later than `_CodeSignature/CodeResources`'s
timestamp (due to HFS+'s one-second timestamp resolution, this might happen
all within the same second, which means that this is a random issue: the
problem only occurs if the executable was modified at least a second later
than `_CodeSignature/CodeResources`.)

So make sure to touch `_CodeSignature/CodeResources` after running codesign,
so that the next time a build occurs (with no modifications), we don't resign
needlessly.

Fixes this (random) test failure when running the MSBuild tests:

    1) Test Failure : Xamarin.iOS.Tasks.TargetTests.RebuildExecutable_NoModifications
         #1: ../MySingleView/bin/iPhoneSimulator/Debug/MySingleView.app/MySingleView
      Expected: 2017-11-30 10:04:20.000
      But was:  2017-11-30 10:04:22.000

Fixes xamarin/maccore#592.
  • Loading branch information
rolfbjarne committed Mar 14, 2018
1 parent 7b405cb commit ba45647
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,11 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
Condition="'$(IsMacEnabled)' == 'true' And ('$(_CanOutputAppBundle)' == 'true' And '%(_AppExtensionCodesignProperties.SigningKey)' != '') And Exists ('$(AppBundleDir)\..\%(_AppExtensionCodesignProperties.Identity).dSYM\Contents\Info.plist')"
Files="$(AppBundleDir)\..\%(_AppExtensionCodesignProperties.Identity).dSYM\Contents\Info.plist"
/>
<Touch
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And Exists ('$(_AppBundlePath)PlugIns\%(_AppExtensionCodesignProperties.Identity)\_CodeSignature\CodeResources')"
Files="$(_AppBundlePath)PlugIns\%(_AppExtensionCodesignProperties.Identity)\_CodeSignature\CodeResources"
/>
</Target>

<Target Name="_PrepareCodesignAppExtension" Condition="'$(_CanOutputAppBundle)' == 'true' And '$(IsAppExtension)' == 'true' And '@(_ResolvedAppBundleExtensions)' == ''">
Expand Down Expand Up @@ -1957,6 +1962,11 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
Condition="'$(IsMacEnabled)' == 'true' And Exists ('$(AppBundleDir).dSYM\Contents\Info.plist')"
Files="$(AppBundleDir).dSYM\Contents\Info.plist"
/>
<Touch
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And Exists ('$(_AppBundlePath)_CodeSignature\CodeResources')"
Files="$(_AppBundlePath)_CodeSignature\CodeResources"
/>
</Target>

<Target Name="_CodesignVerify" Condition="'$(_RequireCodeSigning)' == 'true' And ('$(IsAppExtension)' == 'false' Or '@(_ResolvedAppExtensionReferences)' != '')" DependsOnTargets="_CodesignAppBundle">
Expand Down

0 comments on commit ba45647

Please sign in to comment.