Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Fix detecting already signed executables. #3743

Merged
merged 1 commit into from
Mar 19, 2018

Conversation

rolfbjarne
Copy link
Member

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 https://github.com/xamarin/maccore/issues/592.

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.
Copy link
Contributor

@spouliot spouliot left a comment

Choose a reason for hiding this comment

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

make sense but are not all our bots using APFS ?

@monojenkins
Copy link
Collaborator

Build success

Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

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

woow, what a subtle bug...

@rolfbjarne
Copy link
Member Author

@spouliot not all our bots, but the High Sierra bots should. This is a good question, because this should be 100% reproducible on APFS... yet it isn't.

Test failure from a High Sierra bot (log, wrench revision) :

Errors and Failures:
1) Test Failure : Xamarin.iOS.Tasks.TargetTests.RebuildExecutable_NoModifications
     #1: ../MySingleView/bin/iPhoneSimulator/Debug/MySingleView.app/MySingleView
  Expected: 2018-03-09 19:48:09.000
  But was:  2018-03-09 19:48:11.000

the timestamps clearly have a one-second resolution.

I logged onto the bot, to confirm its file system:

$ diskutil info /
   [...]
   File System Personality:  APFS
   Type (Bundle):            apfs
   Name (User Visible):      APFS

I tested that mono returns sub-second times:

$ csharp -e 'System.IO.File.GetLastWriteTimeUtc ("/Users/builder/MonkeyWrench.log").ToString ("HH:mm:ss.fffffff")'
"11:22:45.2788357"

so I have no idea why this is random on High Sierra as well.

@rolfbjarne
Copy link
Member Author

So I figured out why our High Sierra bots don't fail: mono didn't support sub-second timestamp resolution on non-Windows platforms until mono 5.12 (mono/mono@e0e185d).

I tested for exactly this on the bot, but it turns out that the bot had mono 5.12 installed from another test run when I tested it 😠

Copy link
Contributor

@chamons chamons left a comment

Choose a reason for hiding this comment

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

There are Codesign invocations in Xamarin.Mac.Common.targets, does it need a fix as well for this issue?

@rolfbjarne rolfbjarne merged commit c8e3b94 into xamarin:master Mar 19, 2018
spouliot pushed a commit to spouliot/xamarin-macios that referenced this pull request Jun 12, 2018
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 https://github.com/xamarin/maccore/issues/592.
spouliot added a commit that referenced this pull request Jun 12, 2018
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 https://github.com/xamarin/maccore/issues/592.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants